#include #include #include "GEN.H" #include "resource.h" #include "frontend.h" char szAppName[]="UART Control"; int init(); void config(); void quit(); void get_title(); void put_title(); #define random(num)(int)(((long)rand()*(num))/(RAND_MAX+1)) //define the winamp commands to simple instructions #define PLAY SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON2,0); #define BACK SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON1,0); #define PAUSE SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON3,0); #define STOP SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON4,0); #define FWD SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON5,0); #define FADE_OUT SendMessage(hWinamp,WM_COMMAND,WINAMP_BUTTON4_SHIFT,0); #define VOL_UP SendMessage(hWinamp,WM_COMMAND,WINAMP_VOLUMEUP,0); #define VOL_DN SendMessage(hWinamp,WM_COMMAND,WINAMP_VOLUMEDOWN,0); #define FAST_FWD SendMessage(hWinamp,WM_COMMAND,WINAMP_FFWD5S,0); #define REW SendMessage(hWinamp,WM_COMMAND,WINAMP_REW5S,0); #define GET_SHUFFLE val=SendMessage(hWinamp,WM_WA_IPC,0,IPC_GET_SHUFFLE); #define SHUFFLE_TOG SendMessage(hWinamp,WM_WA_IPC,!val,IPC_SET_SHUFFLE); #define GET_REPEAT val=SendMessage(hWinamp,WM_WA_IPC,0,IPC_GET_REPEAT); #define REPEAT_TOG SendMessage(hWinamp,WM_WA_IPC,!val,IPC_SET_REPEAT); #define MUTE SendMessage(hWinamp,WM_WA_IPC,0,IPC_SETVOLUME); #define LC(x) SetDlgItemText(hDlg,104,x); #define GET_POS cur_pos=SendMessage(hWinamp,WM_WA_IPC,0,IPC_GETLISTPOS); #define GET_TIME time=SendMessage(hWinamp,WM_WA_IPC,1,IPC_GETOUTPUTTIME); //variables for title transmission char this_title[2048],*p; char end[1]={'\r'}; //variables for title update detection int cur_pos, old_pos; int time; int firstboot=1; long target; int val=0; int in=0; int pending=0; char data[64]="Hello there"; //input command buffer char indata[1]; //defined command characters char cmd_play[1]="x"; char cmd_bck[1]="z"; char cmd_pause[1]="c"; char cmd_stop[1]="v"; char cmd_fwd[1]="b"; char cmd_fade[1]="f"; char cmd_vol_up[1]="p"; char cmd_vol_dn[1]="l"; char cmd_fast_fwd[1]="h"; char cmd_rew[1]="g"; char cmd_shuf[1]="s"; char cmd_repeat[1]="r"; char cmd_mute[1]="m"; //uart variables and structures HANDLE uart; DCB dcb; unsigned long event; unsigned long check; LPOVERLAPPED o; //instantiate the plugin winampGeneralPurposePlugin plugin = { GPPHDR_VER, "UART Control", init, config, quit, }; __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin(); UINT TimerNo; HWND hWinamp; //the configuration procedure BOOL FAR PASCAL ConfigProc(HWND hDlg,UINT msg, WPARAM wParam, LPARAM lParam) { return TRUE; } //the main procedure BOOL FAR PASCAL MainProc(HWND hDlg,UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_INITDIALOG: //initialization TimerNo=SetTimer(hDlg,400,20,NULL); //link to winamp hWinamp=plugin.hwndParent; break; //the timer, called every 20 msec case WM_TIMER: //hide the window ShowWindow(hDlg,SW_HIDE); //get the current playlist index. //if is has changed since last time, //the song is different. Get the new //title and send it out over UART old_pos=cur_pos; GET_POS; if (old_pos!=cur_pos){ get_title(); put_title(); } //Overlapping I/O. event set to check if //a receive is in the buffer WaitCommEvent(uart,&event,o); if (event==check){ event=0; //read in the character ReadFile(uart,&indata,1,&in,o); //clear out the buffer, just in case PurgeComm(uart,PURGE_RXCLEAR); if (!strcmp(indata,cmd_bck)) BACK else if (!strcmp(indata,cmd_play)){ PLAY get_title(); put_title(); } else if (!strcmp(indata,cmd_pause)) PAUSE else if (!strcmp(indata,cmd_stop)) STOP else if (!strcmp(indata,cmd_fwd)) FWD else if (!strcmp(indata,cmd_fade)) FADE_OUT else if (!strcmp(indata,cmd_vol_up)) VOL_UP else if (!strcmp(indata,cmd_vol_dn)) VOL_DN else if (!strcmp(indata,cmd_fast_fwd)) FAST_FWD else if (!strcmp(indata,cmd_rew)) REW else if (!strcmp(indata,cmd_shuf)){ GET_SHUFFLE SHUFFLE_TOG } else if (!strcmp(indata,cmd_repeat)) { GET_REPEAT REPEAT_TOG } else if (!strcmp(indata,cmd_mute)) MUTE } else { break; } break; default: return FALSE; } return TRUE; } //Function gets the title from the winamp window, strips off the " - Winamp" footer //and the track number "123. " header. Adds the song time to the end "" Stored in p void get_title(void){ unsigned int i; int seconds; int minutes; char string_sec[3]; char string_min[3]; GetWindowText(hWinamp,this_title,sizeof(this_title)); p = this_title+strlen(this_title)-8; while (p >= this_title){ if (!strnicmp(p,"- Winamp",8)) break; p--; } if (p >= this_title) p--; while (p >= this_title && *p == ' ') p--; //get the song time from winamp time=-1; while (time==-1){ GET_TIME; } //convert the received time in sconds to minutes and seconds //convert those integers to ascii and add them to the title string if (time!=-1 && firstboot!=1){ *++p=' '; *++p='<'; seconds=time%60; minutes=time/60; itoa(seconds,string_sec,10); itoa(minutes,string_min,10); for (i=0; ihEvent = CreateEvent( NULL, // no security attributes FALSE, // auto reset event FALSE, // not signaled NULL // no name ); if (uart == INVALID_HANDLE_VALUE) { // Handle the error. MessageBox(NULL,"COM1 Setup Failure",NULL,MB_OK); return 1; } // We will build on the current configuration, and skip setting the size // of the input and output buffers with SetupComm. fSuccess = GetCommState(uart, &dcb); if (!fSuccess) { // Handle the error. MessageBox(NULL,"COM1 Setup Failure",NULL,MB_OK); return 1; } dcb.BaudRate = 9600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; fSuccess = SetCommState(uart, &dcb); if (!fSuccess) { // Handle the error. MessageBox(NULL,"COM1 Setup Failure",NULL,MB_OK); return 1; } //set the mask to check for character received events SetCommMask(uart,EV_RXCHAR); //create the window to run the process from DialogBox(plugin.hDllInstance,MAKEINTRESOURCE(3),NULL,MainProc); return 0; } void config() { //create the config window DialogBox(plugin.hDllInstance,MAKEINTRESOURCE(2),NULL,ConfigProc); } void quit() { } __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() { return &plugin; }