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.
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
touchScreenJPA.cpp
00001 00002 #include "stm32746g_discovery_lcd.h" 00003 #include "stm32746g_discovery_ts.h" 00004 #include "mbed.h" 00005 //#include "GroveStreams.h" 00006 #include "MbedJSONValue.h" 00007 Timer timer_touch[16]; 00008 Timer timer_lcd; 00009 00010 void sendSerial2(char * str); 00011 void sendSerial7(char * str); 00012 00013 int initDisplayTemp(); 00014 // GroveStreams Settings 00015 //extern const char gsApiKey[];// = "YOUR_SECRET_API_KEY_HERE"; //Change This!!! 00016 extern const char gsCompName[];// = "STM32F746+Discovery"; //Optionally change. Set this to give your component a name when it initially registers. Encode special chars such as spaces. 00017 extern const char gsCompTmplId[]; //Optional. Tells GS what template to use when the feed initially arrives and a new component needs to be created. 00018 ////GroveStreams groveStreams(gsApiKey, &lcd); 00019 //extern GroveStreams groveStreams; 00020 extern const char* myMac; 00021 extern time_t seconds; 00022 time_t seconds_touches = 0; 00023 extern time_t lastToucheTime; 00024 // char touch1_text1; 00025 extern int ethernet_actif ; // use ethernet connection 00026 extern int wifi_actif ; // use wifi connection 00027 00028 // ----------------------------------------------------------------- 00029 int touchInitJPA1() 00030 { //touch screen init 00031 //touch screen 00032 uint8_t status; 00033 BSP_LCD_Init(); 00034 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); 00035 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); 00036 BSP_LCD_SetFont(&Font12); 00037 status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); 00038 if (status != TS_OK) 00039 { BSP_LCD_Clear(LCD_COLOR_RED); 00040 BSP_LCD_SetBackColor(LCD_COLOR_RED); 00041 BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 00042 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); 00043 } 00044 else 00045 { BSP_LCD_Clear(LCD_COLOR_DARKBLUE); 00046 BSP_LCD_SetBackColor(LCD_COLOR_BLACK); 00047 BSP_LCD_SetTextColor(LCD_COLOR_GREEN); 00048 //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); 00049 } 00050 int tt = 0; 00051 for (tt=0;tt<16;tt++) 00052 { if(timer_touch[tt].read_ms() > 500) 00053 { timer_touch[tt].stop();timer_touch[tt].reset(); 00054 } 00055 } 00056 return 0; 00057 } 00058 // ------------------------------------------------------- 00059 int xButton[5],yButton[5],dxButton[5],dyButton[5],xTxtButton[5],yTxtButton[5]; 00060 uint32_t backColorButton[5], txtColorButton[5]; 00061 extern char textButton[5][8]; 00062 extern char text1Button[5][8]; 00063 char statusButton[5][30]; 00064 00065 // ----------------------------------------------------------------------------------------- 00066 int touchButtonJPA1(int numButton) 00067 { if ((numButton > 0) && (numButton < 5)) 00068 { BSP_LCD_SetBackColor(backColorButton[numButton]); 00069 BSP_LCD_SetTextColor(backColorButton[numButton]); 00070 BSP_LCD_FillRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); 00071 BSP_LCD_SetTextColor(txtColorButton[numButton]); 00072 BSP_LCD_DrawRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); 00073 BSP_LCD_SetFont(&Font20); 00074 BSP_LCD_DisplayStringAt(xTxtButton[numButton]+52, yTxtButton[numButton], (uint8_t *)statusButton[numButton], LEFT_MODE); 00075 BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+28, (uint8_t *)textButton[numButton], LEFT_MODE); 00076 BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+48, (uint8_t *)text1Button[numButton], LEFT_MODE); 00077 } 00078 return 0; 00079 } 00080 00081 // ---------------------------------------------------------------------------------- 00082 // generation de fonts : http://omz-software.com/pythonista/docs/ios/ImageFont.html 00083 int touchInitGuiJPA1() 00084 { // button 1 en bas a gauche 00085 xButton[1]=10;yButton[1]=185;dxButton[1]=100;dyButton[1]=80;xTxtButton[1]=12;yTxtButton[1]=190; 00086 backColorButton[1] = LCD_COLOR_GRAY; 00087 txtColorButton[1] = LCD_COLOR_GREEN; 00088 //sprintf(textButton[1],"Lampe "); 00089 //sprintf(text1Button[1],"Sejour"); 00090 sprintf(statusButton[1],"off"); 00091 // bouton 2 a cote bouton 1 00092 xButton[2]=130;yButton[2]=185;dxButton[2]=100;dyButton[2]=80;xTxtButton[2]=132;yTxtButton[2]=190; 00093 backColorButton[2] = LCD_COLOR_GRAY; txtColorButton[2] = LCD_COLOR_GREEN; 00094 //sprintf(textButton[2],"Lampe "); 00095 //sprintf(text1Button[2],"Sejours"); 00096 sprintf(statusButton[2],"off"); 00097 // bouton 3 00098 xButton[3]=250;yButton[3]=185;dxButton[3]=100;dyButton[3]=80;xTxtButton[3]=252;yTxtButton[3]=190; 00099 backColorButton[3] = LCD_COLOR_GRAY; txtColorButton[3] = LCD_COLOR_GREEN; 00100 //sprintf(textButton[3],"Lampe "); 00101 //sprintf(text1Button[3],"Sejour"); 00102 sprintf(statusButton[3],"off"); 00103 // bouton 4 en bas a ddroite 00104 xButton[4]=370;yButton[4]=185;dxButton[4]=100;dyButton[4]=80;xTxtButton[4]=372;yTxtButton[4]=190; 00105 backColorButton[4] = LCD_COLOR_GRAY; txtColorButton[4] = LCD_COLOR_GREEN; 00106 //sprintf(textButton[4],"Lampe "); 00107 //sprintf(text1Button[4],"Sejour"); 00108 sprintf(statusButton[4],"off"); 00109 00110 touchButtonJPA1(1); 00111 touchButtonJPA1(2); 00112 touchButtonJPA1(3); 00113 touchButtonJPA1(4); 00114 00115 BSP_LCD_SetFont(&FontFreeMono64); 00116 //BSP_LCD_DisplayStringAt(20, 30, (uint8_t *)"0123456789", LEFT_MODE); 00117 //BSP_LCD_DisplayCharJPA(20, 90, '8'); 00118 BSP_LCD_SetFont(&Font12); 00119 return 0; 00120 } 00121 00122 // -------------------------------------------------------------------------- 00123 int touchJPA1() 00124 { //touch screen 00125 TS_StateTypeDef TS_State; 00126 uint16_t x, y; 00127 uint8_t text[30]; 00128 uint8_t status = 0; 00129 uint8_t idx; 00130 static uint8_t cleared = 0; 00131 uint8_t prev_nb_touches = 0; 00132 int tt = 0; 00133 for (tt=0;tt<16;tt++) 00134 {if(timer_touch[tt].read_ms() > 200) 00135 {timer_touch[tt].stop();timer_touch[tt].reset();}} 00136 //touch screen 00137 BSP_TS_GetState(&TS_State); 00138 if (TS_State.touchDetected) { 00139 // Clear lines corresponding to old touches coordinates 00140 if (TS_State.touchDetected < prev_nb_touches) { 00141 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { 00142 //BSP_LCD_ClearStringLine(idx); 00143 } 00144 } 00145 prev_nb_touches = TS_State.touchDetected; 00146 cleared = 0; 00147 //sprintf((char*)text, "Touches: %d", TS_State.touchDetected); 00148 //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); 00149 for (idx = 0; idx < TS_State.touchDetected; idx++) { 00150 x = TS_State.touchX[idx]; 00151 y = TS_State.touchY[idx]; 00152 //sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); 00153 //BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); 00154 } 00155 00156 //BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); 00157 if ((TS_State.touchY[0] > 160) && (TS_State.touchY[0] < (160+80))) 00158 { int numTouche = 0; 00159 if ((TS_State.touchX[0] > 10) && (TS_State.touchX[0] < (10+100))) 00160 {if(timer_touch[0].read_ms() == 0) {numTouche = 1;timer_touch[0].start();}} 00161 if ((TS_State.touchX[0] > 130) && (TS_State.touchX[0] < (130+100))) 00162 {if(timer_touch[1].read_ms() == 0) {numTouche = 2;timer_touch[1].start();}} 00163 if ((TS_State.touchX[0] > 250) && (TS_State.touchX[0] < (250+100))) 00164 {if(timer_touch[2].read_ms() == 0) {numTouche = 3;timer_touch[2].start();}} 00165 if ((TS_State.touchX[0] > 370) && (TS_State.touchX[0] < (370+100))) 00166 {if(timer_touch[3].read_ms() == 0) {numTouche = 4;timer_touch[3].start();}} 00167 if (numTouche >0) 00168 { printf("Touche : %d", numTouche); 00169 sprintf((char*)text, "Touche : %d", numTouche); 00170 //BSP_LCD_DisplayStringAt(200,0, (uint8_t *)&text, LEFT_MODE); 00171 status = numTouche; 00172 } 00173 else 00174 {lastToucheTime = 0; 00175 } 00176 } 00177 else 00178 { 00179 int numTouche = 9; 00180 printf("Touche : %d", numTouche); 00181 timer_lcd.stop(); // stop the timer 00182 timer_lcd.reset(); // reset the timer 00183 BSP_LCD_DisplayOn(); 00184 } 00185 } else { 00186 lastToucheTime = 0; 00187 if (!cleared) { 00188 //BSP_LCD_Clear(LCD_COLOR_DARKBLUE); 00189 //sprintf((char*)text, "Touches: 0"); 00190 //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); 00191 //cleared = 1; 00192 //int ss = touchInitGuiJPA1(); 00193 //ss=initDisplayTemp(); 00194 } 00195 } 00196 //touch screen 00197 return status; 00198 } 00199 00200 // ----------------------------------------------------------------------- 00201 int sendTouchJPA(int xx) 00202 { uint8_t status = 0; 00203 seconds = time(NULL); 00204 if((seconds - lastToucheTime) > 1) 00205 { char samples[64] = {0};char resultBuffer[2000]= {0}; 00206 sprintf(samples,"&Touche=%i",xx); 00207 printf("\nSend Touche=%i\n",xx); 00208 // modifier pour rajouter test ethernet / wifi et action en fonction 00209 if (ethernet_actif == 1 ) // ethernet actif 00210 { printf("\ntraitement Ethernet\n",xx); 00211 ///////////// int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); 00212 int sendResult = 0; 00213 if (sendResult == 0) 00214 { ////lcd.printf("Send Successful"); 00215 printf("Send Successful\n"); 00216 if (strlen(resultBuffer) > 0) 00217 { //printf("HTTP string : %s\n", resultBuffer); 00218 MbedJSONValue mbedJson; 00219 parse(mbedJson, resultBuffer); 00220 int displayOn = 0; 00221 string s; 00222 if (mbedJson.hasMember("Touche1")) 00223 { s = mbedJson["Touche1"]["BackColor"].get<std::string>(); 00224 backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); 00225 s = mbedJson["Touche1"]["TextColor"].get<std::string>(); 00226 txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); 00227 s = mbedJson["Touche1"]["Status"].get<std::string>(); 00228 sprintf(statusButton[1],s.c_str()); 00229 displayOn = (0x02 | displayOn); 00230 } 00231 if (mbedJson.hasMember("Touche2")) 00232 { s = mbedJson["Touche2"]["BackColor"].get<std::string>(); 00233 backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); 00234 s = mbedJson["Touche2"]["TextColor"].get<std::string>(); 00235 txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); 00236 s = mbedJson["Touche2"]["Status"].get<std::string>(); 00237 sprintf(statusButton[2],s.c_str()); 00238 displayOn = (0x04 | displayOn); 00239 } 00240 if (mbedJson.hasMember("Touche3")) 00241 { s = mbedJson["Touche3"]["BackColor"].get<std::string>(); 00242 backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); 00243 s = mbedJson["Touche3"]["TextColor"].get<std::string>(); 00244 txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); 00245 s = mbedJson["Touche3"]["Status"].get<std::string>(); 00246 sprintf(statusButton[3],s.c_str()); 00247 displayOn = (0x08 | displayOn); 00248 } 00249 if (mbedJson.hasMember("Touche4")) 00250 { s = mbedJson["Touche4"]["BackColor"].get<std::string>(); 00251 backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); 00252 s = mbedJson["Touche4"]["TextColor"].get<std::string>(); 00253 txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); 00254 s = mbedJson["Touche4"]["Status"].get<std::string>(); 00255 sprintf(statusButton[4],s.c_str()); 00256 displayOn = (0x10 | displayOn); 00257 } 00258 if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);} 00259 if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);} 00260 if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);} 00261 if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);} 00262 }// fin test result buffer 00263 } // fin test send result 00264 } // fin test ethernet actif 00265 else if (wifi_actif == 1) // wifi actif -------------------------------- 00266 { // send trame to wifi to inform touch pressed 00267 printf("\nSend Touche=%i status=%s \n ",xx,statusButton[4] ); 00268 // {"Touche":{ "No":"4","Statusl":"Off"}} 00269 sprintf(samples,"{\"Touche\":{\"No\":\"%i\",\"Status\":\"%s\"}}",xx,statusButton[xx]); 00270 printf(samples); 00271 printf ("\n"); 00272 sendSerial2(samples); 00273 } 00274 else // traitement en local 00275 { printf("\nTraitement local\n"); 00276 } 00277 } 00278 return status; 00279 }
Generated on Wed Jul 13 2022 16:31:24 by
1.7.2