Home
WINAMP REMOTE CONTROL ECE-476 Joe Golden – jg325 Kenny
Contents
1. break nothing case 6 break get status play pause stop case 7 status getStatus if status 0 aPort write stop v stringSize stop v else if status 1 aPort write playNv stringSize playNv else if status 3 aPort write pauselv stringSize pauselv else aPort write unknown v stringSize unknown v break samplerate case 8 format the output sprintf buffer sd v getInfo SAMPLERATE aPort write buffer stringSize buffer break bitrate vase 9 format the output sprintf buffer d v getInfo BITRATE aPort write buffer stringSize buffer break number of channels case a format the output sprintf buffer d v getInfo CHANNELS aPort write buffer stringSize buffer break go to next track case b nextTrack break go to prev track case o s prevTrack break fast forward case d fforward break rewind case e rewind break get version of winamp Case version getVersion format the output sprintf buffer WinAmp v x 02x v version 4096 version amp OxFFF aPort write buffer stringSize buffer break get current play time case g format the output sprintf buffer 02d 02dNv getPlayTime 1000 60 getPlayTime 1000 60 aPort write buffer stringSize buffer break get title of current playing song case h title cha
2. void prevTrack void void fforward void void rewind void int stringSize char int getVersion void int getPlayTime void int getPlaylistIndex void int getPlaylistLength void char getPlaylist void char remove nulls char int 1 kok ok ok ok kk ko ko ko KKK KKK KKK KKK f nedeee winamp plugin Stuff X XWkk ok k kk kk kk kk kk kk ke ke ke ke ke ke ke ke ke e e e KK S ok ok ok ok ok k ok k kk KC k k kk k k k k k kk k Ck kk KC k KC k k k k k k kk kk k kk ko kk k k KK kk kkk kk kkk kk kk k winampGeneralPurposePlugin plugin GPPHDR_VER Winamp Remote v1 0 init config quit required function Int init spawn new thread for main servicing function _beginthread Reader 0 NULL return 0 required function void config required function void quit extern C declspec dllexport winampGeneralPurposePlugin winampGetGeneralPurposePlugin return amp plugin A ok ok ok ok kk ko ko ko ke ke ke ke A ARIA KKK KR RKKKKKKKKKK KONG winamp plugin SCULL KARR KH KR KKK KK KK KK 1 kok ok ok ok KK ke ko AR AAAI IAA KR function that Rx Tx and communicates with winamp static void Reader void HWND mainwinampwin plugin hwndParent int status har choice nt version har aData h ouble x clock String trackFilename truct timeb timebuffer har timeline har title ne pos nt current pos 0 song pos har buffer 10 ha
3. buffer song pos return buffer return the number of songs in the playlist int getPlaylistLength void return SendMessage plugin hwndParent WM WA IPC 0 IPC GETLISTLENGTH calculate the string size so i don t have to int stringSize char inString int x 0 while inString x 0 x return x wac_vl c include lt Mega32 h gt include lt stdio h gt include lt delay h gt include lt string h gt define LCDwidth 16 port A asm equ _ lcd port 0x1B endasm include lt lcd h gt define buttonO 0x01 define buttonl 0x02 define button2 0x04 define button3 0x08 define button4 0x10 define button5 0x20 define button6 0x40 define button 0x80 define CHOICE O0 define PLAY 1 define STOP 2 define PAUSE 3 define VOLUMEUP 4 define VOLUMEDOWN 5 define RWD 6 define FFWD 7 define TOGGLE MODE 8 define NO PUSH 0 define MAYBE PUSH 1 define PUSHED 2 define MAYBE NO PUSHED 3 define PLAY STATUS 0 define SONG TITLE 1 define TIME STATUS 2 define PRINT STATUS 3 define PLAYLIST PRINT 4 define PRINT PL 0 5 define PRINT PL 1 6 define BITRATE 7 define DOWN 0 define UP 1 define NONE 2 mode defines define NORMAL 0 define PLAYLIST 1 void debounce int void init void void toggleLED unsigned int char void checkStatus void char format char unsigned char multi_space char unsigned int pit count unsigned char debounce state unsigned
4. Structure The Winamp controller can be split into two basic pieces the plugin and the controller which communicate serially Plugin The plugin is a way to hook into WinAamp It is also known as a dynamic linked library or dll It is nothing more than a backend server waiting on requests via the com port When a request is received a byte comes in on the receive line the data is translated and the request is serviced either by sending a command to WinAmp or returning some data regarding the request Controller The controller provides the interface for the user consisting of eight buttons and an LCD The hardware runs on a 16 0 MHz Atmel Mega 32 microcontroller Hardware Software Tradeoffs As a first step we wrote an external application to control WinAmp The drawbacks of this implementation were lack of overall control of WinAmp and the application had to be started separate from and after WinAmp had started The external application limited the control to simply play pause stop volume and track changes Since our goal was to provide the user with a more powerful interface including viewing current song information and the entire playlist we had to develop a plugin Now we have total control of WinAmp s API and the plugin loads when WinAmp is started HARDWARE SOFTWARE DESIGN Software 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
5. button7 if push_flag if pit count 400 0 putchar e repeat_flag 1 delay to prevent putchar from occuring mutliple times on the same tick delay ms 1 else if debounced if repeat flag 0 putchar c else repeat_flag 0 button_state CHOICE debounced 0 toggleLED button7 C break change mode between playlist and normal mode case TOGGLE MODE if pit count 30 0 debounce button0 if debounced if mode PLAYLIST mode NORMAL set the start state of print to the play status status PLAY STATUS else mode PLAYLIST set the start state of print to print the playlist status PLAYLIST PRINT button_state CHOICE debounced 0 toggleLED buttonO C break call check status every 50ms if pit_count 50 0 checkStatus this function is the LCD routines it retrieves the needed info fromt the plugin and spits it out to the LCD one piece at a time void checkStatus unsigned char x switch status case PLAY STATUS not waiting for any input if wait for input 0 get_cmd_init putchar 7 send status request wait for input 1 data is ready to be read if cmd_ready 1 sprintf play status str s format cmd_str play status str 5 0 lcd gotoxy 0 1 lcd puts play status str wait for input 0 status SONG TITLE start counter 0 break case SONG_TITLE not w
6. ffer 16 r for i 1 i lt 16 i plbuffer i 16 title i l fill with first 16 chars of second song for i 17 1 lt 32 i if plbuff pl e else if c lear flag er i 0 1 lbuffer i H lear flag 1 pl clear flag 0 Ibuffer i r add vertical tab and null char plbuffer 32 v plbuffer 33 0 1 7 aPort write plbuffer stringSize plbuffer break play current playlist case m selection set playlist position SendMessage plugin hwndParent WM WA IPC current pos IPC SETPLAYLISTPOS play break S KRKKKKKKKKKK KKK k k k k k k kk k k k kk k k k A k kk k k k k k k k k kk kk k kk kk kkk kk kkk kk kk RKKKKKKKKKKKKKHASIC control functions kkkkkkkkkkkkkKKKKK f KK KKK KKK ko ko ke ke ke KKK KKK KK RK f void volumeUp void SendMessage plugin hwndParent void volumeDown void SendMessage plugin hwndParent int play void SendMessage plugin hwndParent return 0 WM COMMAND WINAMP VOLUMEUP 0 WM COMMAND WINAMP VOLUMEDOWN O0 WM COMMAND WINAMP PLAY 0 void stop void SendMessage plugin hwndParent WM COMMAND WINAMP STOP 0 void pause void SendMessage plugin hwndParent WM COMMAND WINAMP PAUSE 0 void nextTrack void SendMessage plugin hwndParent WM COMMAND WINAMP NEXT 0 void prevTrack void SendMessage plugin hwndParent WM COMMAND WINAMP PREV 0 void
7. 10U TIIN T20U C2 70 CONNECTOR DBS RESULTS OF DESIGN We feel our design was very simple and elegant Response time from the button to execution of the command is almost instantaneous except for the read play list function When scrolling up and down the play list a slight delay can be seen This is the only function that needs a button push to begin the command and then must wait for a response from the computer Because of this there is a delay of approximately one quarter of a second Accuracy is very good on our project We never pushed a button and had a wrong command The only problem ever experienced was with our fast forward and rewind commands It is set up so that if the fast forward button is pressed and released it skips to a new song If it is pressed and held it fast forwards through the current song The same is true for rewind There were a few times when we wanted to skip to the new song and we ended up fast forwarding through the current song instead Safety was not much of a concern during our project The 9V battery can only be connected the correct way Our buttons were clearly labeled If going into production there would be real PCBs made and a case for the controller that would eliminate safety issues of exposed wires Our project does not interfere to our knowledge of any other design projects The only other possible interference would be if someone was using WinAmp on the computer while some
8. ISTTITLE fill first 16 characters of buffer with second song add a star to beginning to signify current selected song in playlist plbuffer l6 for i 1 i lt 16 i plbuffer i 16 title i 1 remove the null terminating character and add blank spaces after the null is found replace it and all remaining with spaces for 1 17 1 lt 32 i if plbuffer i 0 plbuffer i clear_flag 1 else if clear flag 1 plbuffer i J clear flag 0 add a vertical tab and null terminate it plbuffer 32 2 Nv plbuffer 33 0 write to uart aPort write plbuffer stringSize plbuffer break get only two songs to display in playlist decrementing case k if current pos 1 0 current pos title char SendMessage plugin hwndParent WM WA IPC current pos IPC GETPLAYLISTTITLE fill first 16 characters of buffer with first song add a star to beginning to signify current playlist selection plbuffer 0 for i 1 i lt 16 i plbuffer i title i 1 cemove the null terminating character and add blank spaces after the null is found replace it and all remaining with spaces for i 0 i lt 16 i if plbuffer i 0 plbuffer i l clear flag 1 else if clear flag 1 plbuffer i l clear flag 0 title char SendMessage plugin hwndParent WM WA _IPC current_pos 1 IPC GETPLAYLISTTITLE fill first 16 characters of buf
9. WINAMP REMOTE CONTROL ECE 476 Joe Golden jg325 Kenny McNutt km279 05 06 04 INTRODUCTION Our goal was to create a remote control for the popular music player Winamp The Winamp controller is a standalone piece of hardware that allows a user to view playlists and control Winamp as if they were actually at the computer It utilizes Winamp s API through a simple plugin that is loaded upon starting the application The remote consists of eight buttons each of which controls various parts of Winamp The built in LCD provides feedback of the current song play status and allows users to view the current playlist HIGH LEVEL DESIGN Rationale Winamp has been one of the most popular music players since it began in 1997 With the users in place who would not want to have a standalone remote to control Winamp Background I have wanted to build a WinAmp remote control for a long time now Several years ago I found a plugin that allowed the user to control the basic functionality of WinAmp with a few pushbuttons over serial communications From that point I figured the next logical step was to provide feedback to the user via an LCD That is when the idea was born I had neither the time nor effort available until we were required to build something for ECE 476 I approached Joe with the idea and aside from him wanting to build a self contained air hockey puck he was all for the idea and the WinAmp Controller was born Logical
10. aiting for any input if wait for input 0 get_cmd_init putchar h send songtitle request wait_for_input 1 data is ready to be read if cmd_ready 1 strcpy song title full cmd str copy the input data to the song title if same song is still playing and the whole or at least the end of the title didn t show last time if song pos timer 10 countertt if counter 2 if strcmp song title full song title full prev 0 amp amp strpos song title full prev 0 gt 16 amp amp multi space song title print 0 change index so the song will seem to scroll song post reset index else song_pos 0 break song pos timer 0 counter 0 else song pos timer copy the first 16 characters of the song title for x 0 x lt 16 x song title print x song title full x song pos i song title print 16 0 null terminate the string strcpy song title full prev song title full sprintf lcd buffer0 s format song title print lcd buffer0 16 0 lcd gotoxy 0 0 lcd puts lcd buffer0 wait for input 0 status TIME STATUS start counter 0 case TIME STATUS if wait for input 0 get cmd init putchar g send songtitle request wait for input 1 data is ready to be read if cmd ready 1 sprintf song time s cmd str wait for input 0 status BITRATE start counter 0 break case BITRATE if wai
11. ass production and competition From these ideas the RS232 standard was born It specified signal voltages signal timing signal function a protocol for information exchange and mechanical connectors To comply with this standard we simply needed to add a MAX232 chip to help convert voltages to and from the micro controller to the serial connection in order to comply with the standard There were several intellectual property considerations for our project For serial communications we used a free general component library for WIN32 from BBDSoft They can be found via the web at http www bbdsoft com Also the main part of the project was the WinAmp API WinAmp has a large group of private developers constantly creating new skins plugins and visiualizers All the API headers are free of charge as is the software The Debounce State Machine was presented to the class by Professor Land Ethically we followed to the best of our knowledge all ten points in the IEEE Code of Ethics both in the design and in this report We have given credit where credit is necessary We did not take bribes We worked to advance our understanding of a subject matter We did not discriminate nor did we place anyone in harms way at any point during this project If working to advance this project there is still plenty of work to be done First thing would be to get a wireless system at a reasonable price We would need two transceivers for this project and good tra
12. char push flag char debounced char adjust done flag char button state har wait for input har status har c har cmd str 250 har song title full prev 250 har song title full 250 har song title print 17 har cmd ready nt char count har play status str 6 har lcd buffer0 17 har repeat flag har mode har song time 7 nsigned char song pos 0 har pl line0 17 pl line1 17 har bit rate 6 har output 12 unsigned char counter song pos timer unsigned int pl pos unsigned int time out counter unsigned char start counter unsigned char scroll Cy X 4X 88 X0 AR E Ge OL GOD CP OL GAS receive interrupt service routine interrupt USART RXC void uartRx void c UDR copy character from UDR to global C if c 2 Nv cmd str char count c else cmd str char count 0 cmd ready 1 UCSRB 7 0 kill interrupt until software is ready init Rx interrupt servicing void get_cmd_init void char_count 0 cmd ready 0 UCSRB 7 1 enable Rx interrupt time_out_counter 0 start counter 1 main function void main void int x init variables init while 1 poll for button presses switch button_state case CHOICE if PINB 0x0 break no button pushed else if PINB button6 toggleLED button6 C button_state PLAY else if PINB button5 amp amp mode NORMAL toggleLED button5 C else
13. else else else else else break case PLAY button state PAUSE if PINB button4 amp amp mode NORMAL toggleLED button4 C button_state STOP if PINB button2 toggleLED button2 C button state VOLUMEUP if PINB buttonl toggleLED buttonl C button state VOLUMEDOWN if PINB button7 amp amp mode NORMAL toggleLED button7 C button state RWD if PINB button3 amp amp mode NORMAL toggleLED button3 C button state FFWD if PINB button0 button state TOGGLE MODE if pit count 30 0 debounce button6 if mode NORMAL else if debounced putchari l button state CHOICE debounced 0 toggleLED button6 C if mode PLAYLIST play the current song viewed on the playlist if debounced putchar m button state CHOICE debounced 0 mode NORMAL toggleLED button6 C break case PAUSE if pit count 30 0 debounce button5 if debounced putchar 3 button state CHOICE debounced 0 toggleLED button5 C break case STOP if pit count 30 0 debounce button4 if debounced putchar 2 button state CHOICE debounced 0 toggleLED button4 C break volume up and scroll up in playlist mode case VOLUMEUP if pit_count 30 0 debounce button2 if mode NORMAL if push flag if
14. et up the ports DDRD 0x00 PORT D is an input DDRB 0x00 PORT B is an input buttons PORTB 0xff PORT B off DDRC 0xff PORT C is output LEDs PORTC 0xff port c is off DDRA 0xff USART UCSRB 0x18 UBRRL 103 set up timer 0 TIMSK 2 OCRO 250 set the compare re to 250 time ticks TCCRO 0b00001011 wait for input 0 status PLAY STATUS repeat flag 0 mode NORMAL scroll NONE pit count 0 counter 0 song pos timer 0 start counter 0 time out counter 0 debounced 0 button is debounced adjust done flag 0 done making changes to freq debounce state NO PUSH button state CHOICE led init LCDwidth led gotoxy 0 0 lcd putsf WinAmp Cont v1 0 lcd gotoxy 0 1 lcd putsf no connection crank up the ISRs asm sei endasm
15. fer with second song add a space to beginning plbuffer 16 for i 1 1 lt 16 i plbuffer i 16 title i 1 remove the null terminating character and add blank spaces after the null is found replace it and all remaining with spaces for 1 17 1 lt 32 1i if plbuffer i 0 plbuffer i clear flag 1 else if clear flag 1 plbuffer iJ clear flag 0 add a vertical tab and null terminate it plbuffer 32 v plbuffer 33 0 aPort write plbuffer stringSize plbuffer break get the current two songs in playlist case l if current pos 0 song pos current pos l else song pos current pos title char SendMessage plugin hwndParent WM WA IPC song pos 1 IPC GETPLAYLISTTITLE z add star to beginning of song to signify current playlist selection if song_pos 1 current_pos plbuffer 0 add space at beginning of song else plbuffer 0 fill buffer with first 16 chars of first song for i 1 i lt 16 i plbuffer i title i 1 remove all null chars and fill remaining with spaces for i 1 i lt 16 i if plbuffer i 0 plbuffer i J clear_flag 1 else if clear flag 1 plbuffer i J clear flag 0 if song pos lt getPlaylistLength title char SendMessage plugin hwndParent WM_ WA IPC song pos IPC GETPLAYLISTTITLE if song pos current pos plbuffer l6 else plbu
16. fforward void SendMessage plugin hwndParent WM COMMAND WINAMP FF 0 void rewind void SendMessage plugin hwndParent WM COMMAND WINAMP REW 0 Pk ok ok ok ok ok ok kk ko ko ke ke ke ko kk kk kk kk ko kok oko oko oko okokokokokok kok k k k kok I I k kok ok kok k k k k eee fx e ee e eng basic control functions KKK KKK KKK KK KK KK JE K K ok ok ok ok KKK A A RR AA k k KKK k k k kk k k k k k kk k k k kk k k k KK get play status play pause stop int getStatus void return SendMessage plugin hwndParent WM WA IPC 0 IPC ISPLAYING get basic info bitrate samplrate channels int getInfo int mode return SendMessage plugin hwndParent WM WA IPC mode IPC GETINFO get winamp version int getVersion void return SendMessage plugin hwndParent WM WA IPC 0 IPC GETVERSION current time elapsed of song time in seconds does not work Use MSECONDS int getPlayTime void return SendMessage plugin hwndParent WM WA IPC MSECONDS IPC GETOUTPUTTIME returns the index of the song in the playlist that is currently playing int getPlaylistIndex void return SendMessage plugin hwndParent WM WA IPC 0 IPC GETLISTPOS returns pointer to entire playlist char getPlaylist void char song int pos 0 char buffer while pos lt getPlaylistLength song char SendMessage plugin hwndParent WM WA IPC getPlaylistIndex IPC GETPLAYLISTTITLE sprintf buffer s r n s r n
17. 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 Ifa 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 Hardware For our project we used an Atmel Mega32 micro controller that we ran at I6MHz The circuit diagram can be found in the Schematic section This Atmel has four I O ports Port A was used to output to the LCD Port B is an input from the pushbuttons that ultimately sends commands to WinAmp Port C was used as a test and debugging port during development We also used two pins on Port D for serial communication Our 5V power was supplied from a 9V battery that was regulated down by using an LM340 5V regulator We also placed a 100uF capacitor on the outp
18. ll begin to autoincrement once every 400ms The RWD and FF will rewind and fast forward instead of skip to the previous or next song Choice Button amp c 5 k Button 0 os Ss Se guj nz58 amp AA Butto 5 de normal st Button o U BT Lo Button 88 wo mode notmal Table 1 Choice State Machine 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 Clock tick 30ms No push Button Maybe Push Button Maybe No Pushed Button Table 2 Debounce State Machine 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
19. m of consecutive empty spaces used for song scrolling unsigned char multi_space char string unsigned char x count 0 for x 13 x lt 16 x if string x count if count 3 return 1 else return 0 debounce button 30ms ticks void debounce int button switch debounce_state case NO PUSH if PINB button debounce state MAYBE PUSH break case MAYBE PUSH if PINB button debounce_state PUSHED push_flag 1 else debounce state NO PUSH break case PUSHED if PINB button else debounce state MAYBE NO PUSHED break case MAYBE NO PUSHED if PINB button debounce state PUSHED else push_flag 0 debounce_state NO_PUSH debounced 1 flag set when completely debounced break timer 0 interrupt service routine interrupt TIMO COMP void timer0 compare void 1ms ticks pit count counter for checking debounce state machine timeout counter if start counter 1 time out counter if timeout if time out counter 500 disable interrupt for now UCSRB 7 0 TIMSK 0 re init init function to toggle leds easy to use takes out some complexity in writing code void toggleLED unsigned int led char port if port a port A PORTA PORTA led if port b port B PORTB PORTB led if port c port C PORTC PORTC led void init void s
20. made smaller with the use of a PCB and surface mount components but for a prototype it works well The software design for this project was a little overwhelming at times It is not difficult to create a plugin for WinAmp but when you begin with absolutely no knowledge of plugins or Windows style programming it can be a lot to swallow We have noticed the occasional strange event occur in Windows If there was more time it would be nice to do more debugging and see what kinds of effects various applications have on the plugin The only applicable standard to our design is the RS232 standard The following is an excerpt from The RS232 Standard by Christopher Strangio In the 1960 s a common interface standard for data communications was developed At that time data communications was thought to mean digital data exchange between a centrally located mainframe computer and a remote computer terminal or possibly between two terminals without a computer involved These devices were linked by telephone voice lines and consequently required a modem at each end for signal translation While simple in concept the many opportunities for data error that occur when transmitting data through an analog channel require a relatively complex design It was thought that a standard was needed first to ensure reliable communication and second to enable the interconnection of equipment produced by different manufacturers thereby fostering the benefits of m
21. n pressed this allows the user to see the playlist Use the volume buttons to scroll up and down the list A is also visible on the left side of the screen To play a song simply press the PLAY button when the is next to the chosen song To exit from play list mode hit the PLAYLIST button again Button 1 VOUME DOWN This button decreases the volume However when viewing the play list it allows the user to scroll down When the button is held down it will decrease the volume at a faster pace Button 2 VOLUME UP This button increases the volume However when viewing the play list it allows the user to scroll up When the button is held down it will increase the volume at a faster pace Button 3 FAST FORWARD When tapped this button skips to the next song on the play list When held down it will fast forward through the current song Button 4 STOP This button stops music from playing Button 5 PAUSE This button will pause a song at its current location To exit PAUSE hit either the PAUSE or PLAY button Button 6 PLAY This button will play the first song on the play list if it is the first button pressed If music had already been playing it will play whichever song the music was stopped at When pressed while viewing the play list the song with the next to it will begin to play Button 7 REWIND When tapped this button skips to the previous song on the play list When held down it will rewind through the current s
22. nd traditional remote controls would make this necessary since they require line of sight The host would also not want to leave the party to constantly go to his bedroom to make changes Our remote control would enable someone from the living room to control the play list without entering private areas of the house RESOURCES 1 MAX232 Data Sheet http rocky digikey com WebLib Texas Instruments Web data MAX232 2321 pdf 2 Atmel Mega32 Data Sheet instruct cit cornell edu courses ee476 AtmelStuff full32 pdf 3 Serial Communications Library www bbdsoft com 4 WinAmp API and Application www winamp com CONTRIBUTIONS OF EACH PARTNER Joe Golden jg325 cornell edu Designed and built the hardware Kenny McNutt km279 cornell edu Wrote the plugin Atmel code and designed the webpage APPENDIX Source Code remote_plugin cpp include stdafx h include windows h include wa_ipc h include gen h include winamp h include lt process h gt include lt iostream gt include COMPORT H include lt string h gt include lt sys timeb h gt include lt time h gt define SAMPLERATE 0 define BITRATE 1 define CHANNELS 2 define SECONDS 1 define MSECONDS 0 int init void config void quit Static void Reader void int play void void volumeUp void void volumeDown void vold stop woid void pause void int getStatus void int getInfo int void nextTrack void
23. nsceivers cost a minimum of 20 each What distinguishes our project from a simple remote control that is available commercially is that we have a play list function that can display on the LCD Without this only one transmitter and one receiver would be necessary and this would tremendously cut costs since a transmitter and receiver together can be found for 10 It should also be noted that by placing a small hard drive or flash card into the remote control it would be easy to convert it to a portable MP3 player Other improvements that can be made would be to make a nice case for the board and to reduce its size through a PCB and surface mount components By doing this the board size can easily be cut in half Another improvement would be a much larger LCD This would allow more information to be seen Finally the system can be made more robust Finally certain bugs can be worked out and improved on For instance when WinAmp is set on shuffle mode our controller has major problems when trying to view the play list Bugs like this and other bugs found through testing can be worked out and fixed We do feel there would be a market for our product if cheap transceivers can be found In particular we feel the college student would be our target audience While at parties it is common for the host to set up a big play list so that music is taken care of all night The host would not want people entering his bedroom at will to change the song a
24. one else was using the remote control Because our code is non blocking of normal use the two people can both control it at the same time which could lead to fights about which song to play Known Bugs As much as we would like to say there are none there are some bugs Inevitably with any software there will be bugs and more will continually creep up e Ifthe playlist mode on WinAmp is set to shuffle and the playlist mode on the contoller is turned on this will cause WinAmp to crash e Ifthe last song in the playlist is deleted and playlist mode is entered from the controller WinAmp will crash e Occassionaly the LCD will bug out when some other action on the computer takes place e At some point Mozilla crashed claiming there was a bug in the com port software that the plugin uses to service requests USER S MANUAL Step 1 Start WinAmp on the computer and set up a playlist Load the plugin file that comes with the remote control onto the computer Simply find the WinAmp directory on the hard drive and place the plugin file given into the plugin directory This only needs to be down the first time you use the remote control Step 2 Power on the remote control by flipping the toggle switch A red LED should illuminate Step 3 All buttons are labeled accordingly on the remote control but they are listed here with functionality When a button is pressed a yellow LED should illuminate next to the button Button 0 MODE Whe
25. ong Frequently Asked Question The LCD is small what if two songs have the same first 16 characters The remote control sets up a scrolling song title This means the entire song name will scroll across the LCD What is shown on the LCD during normal operation You will see the current song being scrolled across the top line On the bottom line it shows what the current state of operation is If the state is PLAY the bottom line will also show how much time has passed in the current song as well as the current bit rate What kind of batteries does it use One 9V battery will last for several hours of usage What does it mean if the LCD reads no connection There can be one of several problems WinAmp could be closed the plugin might not be installed or the serial cable could be loose or not plugged into com 1 As a first step trying resetting the controller and restarting WinAmp COST swin ef sof siso 1M340 voltage regulator snes sies mHzeysa 1 002 0 00 220 resistor o sosa sooo 100 resistor if 0 5000 ker f 80 04 sooo maxs 1 som 5000 ovbatey 82 00 2 13 0 1uF capacitor s stol sooo furs sof sus from o saf 923 91 Table 4 These parts were borrowed donated or otherwise acquired CONCLUSION The hardware design for this project was fairly simple and straightforward There would not be much to do differently It could obviously be
26. pit_count 100 0 putchar 4 delay to prevent putchar from occuring mutliple times on the same tick delay ms 1 i else if debounced button_state CHOICE debounced 0 toggleLED button2 C else if mode PLAYLIST scroll playlist up if debounced scroll playlist up scroll UP button state CHOICE debounced 0 toggleLED button2 C break volume down and scroll down in playlist mode case VOLUMEDOWN if pit_count 30 0 debounce buttonl if mode NORMAL if push_flag if pit_count 100 0 putchar 5 delay to prevent putchar from occuring mutliple times on the same tick delay ms 1 else if debounced button_state CHOICE debounced 0 toggleLED buttonl C else if mode PLAYLIST scroll playlist down if debounced scroll playlist down scroll DOWN button_state CHOICE debounced 0 toggleLED buttonl C break fast forward and skip to next song case FFWD if pit_count 30 0 debounce button3 if push_flag if pit_count 400 0 putchar d repeat_flag 1 delay to prevent putchar from occuring mutliple times on the same tick delay ms 1 else if debounced if repeat flag 0 putchar b else repeat flag 0 button state CHOICE debounced 0 toggleLED button3 C break cewind and skip to prev song case RWD if pit_count 30 0 debounce
27. 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 byte Rx function returns format of return 0 clock time time dddd mmm dd hh mm ss yyyy v 1 play n a n a 2 stop n a n a 3 pause n a n a 4 volume up n a n a 5 volume down n a n a 6 nothing n a n a 7 play status play pause stop status v 8 sample rate sample rate samplerate v 9 bitrate bitrate bitrate a channels channels channels b next track n a n a c prev track n a n a d fforward n a n a e rewind n a n a f version version ft WinAmp version g play time play time mm ss v h song title title ti
28. r SendMessage plugin hwndParent WM WA IPC getPlaylistIndex IPC GETPLAYLISTTITLE format the output sprintf buffer s v title aPort write buffer stringSize buffer break get entire playlist case i sprintf plbuffer pos 1 while pos lt getPlaylistLength title char SendMessage plugin hwndParent WM WA IPC pos IPC GETPLAYLISTTITLE format the output put a r between songs in the playlist sprintf plbuffer s s r plbuffer title pos add the vertical tab as an end of data character sprintf plbuffer s v plbuffer aPort write plbuffer stringSize plbuffer break get only two songs to display in playlist incrementing case j if current pos l lt getPlaylistLength current pos title char SendMessage plugin hwndParent WM WA IPC current pos I IPC GETPLAYLISTTITLE H fill first 16 characters of buffer with first song add a space to beginning plbuffer 0 for i 1 i lt 16 i plbuffer i title i 1 cemove the null terminating character and add blank spaces after the null is found replace it and all remaining with spaces for i 1 i lt 16 i if plbuffer i 0 plbuffer i l clear flag 1 else if clear flag 1 plbuffer i l clear flag 0 get second song to send if current_pos lt getPlaylistLength title char SendMessage plugin hwndParent WM WA IPC current pos IPC GETPLAYL
29. r plbuffer 100 nt i har clear flag 0 Q Ha 0O FF Ga W RO PFG f KRKKKKKKKKKK KKK KKK KKK KKK KKK KKK KKK KKK ok k kk KKK KKK setup com port xd oko de oko BR Ck ko ko ko ko ko ke ke ke kk kk kok kok kk ok ok ko kok kok kok kok KKK KKK COMPort aPort COM1 comi aPort setBitRate COMPort br9600 9600bps aPort setParity COMPort None no parity aPort setDataBits COMPort db8 8 data bits aPort setStopBits COMPort sbl 1 stop bit aPort setxONxOFF false no xOnxOff aPort setHandshaking false no handshaking A ok ok ok ok ok ok ok k kk KKK KKK KKK KKK r 7 end setup com POLE RK AHHH HK HK HK RK RK RK RK RK KK KK BRK ke ko AI KKK KKK char output while 1 block until remote sends a single byte of data choice aPort read all data that is transmitted ends with a vertical tab v I figure this is not used in any text so it makes a good terminator switch choice current time case 0 J KRKKKKKKKKKKK KKK KKK KKK get time _ftime amp timebuffer timeline ctime amp timebuffer time aPort write timeline stringSize timeline aPort write v stringSize v J KRKKKKKKKKKKKK k k k k k k k k k k k KK KK k k k KK break play case 1 play break stop case 2 stop break pause case 3 pause break increase volume case 4 volumeUp break decrease volume case 5 volumeDown
30. t for input 0 get_cmd_init putchar 9 send bitrate request wait_for_input 1 data is ready to be read if cmd_ready 1 sprintf bit rate s cmd str bit rate 5 0 sprintf output led gotoxy 5 1 lcd puts output wait for input 0 status PRINT STATUS start counter 0 o ss s song time bit rate break case PLAYLIST PRINT i pit_count 300 0 if wait for input 0 get cmd init if scroll NONE putchar 1 else if scroll DOWN putehar g s else if scroll UP putchar k Scroll NONE wait for input 1 data is ready to be read if cmd_ready 1 for x 0 x lt 16 x pl lineO x cmd str x pl linel x cmd str x 16 pl line0 16 20 pl linel 16 20 wait for input 0 status PRINT PL 0 start counter 0 break print first song of playlist case PRINT PL 0 led gotoxy 0 0 lcd puts pl line0 status PRINT PL 1 break print second song of playlist case PRINT PL 1 lcd gotoxy 0 1 lcd puts pl linel status PRINT STATUS break resest to beginning state case PRINT STATUS if mode PLAYLIST status PLAYLIST PRINT else status PLAY STATUS break remove all null characters and replace with spaces char format char string char x 0 while string x 0 xc for y x y lt 16 y stringlyl string 16 0 return string count the nu
31. 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 Clock tick 50ms Play Status cmd ready 1 Time Status cmd ready 1 Playlist print cmd_ready 1 Bitrate cmd_ready 1 Print Status Mode Playlist Table 3 Print State Machine 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
32. tle i entire playlist playlist song1 r song2 r v j playlist 2 songs incrementing 2 titles song1 0 14 song2 0 14 v k playlist 2 songs decrementing 2 titles song1 0 14 song2 0 14 v I playlist 2 songs 2 titles song1 0 14 song2 0 14 v m play current playlist selection n a n a The quotes in the format of return column signify a variable Brackets indicate byte 0 to 14 of the song titles All returns end with a vertical tab v to inform the Atmel the end of data It was decided to use the vertical tab because of the improbability of its use in any other sense We considered using the new line character n but wanted to reserve it for future use Atmel 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 wi
33. ut of the regulator to help smooth out the signal Aside from this given the schematic hardware schematic this project should be easily duplicated We experienced two problems with the hardware First we mistakenly assumed that the LEDs had a 0 7V drop across them Originally the LEDs were placed on the other side of the button since a 0 7V signal would be considered a low signal by the micro controller anyway However we soon learned that yellow LEDs require about 2 6 volts to operate This obviously caused problems because we never could give a low input The second problem we faced was that the input pins seemed to do nothing The micro worked fine on the STK500 with the entire circuit set up We then put it on the stand alone board we made and it did not work So to see if the micro and clock were working we wrote a quick program that just changed all of port C from high to low every two seconds This worked fine We knew that it was not a hardware issue but we could not figure out what could possibly be wrong with the code so that the micro would work on the STK but not on a standalone board Finally we remembered from lab that the micro controller would not work without the LCD connected to it which we had failed to disconnect from the STK and connect to the stand alone board Once we realized this our board worked very well Schematic LCD connector ATMega32 13 RIOUT RIIN 8 RZIN RZOUT QI TZN T
Download Pdf Manuals
Related Search
Related Contents
La Nouvelle Bibliothèque publique de Medellín - unesdoc Résumé du stage 取扱説明書 - シャープ INT-036 Rev 1.0 (Manual_Intalacion_Interceptor) ヒュミケアディスポーザブル部品添付文書(圧ライン付き回路用) Guida dell`utente Chamberlain PIRV400R User's Manual Copyright © All rights reserved.
Failed to retrieve file