void GUIDEMO_Touch(void) { #define ID_KEYBOARD 1 #define ID_TESTCAL 2 #define ID_CALIBRATE 3 int i, r; int XSize = LCD_GetXSize(); int YSize = LCD_GetYSize(); int XMid = XSize / 2; int YMid = YSize / 2; //GUIDEMO_NotifyStartNext(); GUIDEMO_HideInfoWin(); do { GUI_RECT rText;/*= {0, 80, XSize, 120};*/ BUTTON_Handle ahButton[3]; rText.x0=0; rText.y0=50; rText.x1=XSize; rText.y1=90; GUI_SetBkColor(GUI_BLUE); GUI_Clear(); GUI_DrawBitmap(&bmMicriumLogo, (XSize - 1 - bmMicriumLogo.XSize) / 2, 15); GUI_SetFont(&GUI_Font16B_1); GUI_DispStringInRect("µC/GUI Touch screen demo", &rText, GUI_TA_HCENTER | GUI_TA_VCENTER); ahButton[0] = BUTTON_Create( XMid - 50, YMid - 30, 100, 50, ID_CALIBRATE,BUTTON_CF_SHOW ); ahButton[1] = BUTTON_Create( XMid - 90, YMid + 30, 80, 30, ID_KEYBOARD, BUTTON_CF_SHOW ); ahButton[2] = BUTTON_Create( XMid + 10, YMid + 30, 80, 30, ID_TESTCAL,BUTTON_CF_SHOW ); BUTTON_SetText (ahButton[0], "Calibrate"); BUTTON_SetBkColor(ahButton[0], 0, GUI_RED); BUTTON_SetText (ahButton[1], "Keyboard"); BUTTON_SetText (ahButton[2], "Test calibration"); BUTTON_SetFont(ahButton[0], &GUI_FontComic18B_ASCII); r = GUIDEMO_WaitKey(); if (r==0) { r = ID_KEYBOARD; BUTTON_SetState(ahButton[1],BUTTON_STATE_PRESSED); GUIDEMO_Delay(500); } for (i=0; i< countof(ahButton); i++) { BUTTON_Delete(ahButton[i]); } switch (r) { case ID_KEYBOARD: init_uart0(); send_press_key(); break; case ID_CALIBRATE: _ExecCalibration(); break; case ID_TESTCAL: _TestCalibration(); break; } } while (r && (r!='n') && (r!='N')); }
void _ExecCalibration(void) { int x,y; uint16_t data[6]; uint16_t get_data[6]; int ax_Phys[2],ay_Phys[2]; /* calculate log. Positions */ int ax[2] = { 15, LCD_XSIZE -1-15}; // const int ay[2] = { 15, LCD_YSIZE-1-15}; int ay[2] = { LCD_YSIZE-1-15, 15}; GUI_TOUCH_SetDefaultCalibration(); /* _Calibrate upper left */ GUI_SetBkColor(GUI_RED); GUI_Clear(); GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[0], ay[0], 10); GUI_SetColor(GUI_RED); GUI_FillCircle(ax[0], ay[0], 5); GUI_SetColor(GUI_WHITE); GUI_DispStringAt("Press here", ax[0]+20, ay[0]); do { #if 0 GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { #endif #if 1 x = TPReadX(); y = TPReadY(); if ((x>=3700)&&(y>=3400)&&(x<3800)&&(y<3600)) { #endif ax_Phys[0] = GUI_TOUCH_GetxPhys(); ay_Phys[0] = GUI_TOUCH_GetyPhys(); break; } GUI_Delay (3000); } while (1); /* Tell user to release */ GUI_Clear(); GUI_DispStringAt("OK", ax[0]+20, ay[0]); do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed == 0) { break; } GUI_Delay (100); } while (1); /* _Calibrate lower right */ GUI_SetBkColor(GUI_RED); GUI_Clear(); GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[1], ay[1], 10); GUI_SetColor(GUI_RED); GUI_FillCircle(ax[1], ay[1], 5); GUI_SetColor(GUI_WHITE); GUI_SetTextAlign(GUI_TA_RIGHT); GUI_DispStringAt("Press here", ax[1]-20, ay[1]); do { #if 1 x = TPReadX(); y = TPReadY(); if ((y>450)&&(y<620)&&(x>350)&&(x<450)) { #endif #if 0 GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { #endif ax_Phys[1] = GUI_TOUCH_GetxPhys(); ay_Phys[1] = GUI_TOUCH_GetyPhys(); break; } GUI_Delay (3000); } while (1); GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]); GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]); { /* calculate and display values for configuration file */ int x0, x1; int y0, y1; GUI_Clear(); _Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1); _Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1); GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine(); GUI_DispString ("x1: "); GUI_DispDec(x1, 4); GUI_DispNextLine(); GUI_DispString ("y0: "); GUI_DispDec(y0, 4); GUI_DispNextLine(); GUI_DispString ("y1: "); GUI_DispDec(y1, 4); GUI_DispNextLine(); GUI_DispString ("Please touch display to continue..."); GUI_Delay(1000); data[0]= CAL_READY; data[1]= ax_Phys[0]; data[2]= ay_Phys[0]; data[3]= ax_Phys[1]; data[4]= ay_Phys[1]; #if 1 save_calibrate_to_flash(data); get_calibrate_data(get_data); GUI_DispStringAt("x0: ", 100, 0); GUI_DispDec(get_data[1], 4); GUI_DispNextLine(); GUI_DispString ("x1: "); GUI_DispDec(get_data[2], 4); GUI_DispNextLine(); GUI_DispString ("y0: "); GUI_DispDec(get_data[3], 4); GUI_DispNextLine(); GUI_DispString ("y1: "); GUI_DispDec(get_data[4], 4); GUI_DispNextLine(); GUI_DispString ("state: "); GUI_DispDec(get_data[0], 4); GUI_DispNextLine(); #endif do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) break; GUI_Delay (10); } while (1); } } int run_cal(void) { if(get_calibrate_state()== CAL_READY) { get_calibration(); }else{ #if 1 _ExecCalibration(); #endif #if 0 Calibration(); #endif } } int get_calibration(void) { uint16_t cal_data[5]; int ax_Phys[2],ay_Phys[2]; int ax[2] = { 15, LCD_XSIZE -1-15}; int ay[2] = { LCD_YSIZE-1-15, 15}; get_calibrate_data(cal_data); ax_Phys[0] = cal_data[1]; ay_Phys[0] = cal_data[2]; ax_Phys[1] = cal_data[3]; ay_Phys[1] = cal_data[4]; GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]); GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]); } #if 0 void myAD2XY( int *adx , int *ady ){ float f_dat; int dat1; f_dat = (float)(*ady - admy)/(float)(*adx - admx); if(f_dat>0){ if( *adx>admx && admk[2] >=f_dat) dat1 = 1; else if( *adx>admx && admk[2] < f_dat ) dat1 =2;//2 else if( *adx<admx && admk[0] >=f_dat ) dat1 =0; else if( *adx<admx && admk[0] < f_dat ) dat1 =3;//0 else{ dat1 =0; }//*adx =0;*ady =0; } }else{ if( *adx>admx && admk[1] >=f_dat) dat1 = 0; else if( *adx>admx && admk[1] < f_dat ) dat1 =1;//1 else if( *adx<admx && admk[3] >=f_dat ) dat1 =3; else if( *adx<admx && admk[3] < f_dat ) dat1 =2;//3 else{ dat1 =0; }//*adx =0;*ady =0; } } *adx = (int)(Factors[dat1][0].a*(*adx)+Factors[dat1][0].b*(*ady)+Factors[dat1][0].c); *ady = (int)(Factors[dat1][1].a*(*adx)+Factors[dat1][1].b*(*ady)+Factors[dat1][1].c); }
void vHeartbeatTask (void * pvParameters){ int Key, Entries, ySize; uint16_t click_cnt=0; int8_t Item_nb; BUTTON_Handle hOK_Button, hTest_Key; LISTBOX_Handle hStationListBox; static enum GuiState eGuiState = SELECT; static const GUI_ConstString StationList[] = {"ZET", "RMFFM", "RMFMAXXX", "SKY.FM", "ESKA ROCK", "TERMINAL", NULL}; vSemaphoreCreateBinary(xButton_pushed_Semaphore); if(xDMAch1_Semaphore != NULL){ xSemaphoreTake(xButton_pushed_Semaphore, 0); }else{ // The semaphore was not created } BUTTON_Config(); //INT0 Button as source of interrupt xSemaphoreTake(xButton_pushed_Semaphore, 0); xListBoxQueue = xQueueCreate(2, sizeof(int8_t)); GUI_Init(); if(0){ _ExecCalibration(); }else{ _DefaultCalibration(); } GUI_SetBkColor(GUI_BLUE); GUI_Clear(); if (xSemaphoreTake(xDhcpCmplSemaphore_1, portMAX_DELAY) == pdTRUE) { /* OK button */ hOK_Button = BUTTON_CreateEx(120, 210, 80, 20, 0, WM_CF_SHOW, 0, 12); GUI_SetFont(&GUI_Font32_ASCII); BUTTON_SetText(hOK_Button, "OK"); /* Cancel button */ hTest_Key = BUTTON_CreateEx(120, 180, 80, 20, 0, WM_CF_SHOW, 0, 13); GUI_SetFont(&GUI_Font16B_ASCII); BUTTON_SetText(hTest_Key, "CLICK"); WM_SetStayOnTop(hTest_Key, 1); /* Station list */ Entries = 6;//countof(StationList) - 1; ySize = GUI_GetYDistOfFont(&GUI_Font16B_ASCII)*Entries; hStationListBox = LISTBOX_CreateEx(100, 10, 120, ySize, 0, WM_CF_SHOW, 0, 5, StationList); SCROLLBAR_CreateAttached(hStationListBox, SCROLLBAR_CF_VERTICAL); } while(1){ Key = GUI_GetKey(); //top = WM_GetStayOnTop(hTest_Key); switch(eGuiState){ case SELECT: switch (Key){ case 12: Item_nb = LISTBOX_GetSel(hStationListBox); if(Item_nb >= 0){ if(xQueueSendToBack(xListBoxQueue, &Item_nb, 50/portTICK_RATE_MS) == pdPASS){ /* OK button delete */ BUTTON_Delete(hOK_Button); GUI_SetBkColor(GUI_BLUE); GUI_ClearRect(120, 210, 200, 230); GUI_ClearKeyBuffer(); /* Listbox delete */ LISTBOX_Delete(hStationListBox); GUI_ClearRect(100, 10, 220, ySize+10); eGuiState = PLAYING; } } vTaskResume(xShoutcastTaskHandle); break; case 13: click_cnt++; GUI_SetFont(&GUI_Font16B_ASCII); Item_nb = LISTBOX_GetSel(hStationListBox); GUI_DispStringAt("CNT = ", 0, 210); GUI_DispDecSpace(Item_nb, 3); break; default: break; } break; case PLAYING: switch (Key){ case 13: click_cnt++; GUI_SetFont(&GUI_Font16B_ASCII); // Item_nb = LISTBOX_GetSel(hStationListBox); GUI_DispStringAt("CNT = ", 0, 210); GUI_DispDecSpace(123, 3); break; default: break; } } vTaskDelay(20/portTICK_RATE_MS); } }