Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "stm32l496g_discovery_lcd.h" 00003 #include "stm32l496g_discovery_ts.h" 00004 00005 int main() 00006 { 00007 TS_StateTypeDef TS_State; 00008 uint16_t x, y; 00009 uint8_t text[30]; 00010 uint8_t idx; 00011 uint8_t cleared = 0; 00012 uint8_t prev_nb_touches = 0; 00013 00014 BSP_LCD_Init(); 00015 BSP_LCD_SetFont(&Font20); 00016 BSP_LCD_Clear(LCD_COLOR_BLUE); 00017 BSP_LCD_SetBackColor(LCD_COLOR_BLUE); 00018 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00019 BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"DISCO_L496AG", CENTER_MODE); 00020 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"LCDTS DEMO", CENTER_MODE); 00021 wait(1); 00022 00023 if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) != TS_OK) 00024 { 00025 BSP_LCD_Clear(LCD_COLOR_RED); 00026 BSP_LCD_SetBackColor(LCD_COLOR_RED); 00027 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00028 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TS INIT FAIL", CENTER_MODE); 00029 } 00030 else 00031 { 00032 BSP_LCD_Clear(LCD_COLOR_GREEN); 00033 BSP_LCD_SetBackColor(LCD_COLOR_GREEN); 00034 BSP_LCD_SetTextColor(LCD_COLOR_BLACK); 00035 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TS INIT OK", CENTER_MODE); 00036 } 00037 wait(0.5); 00038 00039 BSP_LCD_SetFont(&Font16); 00040 BSP_LCD_Clear(LCD_COLOR_BLUE); 00041 BSP_LCD_SetBackColor(LCD_COLOR_BLUE); 00042 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00043 00044 while(1) { 00045 00046 BSP_TS_GetState(&TS_State); 00047 00048 if (TS_State.touchDetected) 00049 { 00050 // Clear lines corresponding to old touches coordinates 00051 if (TS_State.touchDetected < prev_nb_touches) 00052 { 00053 for (idx = (TS_State.touchDetected + 1); idx <= TS_MAX_NB_TOUCH; idx++) 00054 { 00055 BSP_LCD_ClearStringLine(idx); 00056 } 00057 } 00058 prev_nb_touches = TS_State.touchDetected; 00059 00060 cleared = 0; 00061 00062 sprintf((char*)text, "Touches: %d", TS_State.touchDetected); 00063 BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); 00064 00065 for (idx = 0; idx < TS_State.touchDetected; idx++) 00066 { 00067 x = TS_State.touchX[idx]; 00068 y = TS_State.touchY[idx]; 00069 sprintf((char*)text, "Touch %d: x=%d y=%d", idx+1, x, y); 00070 BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); 00071 BSP_LCD_DrawHLine(x-10, y, 20); 00072 BSP_LCD_DrawVLine(x, y-10, 20); 00073 } 00074 } 00075 else 00076 { 00077 if (!cleared) 00078 { 00079 sprintf((char*)text, "Touches: 0"); 00080 BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); 00081 cleared = 1; 00082 } 00083 } 00084 00085 } 00086 00087 }
Generated on Mon Jul 25 2022 21:46:09 by
1.7.2