PLUGIN Most of this project consisted of software. On the Windows side, we had to develop a plugin to tie into Winamp. Although the end product is not complicated, starting from scratch was very difficult. Before this project, we knew nothing about dynamic link libraries or window handlers. The documentation for Winamp’s API is scarce. They just revamped the site for Winamp v.5 so much of the past documentation was not available. After scouring to the ends of google, we were able to put several ideas together and create a successful plugin by spawning a new thread from within the init function of the plugin.
Communication between the Atmel and plugin is taken care of by a free communications library provided by BBDSoft. The Atmel sends all requests as single bytes. The plugin interprets the byte, and responds by either sending a command to Winamp, or returning information to the Atmel. Here is the basic structure of the communications protocol for the plugin.
The ATMEL code is built around polling for button pushes using the Choice State Machine. This state machine runs in the main while(1) loop as fast as possible. When a button is pushed, the value is decoded and the correct state is entered on the next execution loop. Upon entering one of the new states, the button Debounce State Machine is called every 30ms. The Play, Pause, Stop, and mode states return to the Choice state once the button is debounced and the correct byte is sent to the UART. The other states, RWD, FF, and Volume Up and Down, have an added feature. If the user presses the button and releases in under 400ms, a single command is issued, writing a byte to the UART. If the button is held down, Pushflag=1, the volume up and volume down will begin to autoincrement once every 400ms. The RWD and FF will rewind and fast-forward instead of skip to the previous or next song.
The mode button changes the user from normal mode, viewing the current song information, to playlist mode, viewing the current playlist, viewing two songs at a time. When in the playlist mode, only the Play, Volume Up, Volume Down, and mode buttons are enabled. The mode button simply toggles the mode, and the volume buttons scroll the playlist up and down. The play button plays the currently highlighted song on the playlist. It is called every 30ms as needed.
The Atmel uses interrupts to signal the main program when there is data to be read on the UART. The UART buffer is read until the vertical tab, ‘\v’, character is read signifying end of transmission. Once a request is sent that requires a response, the UART receive interrupt is enabled and the Print State Machine stays in its current state until the data is ready, “cmd_ready=1”.
The Print State Machine flows as follows. Every 50ms, the Print State Machine runs. The initial begin state is Play Status. This state sends a request to the plugin for the current status of the song. The plugin returns play, pause, or stop. Once the data is received, the LCD is updated with the new status and the state is then set to the Song Title state.
The Song Title state sends a request to the plugin for the song title information. The plugin returns the name of the song that is displayed in WinAmp’s playlist. The format of this data can be changed from within WinAmp’s preferences menu. Upon receiving the data, the LCD is updated with the song title and the state changes to Time Status.
Time Status and Bitrate are similar to the first two states. They send requests to the plugin and upon receiving the data, the LCD is updated accordingly. After Bitrate is complete, the state machine goes to the Print Status state. Here the new state is determined by the current mode. In this case the machine returns to the Play Status state yielding an overall LCD update in normal mode of 250ms plus the time to execute the button state machine.
When the controller is in playlist mode, set in the Choice State Machine’s mode state, the state of the Print State Machine is set to Playlist Print state. This state retrieves the playlist and formats its. It then sets the current state to Print_pl_0 where the first line of the playlist is written to the LCD. The next state is Print_pl_1 where the second song of the playlist is written to the LCD. Once the playlist has been written to the LCD, the Print Status state determines whether to set the new state to Play Status or Print Playlist based on the current mode.
A key feature of using a state machine like the Print State Machine is the LCD is always up to date. If a user changes song information, play status, or even deletes a song in the playlist, the controller is almost immediately updated. To the user, it should seem to have very little lag.
Built into the controller is another feature known as a time-out timer. If the communications are ever lost, the timer will timeout in 500ms and re-initialize the entire controller. This is to prevent the controller from losing communications and potentially staying out of synch, never regaining synchronization.