
updated version with parameters loaded from sdcard
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
Revision 3:2de8e4771674, committed 2020-09-02
- Comitter:
- jeanpierreaulas
- Date:
- Wed Sep 02 12:54:45 2020 +0000
- Branch:
- jpa
- Parent:
- 2:462b5c0d3472
- Child:
- 4:fbbf5d1785e7
- Commit message:
- Ethernet ok, Display OK, CAN Ok, SerialUSB OK
Changed in this revision
--- a/GettingStarted.html Tue Sep 01 06:37:15 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -<!DOCTYPE HTML> -<html lang="en-US"> - <head> - <meta charset="UTF-8"> - <meta http-equiv="refresh" - content="1;url="https://os.mbed.com/docs/latest/tools/exporting.html> - <script type="text/javascript"> - window.location.href = "https://os.mbed.com/docs/latest/tools/exporting.html" - </script> - <title>Page Redirection</title> - </head> - <body> - If you are not redirected automatically, please follow the - <a href='https://os.mbed.com/docs/v5.6/tools/exporting.html/'>link to the online exporter documentation</a> - </body> -</html> -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ManageBufferJPA.cpp Wed Sep 02 12:54:45 2020 +0000 @@ -0,0 +1,65 @@ +#include "mbed.h" + +const int kMaxBufferSize = 125; +volatile char bufferSerialUSB[kMaxBufferSize+3]; +volatile int idxSerialIntUSB = 0; +int idxSerialUserUSB = 0; +volatile int msgSerialUSB = 0; + +//RawSerial +RawSerial serialUSB(USBTX, USBRX); // serial PC +Serial serial2(PC_6, PC_7); // TX, RX for udp bridge +Serial serial7(PF_7, PF_6); // TX, RX for extension +volatile char x; +// --------------------------------------------------- +void serialUSB_int_recv() +{ + if(serialUSB.readable()) + { + bufferSerialUSB[idxSerialIntUSB]=(serialUSB.getc()); + idxSerialIntUSB++; + if (idxSerialIntUSB >= kMaxBufferSize) {idxSerialIntUSB = 0;} + bufferSerialUSB[idxSerialIntUSB]= 0; + msgSerialUSB = 1; + } + return; +} + +void initSerial() + { + serialUSB.baud(115200); + serialUSB.attach(&serialUSB_int_recv, Serial::RxIrq); + serial2.baud(115200); // required for UDP bridge + serial7.baud(115200); // required for tasmota + //serial7.attach(&pc_recv, Serial::RxIrq); + + bufferSerialUSB[0] = '\0'; + + } + +void sendSerialUSB(char * str) + { + serialUSB.printf(str); + } + +void receiveSerialUSB() + { + while(idxSerialIntUSB != idxSerialUserUSB) + { + x=bufferSerialUSB[idxSerialUserUSB]; + printf("%c",x); + idxSerialUserUSB = idxSerialUserUSB + 1; + if (idxSerialUserUSB >= kMaxBufferSize) {idxSerialUserUSB = 0;} + } + msgSerialUSB = 0; + } + +void sendserial2(char * str) + { + serial2.printf(str); + } + +void sendserial7(char * str) + { + serial7.printf(str); + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ManageBufferJPA.h.py Wed Sep 02 12:54:45 2020 +0000 @@ -0,0 +1,19 @@ +#ifndef MANAGEBUFFERJPA_H +#define MANAGEBUFFERJPA_H + +void initSerial(); +void pc_recv(); + +// serial port sur connecteur arduino (D0,D1)-------------------- +extern Serial pc(USBTX, USBRX); // serial PC +extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge +extern Serial serial7(PF_7, PF_6); // TX, RX for extension + +const int kMaxBufferSize = 100; +char buffer[kMaxBufferSize]; +int len = 0; +int i = 0; +int idx_ser =0; +int recv_ser = 0; + +#endif //MANAGEBUFFERJPA_H
--- a/main.cpp Tue Sep 01 06:37:15 2020 +0000 +++ b/main.cpp Wed Sep 02 12:54:45 2020 +0000 @@ -54,9 +54,11 @@ #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_ts.h" #include "CANMsg.h" +//#include "ManageBufferJPA.h" #include "main.h" + //#include "touchScreen.cpp" int touchInitJPA1(); int touchJPA1(); @@ -77,51 +79,48 @@ //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to. //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these. -const char gsStreamId1[] = "voltage"; -const char gsStreamId2[] = "temperature"; -char gsStreamIPdatas[] = "192.168.1.49"; -char ethernet_actif[] = "O"; -char wifi_actif[] = "O"; -char can_actif[] = "O"; -char serial_actif[] = "O"; -char read_sd[] = ""; -uint8_t text2[30]; -uint8_t counter = 0; -float voltage; -const int kMaxBufferSize = 100; -char buffer[kMaxBufferSize]; -int len = 0; -int i = 0; -int idx_ser =0; -int recv_ser = 0; -Timer timer; +const char gsStreamId1[] = "voltage"; +const char gsStreamId2[] = "temperature"; +char gsStreamIPdatas[] = "192.168.1.49"; +char ethernet_actif[] = "O"; +char wifi_actif[] = "O"; +char can_actif[] = "O"; +char serial_actif[] = "O"; +char read_sd[] = ""; +uint8_t text2[30]; +uint8_t counter = 0; +float voltage; + +Timer timer; AnalogIn analogIn(A0); // CAN ------------------------------------------------------------ -CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name -CANMsg rxMsg; -CANMsg txMsg; +CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name +CANMsg rxMsg; +CANMsg txMsg; // Other Settings -int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency. +int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency. + +AnalogIn adc_temp(ADC_TEMP); +AnalogIn adc_vref(ADC_VREF); +DigitalOut myled(LED1); -AnalogIn adc_temp(ADC_TEMP); -AnalogIn adc_vref(ADC_VREF); -DigitalOut myled(LED1); +void initSerial(); +void sendSerialUSB(char * str); +void receiveSerialUSB(); -// serial port sur connecteur arduino (D0,D1)-------------------- -Serial pc(USBTX, USBRX); // serial PC -Serial serial2(PC_6, PC_7); // TX, RX for udp bridge -Serial serial7(PF_7, PF_6); // TX, RX for extension +extern volatile char bufferSerialUSB[]; +extern volatile int msgSerialUSB; + +//extern Serial serialUSB(USBTX, USBRX); // serial PC +//extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge +//extern Serial serial7(PF_7, PF_6); // TX, RX for extension #define BOARD1 1 // comment out this line when compiling for board #2 -#if defined(BOARD1) - const unsigned int RX_ID = 0x100; - const unsigned int TX_ID = 0x101; -#else const unsigned int RX_ID = 0x101; const unsigned int TX_ID = 0x100; -#endif + // --------------------------------------------------------------------------------------- //* @brief Prints CAN message to PC's serial terminal @@ -158,36 +157,19 @@ can.read(rxMsg); CanRcv = 1; } -// --------------------------------------------------- -void pc_recv() -{ if(serial7.readable()) - { buffer[i]=(serial7.getc()); - if (buffer[i] == '\n') { - serial7.printf("%s",buffer); - len = 0; - idx_ser =0; - recv_ser = 1; - } - idx_ser++; - } -} + // ------------------------------------------------------------------------------------------ int main() -{ pc.baud(115200); - //serial2.baud(115200); // required for tasmota - serial2.baud(57600); // required for UDP bridge - serial7.baud(115200); // required for tasmota - //serial7.attach(&pc_recv, Serial::RxIrq); +{ + initSerial(); + // attach ISR to handle received messages -#if defined(BOARD1) timer.start(); // start timer - pc.printf("CAN_Hello board #1\r\n"); -#else - pc.printf("CAN_Hello board #2\r\n"); -#endif - buffer[0] = '\0'; + sendSerialUSB("CAN_Hello board serialUSB #1\r\n"); + + printf("\nInit SDCard ...\n"); mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib // reaf following datas @@ -224,9 +206,9 @@ // config can -------------------------------------- can.frequency(125000); // set CAN bit rate to 125 kbps //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID - can.attach(onCanReceived); + can.attach(onCanReceived, CAN::RxIrq); - // main loop --------------------------------------------------- + // main loop --------------------------------------------------- while (true) { if (CanRcv > 0) @@ -237,30 +219,16 @@ if (rxMsg.id == RX_ID) { rxMsg >> counter; rxMsg >> voltage; - pc.printf(" counter = %d\r\n", counter); - pc.printf(" voltage = %e V\r\n", voltage); + //serialUSB.printf(" counter = %d\r\n", counter); + //serialUSB.printf(" voltage = %e V\r\n", voltage); } } - // lecture sur port serie from tasmota - if(serial7.readable()) - { buffer[i]=(serial7.getc()); - serial7.printf("%c",buffer[i]); - if (buffer[i] == '\n') { - serial7.printf("%s",buffer); - len = 0; - idx_ser =0; - recv_ser = 1; - } - idx_ser++; - } - if ( recv_ser == 1) - {serial7.printf("sent: %s",buffer); - pc.printf("sent: %s",buffer); - recv_ser =0; - } - + + if (msgSerialUSB > 0) {receiveSerialUSB();} + //sendSerialUSB(bufferSerialUSB); + // timer send can - if(timer.read_ms() >= 3000) // check for timeout + if(timer.read_ms() >= 10000) // check for timeout { timer.stop(); // stop the timer timer.reset(); // reset the timer counter = (counter+1) & 1; // increment the counter @@ -288,7 +256,7 @@ BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); } else - { pc.printf("Transmission error\r\n"); + { //serialUSB.printf("Transmission error\r\n"); BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); } @@ -297,32 +265,26 @@ //touch screen int xx = touchJPA1(); // if (xx > 0) - { pc.printf("Touche appuyee %d \r\n",xx); - // send data to serial bridge tasmota - serial2.printf(" Touche %d appuyee to Tasmota", xx); - serial7.printf(" Touche %d appuyee to Tasmota", xx); - if (xx ==4 ) + { + if (xx == 4) { // send trame to can + txMsg.id = 0x100130CB;//TX_ID; // set the message ID + txMsg.format = CANExtended ; //extended + txMsg.len=2; + txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!) + if(can.write(txMsg)) // transmit message - { //if(can->write(txMsg)) { // transmit the CAN message - //led = OFF; // turn the LED off - pc.printf("-------------------------------------\r\n"); - pc.printf("CAN message sent\r\n"); + { printMsg(txMsg,0); - pc.printf(" counter = %d\r\n", counter); - pc.printf(" voltage = %e V\r\n", voltage); BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); - serial7.printf(" send trame can ok"); - } + } else - { pc.printf("Transmission error\r\n"); + { BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); } } - pc.printf("data sent to tasmota serial bridge \n"); - // data sent to ethernet xx = sendTouchJPA(xx); lastToucheTime = time(NULL); @@ -332,7 +294,7 @@ { lastToucheTime = 0; } // send mqtt // Update sensor data to GroveStreams - seconds = time(NULL); + time_t seconds = time(NULL); if(seconds - lastSuccessfulUploadTime > updateFrequency) { ////lcd.clear(); ////lcd.printf("Getting Samples...");
--- a/mbed_config.h Tue Sep 01 06:37:15 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * mbed SDK - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Automatically generated configuration file. -// DO NOT EDIT, content will be overwritten. - -#ifndef __MBED_CONFIG_DATA__ -#define __MBED_CONFIG_DATA__ - -// Configuration parameters -#define CLOCK_SOURCE USE_PLL_HSE_XTAL|USE_PLL_HSI // set by target:DISCO_F746NG -#define LPTICKER_DELAY_TICKS 0 // set by target:DISCO_F746NG -#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 9600 // set by library:platform -#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE 9600 // set by library:platform -#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 0 // set by library:platform -#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT 1 // set by library:platform -#define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x1000 // set by target:Target -#define MBED_CONF_TARGET_CONSOLE_UART 1 // set by target:Target -#define MBED_CONF_TARGET_DEEP_SLEEP_LATENCY 4 // set by target:MCU_STM32 -#define MBED_CONF_TARGET_DEFAULT_ADC_VREF NAN // set by target:Target -#define MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT 1 // set by target:MCU_STM32 -#define MBED_CONF_TARGET_LPTICKER_LPTIM 1 // set by target:DISCO_F746NG -#define MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK 1 // set by target:MCU_STM32 -#define MBED_CONF_TARGET_LPUART_CLOCK_SOURCE USE_LPUART_CLK_LSE|USE_LPUART_CLK_PCLK1 // set by target:MCU_STM32 -#define MBED_CONF_TARGET_LSE_AVAILABLE 1 // set by target:MCU_STM32 -#define MBED_CONF_TARGET_MPU_ROM_END 0x0fffffff // set by target:Target -#define MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE ETHERNET // set by target:DISCO_F746NG -#define MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER 0 // set by target:Target -#define MBED_CONF_TARGET_USB_SPEED USE_USB_OTG_FS // set by target:DISCO_F746NG -#define MBED_CONF_TARGET_XIP_ENABLE 0 // set by target:Target - -#endif -
--- a/touchScreen.cpp Tue Sep 01 06:37:15 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,246 +0,0 @@ - -#include "stm32746g_discovery_lcd.h" -#include "stm32746g_discovery_ts.h" -#include "mbed.h" -#include "GroveStreams.h" -#include "MbedJSONValue.h" - -int initDisplayTemp(); - -// GroveStreams Settings -//extern const char gsApiKey[];// = "YOUR_SECRET_API_KEY_HERE"; //Change This!!! -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. - -extern const char gsCompTmplId[]; //Optional. Tells GS what template to use when the feed initially arrives and a new component needs to be created. - -////GroveStreams groveStreams(gsApiKey, &lcd); -extern GroveStreams groveStreams; - -extern const char* myMac; - -extern time_t seconds; -time_t seconds_touches = 0; -extern time_t lastToucheTime; - -int touchInitJPA1() - { //touch screen init - //touch screen - uint8_t status; - BSP_LCD_Init(); - BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); - BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); - BSP_LCD_SetFont(&Font12); - status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); - if (status != TS_OK) { - BSP_LCD_Clear(LCD_COLOR_RED); - BSP_LCD_SetBackColor(LCD_COLOR_RED); - BSP_LCD_SetTextColor(LCD_COLOR_WHITE); - BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); - } - else { - BSP_LCD_Clear(LCD_COLOR_DARKBLUE); - BSP_LCD_SetBackColor(LCD_COLOR_BLACK); - BSP_LCD_SetTextColor(LCD_COLOR_GREEN); - //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); - } - - return 0; - } - -int xButton[5],yButton[5],dxButton[5],dyButton[5],xTxtButton[5],yTxtButton[5]; -uint32_t backColorButton[5], txtColorButton[5]; -char textButton[5][30]; -char text1Button[5][30]; -char statusButton[5][30]; - -int touchButtonJPA1(int numButton) - { - if ((numButton > 0) && (numButton < 5)) - { - BSP_LCD_SetBackColor(backColorButton[numButton]); - BSP_LCD_SetTextColor(backColorButton[numButton]); - BSP_LCD_FillRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); - BSP_LCD_SetTextColor(txtColorButton[numButton]); - BSP_LCD_DrawRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); - BSP_LCD_SetFont(&Font20); - BSP_LCD_DisplayStringAt(xTxtButton[numButton]+52, yTxtButton[numButton], (uint8_t *)statusButton[numButton], LEFT_MODE); - BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+28, (uint8_t *)textButton[numButton], LEFT_MODE); - BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+48, (uint8_t *)text1Button[numButton], LEFT_MODE); - } - return 0; - } - - -// generation de fonts : http://omz-software.com/pythonista/docs/ios/ImageFont.html -int touchInitGuiJPA1() - { - xButton[1]=10;yButton[1]=185;dxButton[1]=100;dyButton[1]=80;xTxtButton[1]=12;yTxtButton[1]=190; - backColorButton[1] = LCD_COLOR_GRAY; txtColorButton[1] = LCD_COLOR_GREEN; - sprintf(textButton[1],"Lampe "); - sprintf(text1Button[1],"Sejour"); - sprintf(statusButton[1],"off"); - - xButton[2]=130;yButton[2]=185;dxButton[2]=100;dyButton[2]=80;xTxtButton[2]=132;yTxtButton[2]=190; - backColorButton[2] = LCD_COLOR_GRAY; txtColorButton[2] = LCD_COLOR_GREEN; - sprintf(textButton[2],"Lampe "); - sprintf(text1Button[2],"Sejours"); - sprintf(statusButton[2],"off"); - - xButton[3]=250;yButton[3]=185;dxButton[3]=100;dyButton[3]=80;xTxtButton[3]=252;yTxtButton[3]=190; - backColorButton[3] = LCD_COLOR_GRAY; txtColorButton[3] = LCD_COLOR_GREEN; - sprintf(textButton[3],"Lampe "); - sprintf(text1Button[3],"Sejour"); - sprintf(statusButton[3],"off"); - - xButton[4]=370;yButton[4]=185;dxButton[4]=100;dyButton[4]=80;xTxtButton[4]=372;yTxtButton[4]=190; - backColorButton[4] = LCD_COLOR_GRAY; txtColorButton[4] = LCD_COLOR_GREEN; - sprintf(textButton[4],"Lampe "); - sprintf(text1Button[4],"Sejour"); - sprintf(statusButton[4],"off"); - - touchButtonJPA1(1); - touchButtonJPA1(2); - touchButtonJPA1(3); - touchButtonJPA1(4); - - BSP_LCD_SetFont(&FontFreeMono64); - //BSP_LCD_DisplayStringAt(20, 30, (uint8_t *)"0123456789", LEFT_MODE); - //BSP_LCD_DisplayCharJPA(20, 90, '8'); - BSP_LCD_SetFont(&Font12); - return 0; - } - -int touchJPA1() - { - //touch screen - TS_StateTypeDef TS_State; - uint16_t x, y; - uint8_t text[30]; - uint8_t status = 0; - uint8_t idx; - static uint8_t cleared = 0; - uint8_t prev_nb_touches = 0; - - - //touch screen - BSP_TS_GetState(&TS_State); - if (TS_State.touchDetected) { - // Clear lines corresponding to old touches coordinates - if (TS_State.touchDetected < prev_nb_touches) { - for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { - //BSP_LCD_ClearStringLine(idx); - } - } - prev_nb_touches = TS_State.touchDetected; - - cleared = 0; - - //sprintf((char*)text, "Touches: %d", TS_State.touchDetected); - //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); - - for (idx = 0; idx < TS_State.touchDetected; idx++) { - x = TS_State.touchX[idx]; - y = TS_State.touchY[idx]; - //sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); - //BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); - } - - //BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); - - if ((TS_State.touchY[0] > 160) && (TS_State.touchY[0] < (160+80))) - { - int numTouche = 0; - if ((TS_State.touchX[0] > 10) && (TS_State.touchX[0] < (10+100))) {numTouche = 1;} - if ((TS_State.touchX[0] > 130) && (TS_State.touchX[0] < (130+100))) {numTouche = 2;} - if ((TS_State.touchX[0] > 250) && (TS_State.touchX[0] < (250+100))) {numTouche = 3;} - if ((TS_State.touchX[0] > 370) && (TS_State.touchX[0] < (370+100))) {numTouche = 4;} - if (numTouche >0) - { - printf("Touche : %d", numTouche); - sprintf((char*)text, "Touche : %d", numTouche); - //BSP_LCD_DisplayStringAt(200,0, (uint8_t *)&text, LEFT_MODE); - status = numTouche; - } - else {lastToucheTime = 0;} - } - } else { - lastToucheTime = 0; - if (!cleared) { - //BSP_LCD_Clear(LCD_COLOR_DARKBLUE); - //sprintf((char*)text, "Touches: 0"); - //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); - //cleared = 1; - //int ss = touchInitGuiJPA1(); - //ss=initDisplayTemp(); - } - } - //touch screen - return status; - } - -int sendTouchJPA(int xx) - { - uint8_t status = 0; - seconds = time(NULL); - if((seconds - lastToucheTime) > 1) - { - char samples[64] = {0};char resultBuffer[2000]= {0}; - sprintf(samples,"&Touche=%i",xx); - printf("\nSend Touche=%i\n",xx); - int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); - if (sendResult == 0) { - ////lcd.printf("Send Successful"); - printf("Send Successful\n"); - if (strlen(resultBuffer) > 0) { - //printf("HTTP string : %s\n", resultBuffer); - MbedJSONValue mbedJson; - parse(mbedJson, resultBuffer); - - int displayOn = 0; - string s; - if (mbedJson.hasMember("Touche1")) { - s = mbedJson["Touche1"]["BackColor"].get<std::string>(); - backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche1"]["TextColor"].get<std::string>(); - txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche1"]["Status"].get<std::string>(); - sprintf(statusButton[1],s.c_str()); - displayOn = (0x02 | displayOn);} - - if (mbedJson.hasMember("Touche2")) { - s = mbedJson["Touche2"]["BackColor"].get<std::string>(); - backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche2"]["TextColor"].get<std::string>(); - txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche2"]["Status"].get<std::string>(); - sprintf(statusButton[2],s.c_str()); - displayOn = (0x04 | displayOn);} - - if (mbedJson.hasMember("Touche3")) { - s = mbedJson["Touche3"]["BackColor"].get<std::string>(); - backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche3"]["TextColor"].get<std::string>(); - txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche3"]["Status"].get<std::string>(); - sprintf(statusButton[3],s.c_str()); - displayOn = (0x08 | displayOn);} - - if (mbedJson.hasMember("Touche4")) { - s = mbedJson["Touche4"]["BackColor"].get<std::string>(); - backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche4"]["TextColor"].get<std::string>(); - txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); - s = mbedJson["Touche4"]["Status"].get<std::string>(); - sprintf(statusButton[4],s.c_str()); - displayOn = (0x10 | displayOn);} - - if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);} - if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);} - if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);} - if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);} - } - } - } - - return status; - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/touchScreenJPA.cpp Wed Sep 02 12:54:45 2020 +0000 @@ -0,0 +1,246 @@ + +#include "stm32746g_discovery_lcd.h" +#include "stm32746g_discovery_ts.h" +#include "mbed.h" +#include "GroveStreams.h" +#include "MbedJSONValue.h" + +int initDisplayTemp(); + +// GroveStreams Settings +//extern const char gsApiKey[];// = "YOUR_SECRET_API_KEY_HERE"; //Change This!!! +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. + +extern const char gsCompTmplId[]; //Optional. Tells GS what template to use when the feed initially arrives and a new component needs to be created. + +////GroveStreams groveStreams(gsApiKey, &lcd); +extern GroveStreams groveStreams; + +extern const char* myMac; + +extern time_t seconds; +time_t seconds_touches = 0; +extern time_t lastToucheTime; + +int touchInitJPA1() + { //touch screen init + //touch screen + uint8_t status; + BSP_LCD_Init(); + BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); + BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); + BSP_LCD_SetFont(&Font12); + status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); + if (status != TS_OK) { + BSP_LCD_Clear(LCD_COLOR_RED); + BSP_LCD_SetBackColor(LCD_COLOR_RED); + BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); + } + else { + BSP_LCD_Clear(LCD_COLOR_DARKBLUE); + BSP_LCD_SetBackColor(LCD_COLOR_BLACK); + BSP_LCD_SetTextColor(LCD_COLOR_GREEN); + //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); + } + + return 0; + } + +int xButton[5],yButton[5],dxButton[5],dyButton[5],xTxtButton[5],yTxtButton[5]; +uint32_t backColorButton[5], txtColorButton[5]; +char textButton[5][30]; +char text1Button[5][30]; +char statusButton[5][30]; + +int touchButtonJPA1(int numButton) + { + if ((numButton > 0) && (numButton < 5)) + { + BSP_LCD_SetBackColor(backColorButton[numButton]); + BSP_LCD_SetTextColor(backColorButton[numButton]); + BSP_LCD_FillRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); + BSP_LCD_SetTextColor(txtColorButton[numButton]); + BSP_LCD_DrawRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]); + BSP_LCD_SetFont(&Font20); + BSP_LCD_DisplayStringAt(xTxtButton[numButton]+52, yTxtButton[numButton], (uint8_t *)statusButton[numButton], LEFT_MODE); + BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+28, (uint8_t *)textButton[numButton], LEFT_MODE); + BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+48, (uint8_t *)text1Button[numButton], LEFT_MODE); + } + return 0; + } + + +// generation de fonts : http://omz-software.com/pythonista/docs/ios/ImageFont.html +int touchInitGuiJPA1() + { + xButton[1]=10;yButton[1]=185;dxButton[1]=100;dyButton[1]=80;xTxtButton[1]=12;yTxtButton[1]=190; + backColorButton[1] = LCD_COLOR_GRAY; txtColorButton[1] = LCD_COLOR_GREEN; + sprintf(textButton[1],"Lampe "); + sprintf(text1Button[1],"Sejour"); + sprintf(statusButton[1],"off"); + + xButton[2]=130;yButton[2]=185;dxButton[2]=100;dyButton[2]=80;xTxtButton[2]=132;yTxtButton[2]=190; + backColorButton[2] = LCD_COLOR_GRAY; txtColorButton[2] = LCD_COLOR_GREEN; + sprintf(textButton[2],"Lampe "); + sprintf(text1Button[2],"Sejours"); + sprintf(statusButton[2],"off"); + + xButton[3]=250;yButton[3]=185;dxButton[3]=100;dyButton[3]=80;xTxtButton[3]=252;yTxtButton[3]=190; + backColorButton[3] = LCD_COLOR_GRAY; txtColorButton[3] = LCD_COLOR_GREEN; + sprintf(textButton[3],"Lampe "); + sprintf(text1Button[3],"Sejour"); + sprintf(statusButton[3],"off"); + + xButton[4]=370;yButton[4]=185;dxButton[4]=100;dyButton[4]=80;xTxtButton[4]=372;yTxtButton[4]=190; + backColorButton[4] = LCD_COLOR_GRAY; txtColorButton[4] = LCD_COLOR_GREEN; + sprintf(textButton[4],"Lampe "); + sprintf(text1Button[4],"Sejour"); + sprintf(statusButton[4],"off"); + + touchButtonJPA1(1); + touchButtonJPA1(2); + touchButtonJPA1(3); + touchButtonJPA1(4); + + BSP_LCD_SetFont(&FontFreeMono64); + //BSP_LCD_DisplayStringAt(20, 30, (uint8_t *)"0123456789", LEFT_MODE); + //BSP_LCD_DisplayCharJPA(20, 90, '8'); + BSP_LCD_SetFont(&Font12); + return 0; + } + +int touchJPA1() + { + //touch screen + TS_StateTypeDef TS_State; + uint16_t x, y; + uint8_t text[30]; + uint8_t status = 0; + uint8_t idx; + static uint8_t cleared = 0; + uint8_t prev_nb_touches = 0; + + + //touch screen + BSP_TS_GetState(&TS_State); + if (TS_State.touchDetected) { + // Clear lines corresponding to old touches coordinates + if (TS_State.touchDetected < prev_nb_touches) { + for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { + //BSP_LCD_ClearStringLine(idx); + } + } + prev_nb_touches = TS_State.touchDetected; + + cleared = 0; + + //sprintf((char*)text, "Touches: %d", TS_State.touchDetected); + //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + for (idx = 0; idx < TS_State.touchDetected; idx++) { + x = TS_State.touchX[idx]; + y = TS_State.touchY[idx]; + //sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); + //BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); + } + + //BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); + + if ((TS_State.touchY[0] > 160) && (TS_State.touchY[0] < (160+80))) + { + int numTouche = 0; + if ((TS_State.touchX[0] > 10) && (TS_State.touchX[0] < (10+100))) {numTouche = 1;} + if ((TS_State.touchX[0] > 130) && (TS_State.touchX[0] < (130+100))) {numTouche = 2;} + if ((TS_State.touchX[0] > 250) && (TS_State.touchX[0] < (250+100))) {numTouche = 3;} + if ((TS_State.touchX[0] > 370) && (TS_State.touchX[0] < (370+100))) {numTouche = 4;} + if (numTouche >0) + { + printf("Touche : %d", numTouche); + sprintf((char*)text, "Touche : %d", numTouche); + //BSP_LCD_DisplayStringAt(200,0, (uint8_t *)&text, LEFT_MODE); + status = numTouche; + } + else {lastToucheTime = 0;} + } + } else { + lastToucheTime = 0; + if (!cleared) { + //BSP_LCD_Clear(LCD_COLOR_DARKBLUE); + //sprintf((char*)text, "Touches: 0"); + //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + //cleared = 1; + //int ss = touchInitGuiJPA1(); + //ss=initDisplayTemp(); + } + } + //touch screen + return status; + } + +int sendTouchJPA(int xx) + { + uint8_t status = 0; + seconds = time(NULL); + if((seconds - lastToucheTime) > 1) + { + char samples[64] = {0};char resultBuffer[2000]= {0}; + sprintf(samples,"&Touche=%i",xx); + printf("\nSend Touche=%i\n",xx); + int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); + if (sendResult == 0) { + ////lcd.printf("Send Successful"); + printf("Send Successful\n"); + if (strlen(resultBuffer) > 0) { + //printf("HTTP string : %s\n", resultBuffer); + MbedJSONValue mbedJson; + parse(mbedJson, resultBuffer); + + int displayOn = 0; + string s; + if (mbedJson.hasMember("Touche1")) { + s = mbedJson["Touche1"]["BackColor"].get<std::string>(); + backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche1"]["TextColor"].get<std::string>(); + txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche1"]["Status"].get<std::string>(); + sprintf(statusButton[1],s.c_str()); + displayOn = (0x02 | displayOn);} + + if (mbedJson.hasMember("Touche2")) { + s = mbedJson["Touche2"]["BackColor"].get<std::string>(); + backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche2"]["TextColor"].get<std::string>(); + txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche2"]["Status"].get<std::string>(); + sprintf(statusButton[2],s.c_str()); + displayOn = (0x04 | displayOn);} + + if (mbedJson.hasMember("Touche3")) { + s = mbedJson["Touche3"]["BackColor"].get<std::string>(); + backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche3"]["TextColor"].get<std::string>(); + txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche3"]["Status"].get<std::string>(); + sprintf(statusButton[3],s.c_str()); + displayOn = (0x08 | displayOn);} + + if (mbedJson.hasMember("Touche4")) { + s = mbedJson["Touche4"]["BackColor"].get<std::string>(); + backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche4"]["TextColor"].get<std::string>(); + txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); + s = mbedJson["Touche4"]["Status"].get<std::string>(); + sprintf(statusButton[4],s.c_str()); + displayOn = (0x10 | displayOn);} + + if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);} + if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);} + if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);} + if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);} + } + } + } + + return status; + }