int main(void) { SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); LED_Init(LED_PinLookup_CHK60EVB, kNumOfLED); UART_DebugPortInit(UART4_RX_C14_TX_C15, 115200); DisplayCPUInfo(); GUI_Init(&CHGUI_InitStruct1); GUI_SetFontFormName("FONT_CourierNew"); while(1) { GUI_GotoXY(0, 0); GUI_TOUCH_GetState(&State); //打印物理AD坐标 GUI_printf("Phy:X:%04d Y:%04d\r\n", GUI_TOUCH_GetxPhys(), GUI_TOUCH_GetyPhys()); //打印逻辑AD坐标 GUI_printf("Log:X:%04d Y:%04d\r\n", State.x, State.y); GUI_printf("State:%01d\r\n", State.Pressed); //LCD 画笔跟踪 GUI_DrawPoint(State.x, State.y); DelayMs(10); //GUI 触摸屏处理函数 每10MS调用一次 GUI_TOUCH_Exec(); } }
/********************************************************************* * * 在触摸校正的时候使用这个来读取ADC的值 */ void Touch_MainTask(void) { GUI_CURSOR_Show(); GUI_CURSOR_Select(&GUI_CursorCrossL); GUI_SetBkColor(GUI_WHITE); GUI_SetColor(GUI_BLACK); GUI_Clear(); GUI_DispString("Measurement of\nA/D converter values"); while (1) { GUI_PID_STATE TouchState; int xPhys, yPhys; GUI_TOUCH_GetState(&TouchState); /* Get the touch position in pixel */ xPhys = GUI_TOUCH_GetxPhys(); /* Get the A/D mesurement result in x */ yPhys = GUI_TOUCH_GetyPhys(); /* Get the A/D mesurement result in y */ /* Display the measurement result */ GUI_SetColor(GUI_BLUE); GUI_DispStringAt("Analog input:\n", 0, 20); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(xPhys, 4); GUI_DispString(", y:"); GUI_DispDec(yPhys, 4); /* Display the according position */ GUI_SetColor(GUI_RED); GUI_GotoY(GUI_GetDispPosY() + 4); GUI_DispString("\nPosition:\n"); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(TouchState.x,4); GUI_DispString(", y:"); GUI_DispDec(TouchState.y,4); /* Wait a while */ GUI_Delay(100); }; }
void _TestCalibration(void) { int IdleCnt=0; BUTTON_Handle hButton; GUI_SetBkColor(GUI_RED); GUI_SetColor(GUI_WHITE); GUI_Clear(); hButton = BUTTON_Create( 225, 15, 80, 40, 1, BUTTON_CF_SHOW ); BUTTON_SetText (hButton, "ABORT"); BUTTON_SetFont (hButton, &GUI_FontComic18B_ASCII); while ((IdleCnt<50) && (GUI_GetKey()==0)) { static GUI_PID_STATE StateLast; GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if ((StateLast.Pressed != State.Pressed) && (State.Pressed == 0)) { GUI_Clear(); } if ((StateLast.x != State.x) || ((StateLast.y != State.y))) { if (State.Pressed) { GUI_FillCircle(State.x, State.y, 5); } StateLast = State; } if (State.Pressed) { IdleCnt =0; } else { IdleCnt++; } GUI_Delay (100); } EDIT_Delete(hButton); }
void Calibration(void) { int ax_Phys[5],ay_Phys[5]; int move; /* calculate log. Positions */ int ax[5] = { 50, LCD_XSIZE-50, LCD_XSIZE-50, 50, (LCD_XSIZE/2)-10}; int ay[5] = { 50, 50, LCD_YSIZE-50, LCD_YSIZE-50, (LCD_YSIZE/2)-10}; // GUI_TOUCH_SetDefaultCalibration(); /* _Calibrate upper left */ for( move =0 ; move<5; move++){ GUI_SetBkColor(GUI_RED); GUI_Clear(); GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[move], ay[move], 10); GUI_SetColor(GUI_RED); GUI_FillCircle(ax[move], ay[move], 5); GUI_SetColor(GUI_WHITE); do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { ax_Phys[move] = State.x;//GUI_TOUCH_GetxPhys(); ay_Phys[move] = State.y;//GUI_TOUCH_GetyPhys(); break; } GUI_Delay (100); } while (1); GUI_Delay (4000); /* release */ GUI_TOUCH_StoreState(-1,-1); } GUI_myTOUCH_Calibrate(ax,ay,ax_Phys,ay_Phys); GUI_Delay(500); GUI_DispStringAt ("Please touch display to continue...",50,20); GUI_TOUCH_StoreState(-1,-1); do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) break; GUI_Delay (10); } while (1); }
/********************************************************************* * * _WaitForPressedState * * Purpose: * Waits until the touch is in the given pressed state for at least 250 ms */ static void _WaitForPressedState(int Pressed) { GUI_PID_STATE State; do { GUI_TOUCH_GetState(&State); GUI_Delay(10); if (State.Pressed == Pressed) { int TimeStart = GUI_GetTime(); do { GUI_TOUCH_GetState(&State); GUI_Delay(10); if (State.Pressed != Pressed) { break; } else if ((GUI_GetTime() - 150) > TimeStart) { return; } } while (1); } } while (1); }
/********************************************************************* * * _WaitForPressedState * * Purpose: * Waits until the touch is in the given pressed state for at least 150 ms * pressed 1:表示触摸按下 。0:没有按下 */ static void _WaitForPressedState(int Pressed) { GUI_PID_STATE State; do { GUI_TOUCH_GetState(&State); /*获取触摸的状态*/ GUI_Delay(10); /*该函数调用GUI_X_Delay()*/ if (State.Pressed == Pressed) { /*如果触摸按下*/ int TimeStart = GUI_GetTime();/*获取GUI起始时间*/ do { GUI_TOUCH_GetState(&State); GUI_Delay(10); if (State.Pressed != Pressed) { /*如果确实没有按下返回,反之延时*/ break; } else if ((GUI_GetTime() - 150) > TimeStart) { return; } } while (1); } } while (1); }
int main(void) { DelayInit(); GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200); printf("spi touch screen test\r\n"); /* 初始化SPI2 接口连接触控屏的触控芯片*/ SPI_QuickInit(SPI2_SCK_PD12_SOUT_PD13_SIN_PD14, kSPI_CPOL0_CPHA0, 2*1000*1000); PORT_PinMuxConfig(HW_GPIOD, 11, kPinAlt2); /* SPI2_PCS0 */ /* 初始化触控芯片 使用CS0片选 */ ads7843_init(HW_SPI2, HW_SPI_CS0); GUI_Init();//液晶屏界面初始化 GUI_SetBkColor(GUI_WHITE); //设置背景色 GUI_SetColor(GUI_BLACK); //设置前景色 GUI_Clear(); //清屏 GUI_SetPenSize(3); //设置点的大小 GUI_DispString("Measurement of\nA/D converter values"); while (1) { GUI_PID_STATE TouchState; int xPhys, yPhys; GUI_TOUCH_GetState(&TouchState); /* 获得触控位置 */ xPhys = GUI_TOUCH_GetxPhys(); /* 获得x轴的测量值 */ yPhys = GUI_TOUCH_GetyPhys(); /* 获得y轴的测量值 */ /* 显示测量结果 */ GUI_SetColor(GUI_BLUE); GUI_DispStringAt("Analog input:\n", 0, 20); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(xPhys, 4); GUI_DispString(", y:"); GUI_DispDec(yPhys, 4); /* Display the according position */ GUI_SetColor(GUI_RED); GUI_GotoY(GUI_GetDispPosY() + 4); GUI_DispString("\nPosition:\n"); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(TouchState.x,4); GUI_DispString(", y:"); GUI_DispDec(TouchState.y,4); GUI_DrawPoint(TouchState.x, TouchState.y); GUI_TOUCH_Exec(); } }
/********************************************************************* * * _GetPhysValues * * Purpose: * Asks the user to press the touch screen at the given position * and returns the physical pixels(A/D) values */ static void _GetPhysValues(int LogX, int LogY, int * pPhysX, int * pPhysY, const char * pString) { char acText[] = "Press here"; GUI_RECT Rect; GUI_PID_STATE State; int FontSizeY, Align; FontSizeY = GUI_GetFontSizeY(); /*获取字体的高度*/ GUI_Clear(); GUI_SetColor(GUI_BLACK); _DispStringCentered("Runtime calibration,\n" "please touch the corners of the screen\n" "at the center of the rings."); /* Ask user to press the touch */ /* Calculate the rectangle for the string(根据触摸点的位置,设置文字显示的区域) */ if (LogX < LCD_GetXSize() / 2) {/*判断是左上角的点,还是有下角的点*/ Rect.x0 = LogX + 25; Rect.x1 = LCD_GetXSize(); Rect.y0 = LogY - FontSizeY + 5; /*设置大小能显示两行字符*/ Rect.y1 = LogY + FontSizeY + 5; Align = GUI_TA_LEFT; } else { Rect.x0 = 0; Rect.x1 = LogX - 25; Rect.y0 = LogY - FontSizeY - 5; Rect.y1 = LogY + FontSizeY - 5; Align = GUI_TA_RIGHT; } /* Show the text nearby the ring */ GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP); GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM); /* Draw the ring */ GUI_FillCircle(LogX, LogY, 10); GUI_SetColor(GUI_WHITE); GUI_FillCircle(LogX, LogY, 7); GUI_SetColor(GUI_BLACK); /* Wait until touch is pressed */ _WaitForPressedState(1); /*得到触摸点的值*/ GUI_TOUCH_GetState(&State); *pPhysX = State.x; *pPhysY = State.y; /* Wait until touch is released */ _WaitForPressedState(0); }
void show_bitmap() { int ax_Phys[2],ay_Phys[2],i; unsigned char *images[] = { gImage_terminator_large, gImage_britney }; //clear_buttons_and_frames(); GUIDEMO_ShowIntro("Photographic Bitmap", "Showing" "\nTerminator Sarah Connor Chronicles" "\nBy Siddharth Kaul"); GLCD_Init (); GLCD_Clear (White); i = 0; do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { GLCD_Clear(White); GLCD_Bitmap(0, 0, 320, 240, images[i]); i++; if(i > 1) { i = 0; } //break; } }while(1);//end of do while //delete pointer to free up memory free(images); /* GUI_SetFont(&GUI_Font24B_1); GUI_SetColor(GUI_YELLOW); GUI_DispStringAt("Terminator", 0,0);*/ }
/********************************************************************* * * MainTask */ void MainTask_TOUCHCAL(void) { int aPhysX[2], aPhysY[2], aLogX[2], aLogY[2], i; GUI_Init(); GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetColor(GUI_BLACK); GUI_SetFont(&GUI_Font13B_ASCII); _Explain(); /* Set the logical values */ aLogX[0] = 15; aLogY[0] = 15; aLogX[1] = LCD_GetXSize() - 15; aLogY[1] = LCD_GetYSize() - 15; /* Get the physical values of the AD converter for 2 positions */ for (i = 0; i < 2; i++) { _GetPhysValues(aLogX[i], aLogY[i], &aPhysX[i], &aPhysY[i], _acPos[i]); } /* Use the physical values to calibrate the touch screen */ GUI_TOUCH_Calibrate(0, aLogX[0], aLogX[1], aPhysX[0], aPhysX[1]); /* Calibrate X-axis */ //如果我们要存到外部存储器中 那么就存储这里的8个参数 GUI_TOUCH_Calibrate(1, aLogY[0], aLogY[1], aPhysY[0], aPhysY[1]); /* Calibrate Y-axis */ /* Display the result */ GUI_CURSOR_Show(); GUI_Clear(); _DispStringCentered("Congratulation, your\n" "touch screen has been\n" "calibrated. Please use\n" "the cursor to test\n" "the calibration..."); /* Let the user play */ while(1) { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed == 1) { GUI_FillCircle(State.x, State.y, 3); } GUI_Delay(10); } }
void MainTask(void) { GUI_PID_STATE TouchState; GUI_Init(); GUI_CURSOR_Show(); GUI_Delay(1000); GUI_CURSOR_Select(&GUI_CursorCrossL); GUI_Delay(1000); while (1) { GUI_TOUCH_GetState(&TouchState); GUI_DispStringAt("Analog input: ", 0, 40); GUI_DispDec(GUI_TOUCH_GetxPhys(),4); GUI_DispString(","); GUI_DispDec(GUI_TOUCH_GetyPhys(),4); GUI_DispStringAt("TOUCH_X_MeasureX: ",0,60); GUI_DispDec(TouchState.x,4); GUI_DispString(","); GUI_DispDec(TouchState.y,4); GUI_Delay(100); }; }
void _ExecCalibration(void) { 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}; CalibrationComplete = 0; 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 { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { ax_Phys[0] = GUI_TOUCH_GetxPhys(); ay_Phys[0] = GUI_TOUCH_GetyPhys(); break; } GUI_Delay (100); } 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 { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) { ax_Phys[1] = GUI_TOUCH_GetxPhys(); ay_Phys[1] = GUI_TOUCH_GetyPhys(); break; } GUI_Delay (100); } 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); do { GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if (State.Pressed) break; GUI_Delay (10); } while (1); } CalibrationComplete = 1; }
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); }
/** * @brief Callback routine of dialog * @param pMsg: pointer to data structure of type WM_MESSAGE * @retval None */ static void _cbDialog(WM_MESSAGE * pMsg) { WM_HWIN hItem; int Id, NCode; TREEVIEW_ITEM_Handle hTreeView; TREEVIEW_ITEM_INFO Info; GUI_PID_STATE State; switch (pMsg->MsgId) { case WM_INIT_DIALOG: pFileList = (FILELIST_FileTypeDef *)k_malloc(sizeof(FILELIST_FileTypeDef)); pFileList->ptr = 0; hPopUp = WM_CreateWindowAsChild(0, 26, LCD_GetXSize(), LCD_GetYSize()-26, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS , _cbPopup, 0); WM_BringToBottom(hPopUp); hItem = pMsg->hWin; FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0); WM_CreateWindowAsChild(240, 320, 1, 1, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbMediaConnection , 0); _RefreshBrowser(pMsg->hWin); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */ NCode = pMsg->Data.v; /* Notification code */ switch (NCode) { case WM_NOTIFICATION_CHILD_DELETED: k_free(pFileList); if(hFileInfo != 0) { hFileInfo = 0; } break; case WM_NOTIFICATION_CLICKED: /* React only if released */ switch (Id) { case ID_TREEVIEW: hTreeView = TREEVIEW_GetSel(pMsg->hWinSrc); TREEVIEW_ITEM_GetInfo(hTreeView, &Info); if(Info.IsNode == 0) { GUI_TOUCH_GetState(&State); State.x += 20; if(State.x > 175) { State.x = 175; } State.y-= 50; if(State.y > 150) { State.y -= 70; } _FindFullPath(pMsg->hWinSrc, hTreeView, SelectedFileName); /* Create popup menu after touching the display */ _OpenPopup(hPopUp, _aMenuItems, GUI_COUNTOF(_aMenuItems), State.x, State.y); } break; case ID_BUTTON_REFRESH: _RefreshBrowser (pMsg->hWin); break; } break; } break; default: WM_DefaultProc(pMsg); break; } }
void MainTask_2D_text_bmp(void) { int i; horPos = ICONS_HOR_POS; verPos = ICONS_VER_POS; iconTouched = 0xFF; SetemWinRunning(1); GUI_SelectLayer(1); // select foregroung layer GUI_SetBkColor(GUI_TRANSPARENT); // select background as transparent color GUI_Clear(); // fill with the background color // get the number of icons iconNumber = GUI_COUNTOF(iconDrawFunctions); // compute padding to fit to whole display iconPadding = ((GUI_GetScreenSizeY() - (iconNumber * ICON_SIZE) - 2*ICONS_VER_POS) / iconNumber); // start time measurement timeMeasureStart(); // draw a background bitmap to the bottom LCD layer GUI_SelectLayer(0); // select the background layer // !! TO BE MODIFIED !! GUI_DrawBitmap(&bmbackground, 0, 0); GUI_SelectLayer(1); // set back the foregroung layer // now draw our icons one by one for (i = 0; i < iconNumber; i++) { iconDrawFunctions[i](horPos, verPos, ICON_SIZE); verPos += ICON_SIZE + iconPadding; } // add a title text GUI_SetTextMode(GUI_TM_TRANS); GUI_SetFont(&GUI_FontTimesNewRoman31); LCD_AA_SetAndMask(0xFFFFFFFF); GUI_DispStringInRect("STM32 Player", &rect, GUI_TA_CENTER); LCD_AA_SetAndMask(0x00FFFFFF); // end measurement time = timeMeasureEnd(); GUI_SetFont(&GUI_Font8_1); sprintf (timeString, "time to render: %d,%dms", time/10, time%10); GUI_DispStringAt(timeString, 10, 320 - 10); // optionally we can use cursor GUI_CURSOR_Show(); // the GUI is now rendered // in never ending loop just check if an incon is touched while(!tamperPushed) { GUI_TOUCH_GetState(&TouchState); // Get the touch position in pixel if (TouchState.Pressed) { if (iconTouched == 0xFF) // no icon was touched previously { GUI_CURSOR_SetPosition(TouchState.x, TouchState.y); // move the cursor to current touch position // check if the touch is in icons area if (TouchState.x > ICONS_HOR_POS && TouchState.x < ICONS_HOR_POS + ICON_SIZE) { if(TouchState.y > ICONS_VER_POS && TouchState.y < ICONS_VER_POS + iconNumber*(ICON_SIZE + iconPadding)) { // get he number of touched icon iconTouched = (TouchState.y - ICONS_VER_POS) / (ICON_SIZE + iconPadding); ReDrawIcon(GUI_RED, iconTouched); // draw again with hihghlight color } } } } else { ReDrawIcon(GUI_WHITE, iconTouched); iconTouched = 0xFF; } } SetemWinRunning(0); GUI_CURSOR_Hide(); }