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
main.cpp@10:41aff2b7acc6, 2020-09-15 (annotated)
- Committer:
- 38domo
- Date:
- Tue Sep 15 19:11:11 2020 +0000
- Branch:
- jpa
- Revision:
- 10:41aff2b7acc6
- Parent:
- 9:332bd237b98f
- Child:
- 11:b198b2f2676f
grov stream lib updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38domo | 0:48863a0964f5 | 1 | /* -------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 2 | // test compile ok 31/07/2020 |
38domo | 0:48863a0964f5 | 3 | |
38domo | 10:41aff2b7acc6 | 4 | // 01/09/2020 : update JPA serial et CAN : tests OK sur CAN et 1 srial 2 |
38domo | 10:41aff2b7acc6 | 5 | : attention 1 seul serial operationnel serial 2 - serial 7 ne marche pas en reception |
38domo | 10:41aff2b7acc6 | 6 | // : test ok send/receive tasmota sur serial 2 |
38domo | 0:48863a0964f5 | 7 | // 30/08/2020 : emission CAN OK en Wifi sur tasmota ou udp bridge |
38domo | 0:48863a0964f5 | 8 | // mais pb reception caracteres sur port serie ( idem port series pc ouu serial 7 |
38domo | 0:48863a0964f5 | 9 | |
38domo | 0:48863a0964f5 | 10 | // 02/08/2020 |
38domo | 0:48863a0964f5 | 11 | // add sd parameters: read ok |
38domo | 0:48863a0964f5 | 12 | // ip address |
38domo | 0:48863a0964f5 | 13 | // ethernet actif |
38domo | 0:48863a0964f5 | 14 | // wifi actif |
38domo | 0:48863a0964f5 | 15 | // can actif |
38domo | 0:48863a0964f5 | 16 | // serial actif |
38domo | 0:48863a0964f5 | 17 | // fonction |
38domo | 0:48863a0964f5 | 18 | // Touche1 status (0/1) |
38domo | 0:48863a0964f5 | 19 | // Touche1 backcolor |
38domo | 0:48863a0964f5 | 20 | // touche1 text color |
38domo | 0:48863a0964f5 | 21 | // Touche1 text |
38domo | 0:48863a0964f5 | 22 | // Touche1 text1 |
38domo | 0:48863a0964f5 | 23 | // Touche2 |
38domo | 0:48863a0964f5 | 24 | // Touche3 |
38domo | 0:48863a0964f5 | 25 | // Touche4 |
38domo | 0:48863a0964f5 | 26 | // Temp1 text |
38domo | 0:48863a0964f5 | 27 | // Temp2 text |
38domo | 0:48863a0964f5 | 28 | |
38domo | 0:48863a0964f5 | 29 | // works ok 31/07/2020 |
38domo | 0:48863a0964f5 | 30 | // updated package from jpa |
38domo | 0:48863a0964f5 | 31 | // added fonts in bsp_disco_f746ng/utilities/fonts |
38domo | 0:48863a0964f5 | 32 | // fonts.h updated to manage added fonts |
38domo | 0:48863a0964f5 | 33 | // grovestream.cpp & grovesttream.h updated |
38domo | 0:48863a0964f5 | 34 | // remove stm32746ng_dicovery_sd in /bsp_disco_f746ng/drivers/stm32746ng_discovery |
38domo | 0:48863a0964f5 | 35 | // mainSDAcardJPA issue: add sdcardjpa.cpp in lib /sdfilesystem_warning_fixed |
38domo | 0:48863a0964f5 | 36 | // isue with big fonts: replace /bsp_disco_f746ng/drivers/stm32746ng-discovery/stm32746ng-discovery_lcd.c &.h |
38domo | 0:48863a0964f5 | 37 | |
38domo | 0:48863a0964f5 | 38 | // need to add CAN and WiFi |
38domo | 0:48863a0964f5 | 39 | |
38domo | 0:48863a0964f5 | 40 | STM32F746 GroveStreams Stream Feed via Ethernet |
38domo | 0:48863a0964f5 | 41 | |
38domo | 0:48863a0964f5 | 42 | This GroveStreams example is designed for the STM32F746. |
38domo | 0:48863a0964f5 | 43 | https://www.grovestreams.com/developers/getting_started_stm32F746.html |
38domo | 0:48863a0964f5 | 44 | |
38domo | 0:48863a0964f5 | 45 | The STM32 uses DHCP and DNS for a simpler network setup. |
38domo | 0:48863a0964f5 | 46 | |
38domo | 0:48863a0964f5 | 47 | */ |
38domo | 0:48863a0964f5 | 48 | |
38domo | 0:48863a0964f5 | 49 | #if !FEATURE_LWIP |
38domo | 0:48863a0964f5 | 50 | #error [NOT_SUPPORTED] LWIP not supported for this target |
38domo | 0:48863a0964f5 | 51 | #endif |
38domo | 0:48863a0964f5 | 52 | |
38domo | 0:48863a0964f5 | 53 | #include "mbed.h" |
38domo | 0:48863a0964f5 | 54 | #include "LcdDiscoF746NgTracer.h" |
38domo | 0:48863a0964f5 | 55 | #include "GroveStreams.h" |
38domo | 0:48863a0964f5 | 56 | #include "MbedJSONValue.h" |
38domo | 0:48863a0964f5 | 57 | #include "stm32746g_discovery_lcd.h" |
38domo | 0:48863a0964f5 | 58 | #include "stm32746g_discovery_ts.h" |
38domo | 0:48863a0964f5 | 59 | #include "CANMsg.h" |
jeanpierreaulas | 3:2de8e4771674 | 60 | //#include "ManageBufferJPA.h" |
38domo | 0:48863a0964f5 | 61 | |
38domo | 0:48863a0964f5 | 62 | #include "main.h" |
38domo | 0:48863a0964f5 | 63 | |
38domo | 10:41aff2b7acc6 | 64 | extern char textButton[5][8]; |
38domo | 10:41aff2b7acc6 | 65 | extern char text1Button[5][8]; |
38domo | 10:41aff2b7acc6 | 66 | extern char textTempTitle[3][30]; |
jeanpierreaulas | 3:2de8e4771674 | 67 | |
38domo | 0:48863a0964f5 | 68 | //#include "touchScreen.cpp" |
38domo | 0:48863a0964f5 | 69 | int touchInitJPA1(); |
38domo | 0:48863a0964f5 | 70 | int touchJPA1(); |
38domo | 0:48863a0964f5 | 71 | int touchInitGuiJPA1(); |
38domo | 0:48863a0964f5 | 72 | int sendTouchJPA(int xx); |
38domo | 0:48863a0964f5 | 73 | time_t lastToucheTime = 0; |
38domo | 0:48863a0964f5 | 74 | int touchButtonJPA1(int numButton); |
38domo | 0:48863a0964f5 | 75 | |
38domo | 0:48863a0964f5 | 76 | //#include "GuiJPA.cpp" |
38domo | 0:48863a0964f5 | 77 | int initDisplayTemp(); |
38domo | 0:48863a0964f5 | 78 | int initDatasGuiJPA(); |
38domo | 0:48863a0964f5 | 79 | int setTemp1(std::string temp1); |
38domo | 0:48863a0964f5 | 80 | int setTemp2(std::string temp2); |
38domo | 0:48863a0964f5 | 81 | int sendInitDatasJPA(int xx); |
38domo | 0:48863a0964f5 | 82 | |
38domo | 0:48863a0964f5 | 83 | //#SDCARD |
38domo | 0:48863a0964f5 | 84 | int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd |
38domo | 0:48863a0964f5 | 85 | |
38domo | 0:48863a0964f5 | 86 | //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to. |
38domo | 0:48863a0964f5 | 87 | //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these. |
jeanpierreaulas | 3:2de8e4771674 | 88 | const char gsStreamId1[] = "voltage"; |
jeanpierreaulas | 3:2de8e4771674 | 89 | const char gsStreamId2[] = "temperature"; |
jeanpierreaulas | 3:2de8e4771674 | 90 | char gsStreamIPdatas[] = "192.168.1.49"; |
38domo | 10:41aff2b7acc6 | 91 | int ethernet_actif = '0'; |
38domo | 10:41aff2b7acc6 | 92 | int wifi_actif = '1'; |
38domo | 10:41aff2b7acc6 | 93 | int can_actif = '1'; |
38domo | 10:41aff2b7acc6 | 94 | int serial_actif = '1'; |
jeanpierreaulas | 3:2de8e4771674 | 95 | char read_sd[] = ""; |
38domo | 10:41aff2b7acc6 | 96 | char function_mod[]= "O"; |
38domo | 10:41aff2b7acc6 | 97 | |
38domo | 10:41aff2b7acc6 | 98 | char touch1_status[]= "0"; |
38domo | 10:41aff2b7acc6 | 99 | char touch1_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 100 | char touch1_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 101 | char touch1_text[]= "Touch1"; |
38domo | 10:41aff2b7acc6 | 102 | char touch1_text1[]= "Text1"; |
38domo | 10:41aff2b7acc6 | 103 | |
38domo | 10:41aff2b7acc6 | 104 | char touch2_status[]= "0"; |
38domo | 10:41aff2b7acc6 | 105 | char touch2_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 106 | char touch2_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 107 | char touch2_text[]= "Touch2"; |
38domo | 10:41aff2b7acc6 | 108 | char touch2_text1[]= "Text2"; |
38domo | 10:41aff2b7acc6 | 109 | |
38domo | 10:41aff2b7acc6 | 110 | char touch3_status[]= "0"; |
38domo | 10:41aff2b7acc6 | 111 | char touch3_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 112 | char touch3_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 113 | char touch3_text[]= "Touch3"; |
38domo | 10:41aff2b7acc6 | 114 | char touch3_text1[]= "Text3"; |
38domo | 10:41aff2b7acc6 | 115 | |
38domo | 10:41aff2b7acc6 | 116 | char touch4_status[]= "0"; |
38domo | 10:41aff2b7acc6 | 117 | char touch4_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 118 | char touch4_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 119 | char touch4_text[]= "Touch4"; |
38domo | 10:41aff2b7acc6 | 120 | char touch4_text1[]= "Text4"; |
38domo | 10:41aff2b7acc6 | 121 | |
38domo | 10:41aff2b7acc6 | 122 | char temp1_text[]= "Temp1"; |
38domo | 10:41aff2b7acc6 | 123 | char temp1_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 124 | char temp1_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 125 | |
38domo | 10:41aff2b7acc6 | 126 | char temp2_text[]= "Temp2"; |
38domo | 10:41aff2b7acc6 | 127 | char temp2_back_color[]= "0xFF404040"; |
38domo | 10:41aff2b7acc6 | 128 | char temp2_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 129 | |
38domo | 10:41aff2b7acc6 | 130 | |
38domo | 10:41aff2b7acc6 | 131 | |
38domo | 10:41aff2b7acc6 | 132 | int len_line_sd = 0; |
38domo | 10:41aff2b7acc6 | 133 | |
jeanpierreaulas | 3:2de8e4771674 | 134 | uint8_t text2[30]; |
jeanpierreaulas | 3:2de8e4771674 | 135 | uint8_t counter = 0; |
jeanpierreaulas | 3:2de8e4771674 | 136 | float voltage; |
jeanpierreaulas | 3:2de8e4771674 | 137 | |
jeanpierreaulas | 3:2de8e4771674 | 138 | Timer timer; |
38domo | 0:48863a0964f5 | 139 | AnalogIn analogIn(A0); |
38domo | 0:48863a0964f5 | 140 | |
38domo | 0:48863a0964f5 | 141 | // CAN ------------------------------------------------------------ |
jeanpierreaulas | 3:2de8e4771674 | 142 | CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name |
jeanpierreaulas | 3:2de8e4771674 | 143 | CANMsg rxMsg; |
jeanpierreaulas | 3:2de8e4771674 | 144 | CANMsg txMsg; |
38domo | 0:48863a0964f5 | 145 | |
38domo | 0:48863a0964f5 | 146 | // Other Settings |
jeanpierreaulas | 3:2de8e4771674 | 147 | int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency. |
jeanpierreaulas | 3:2de8e4771674 | 148 | |
jeanpierreaulas | 3:2de8e4771674 | 149 | AnalogIn adc_temp(ADC_TEMP); |
jeanpierreaulas | 3:2de8e4771674 | 150 | AnalogIn adc_vref(ADC_VREF); |
jeanpierreaulas | 3:2de8e4771674 | 151 | DigitalOut myled(LED1); |
38domo | 0:48863a0964f5 | 152 | |
jeanpierreaulas | 3:2de8e4771674 | 153 | void initSerial(); |
jeanpierreaulas | 3:2de8e4771674 | 154 | void sendSerialUSB(char * str); |
jeanpierreaulas | 3:2de8e4771674 | 155 | void receiveSerialUSB(); |
jeanpierreaulas | 4:fbbf5d1785e7 | 156 | void sendSerial2(char * str); |
jeanpierreaulas | 4:fbbf5d1785e7 | 157 | void receiveSerial2(); |
jeanpierreaulas | 4:fbbf5d1785e7 | 158 | void sendSerial7(char * str); |
jeanpierreaulas | 4:fbbf5d1785e7 | 159 | void receiveSerial7(); |
38domo | 0:48863a0964f5 | 160 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 161 | //extern volatile char bufferSerialUSB[]; |
jeanpierreaulas | 3:2de8e4771674 | 162 | extern volatile int msgSerialUSB; |
jeanpierreaulas | 8:275ae4382788 | 163 | extern char stringSerialUSB[]; // trame from serialUSB |
jeanpierreaulas | 8:275ae4382788 | 164 | extern int stringSerialUSBok; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 8:275ae4382788 | 165 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 166 | extern volatile int msgSerial2; |
jeanpierreaulas | 8:275ae4382788 | 167 | extern char stringSerial2[]; // trame from serialUSB |
jeanpierreaulas | 8:275ae4382788 | 168 | extern int stringSerial2ok; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 8:275ae4382788 | 169 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 170 | extern volatile int msgSerial7; |
jeanpierreaulas | 8:275ae4382788 | 171 | extern char stringSerial7[]; // trame from serialUSB |
jeanpierreaulas | 8:275ae4382788 | 172 | extern int stringSerial7ok; // si ==1 alors trame dispo (fin de trame == LF ou 10 |
jeanpierreaulas | 3:2de8e4771674 | 173 | |
jeanpierreaulas | 3:2de8e4771674 | 174 | //extern Serial serialUSB(USBTX, USBRX); // serial PC |
jeanpierreaulas | 3:2de8e4771674 | 175 | //extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge |
jeanpierreaulas | 3:2de8e4771674 | 176 | //extern Serial serial7(PF_7, PF_6); // TX, RX for extension |
38domo | 0:48863a0964f5 | 177 | |
38domo | 0:48863a0964f5 | 178 | #define BOARD1 1 // comment out this line when compiling for board #2 |
38domo | 0:48863a0964f5 | 179 | const unsigned int RX_ID = 0x101; |
38domo | 0:48863a0964f5 | 180 | const unsigned int TX_ID = 0x100; |
jeanpierreaulas | 3:2de8e4771674 | 181 | |
38domo | 0:48863a0964f5 | 182 | |
38domo | 0:48863a0964f5 | 183 | // --------------------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 184 | //* @brief Prints CAN message to PC's serial terminal |
38domo | 0:48863a0964f5 | 185 | void printMsg(CANMessage& msg, int dir) |
38domo | 0:48863a0964f5 | 186 | { if (dir ==0) |
38domo | 0:48863a0964f5 | 187 | { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE); |
jeanpierreaulas | 7:6ec7a4b94d0b | 188 | printf(" Can message sent : "); |
jeanpierreaulas | 2:462b5c0d3472 | 189 | printf("ID = 0x%.3X Data=", msg.id); |
jeanpierreaulas | 2:462b5c0d3472 | 190 | for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); |
jeanpierreaulas | 7:6ec7a4b94d0b | 191 | printf("\n"); |
38domo | 0:48863a0964f5 | 192 | } |
38domo | 0:48863a0964f5 | 193 | else |
38domo | 10:41aff2b7acc6 | 194 | { printf(" Can message receive : "); |
jeanpierreaulas | 4:fbbf5d1785e7 | 195 | /* |
jeanpierreaulas | 2:462b5c0d3472 | 196 | printf(" ID = 0x%.3X\r\n", msg.id); |
jeanpierreaulas | 2:462b5c0d3472 | 197 | printf(" Type = %d\r\n", msg.type); |
jeanpierreaulas | 2:462b5c0d3472 | 198 | printf(" Format = %d\r\n", msg.format); |
jeanpierreaulas | 2:462b5c0d3472 | 199 | printf(" Length = %d\r\n", msg.len); |
jeanpierreaulas | 7:6ec7a4b94d0b | 200 | */ |
jeanpierreaulas | 4:fbbf5d1785e7 | 201 | printf("ID = 0x%.3X Data=", msg.id); |
jeanpierreaulas | 4:fbbf5d1785e7 | 202 | for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); |
jeanpierreaulas | 7:6ec7a4b94d0b | 203 | printf("\n"); |
38domo | 0:48863a0964f5 | 204 | } |
38domo | 0:48863a0964f5 | 205 | } |
38domo | 0:48863a0964f5 | 206 | |
38domo | 0:48863a0964f5 | 207 | /** ----------------------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 208 | * @brief Handles received CAN messages |
38domo | 0:48863a0964f5 | 209 | * @note Called on 'CAN message received' interrupt. |
38domo | 0:48863a0964f5 | 210 | */ |
jeanpierreaulas | 2:462b5c0d3472 | 211 | int CanRcv = 0; |
38domo | 0:48863a0964f5 | 212 | void onCanReceived(void) |
38domo | 10:41aff2b7acc6 | 213 | { can.read(rxMsg); |
jeanpierreaulas | 2:462b5c0d3472 | 214 | CanRcv = 1; |
38domo | 0:48863a0964f5 | 215 | } |
jeanpierreaulas | 3:2de8e4771674 | 216 | |
38domo | 0:48863a0964f5 | 217 | // ------------------------------------------------------------------------------------------ |
38domo | 0:48863a0964f5 | 218 | int main() |
38domo | 10:41aff2b7acc6 | 219 | { initSerial(); |
jeanpierreaulas | 2:462b5c0d3472 | 220 | // attach ISR to handle received messages |
38domo | 0:48863a0964f5 | 221 | timer.start(); // start timer |
jeanpierreaulas | 3:2de8e4771674 | 222 | sendSerialUSB("CAN_Hello board serialUSB #1\r\n"); |
38domo | 10:41aff2b7acc6 | 223 | |
jeanpierreaulas | 5:ceefd0cfa233 | 224 | sendSerial2("CAN_Hello board serial2 #1\r\n"); |
jeanpierreaulas | 5:ceefd0cfa233 | 225 | sendSerial7("CAN_Hello board serial7 #1\r\n"); |
jeanpierreaulas | 3:2de8e4771674 | 226 | |
38domo | 0:48863a0964f5 | 227 | printf("\nInit SDCard ...\n"); |
38domo | 0:48863a0964f5 | 228 | mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib |
38domo | 0:48863a0964f5 | 229 | // reaf following datas |
38domo | 0:48863a0964f5 | 230 | // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters |
38domo | 0:48863a0964f5 | 231 | // store local variables from sd |
38domo | 10:41aff2b7acc6 | 232 | // gsStreamIPdatas[]; |
38domo | 10:41aff2b7acc6 | 233 | // ethernet_actif[] ; wifi_actif[];can_actif[]; serial_actif[]; function_mod[]= "O"; |
38domo | 10:41aff2b7acc6 | 234 | // touch1_status[]= "0"; touch1_back_color[]= "0xFF404040"; touch1_text_color[]= "0xFFFFFF00"; touch1_text[]= "Touch1"; touch1_text1[]= "Text1"; |
38domo | 10:41aff2b7acc6 | 235 | // touch2_status[]= "0"; touch2_back_color[]= "0xFF404040"; touch2_text_color[]= "0xFFFFFF00"; touch2_text[]= "Touch2"; touch2_text1[]= "Text2"; |
38domo | 10:41aff2b7acc6 | 236 | // touch3_status[]= "0"; touch3_back_color[]= "0xFF404040"; touch3_text_color[]= "0xFFFFFF00"; touch3_text[]= "Touch3"; touch3_text1[]= "Text3"; |
38domo | 10:41aff2b7acc6 | 237 | // touch4_status[]= "0"; touch4_back_color[]= "0xFF404040"; touch4_text_color[]= "0xFFFFFF00"; touch4_text[]= "Touch4"; touch4_text1[]= "Text4"; |
38domo | 10:41aff2b7acc6 | 238 | // temp1_text[]= "Temp1"; temp1_back_color[]= "0xFF404040"; temp1_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 239 | // temp2_text[]= "Temp2"; temp2_back_color[]= "0xFF404040"; temp2_text_color[]= "0xFFFFFF00"; |
38domo | 10:41aff2b7acc6 | 240 | |
38domo | 0:48863a0964f5 | 241 | printf("\nFin init SDCard ...\n"); |
38domo | 0:48863a0964f5 | 242 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD |
38domo | 0:48863a0964f5 | 243 | uint8_t text[300]; |
38domo | 0:48863a0964f5 | 244 | printf("Start Prog\n"); |
38domo | 0:48863a0964f5 | 245 | std::string temp1; |
38domo | 0:48863a0964f5 | 246 | std::string temp2; |
38domo | 0:48863a0964f5 | 247 | |
38domo | 0:48863a0964f5 | 248 | //lastSuccessfulUploadTime is used for upload frequency. |
38domo | 0:48863a0964f5 | 249 | time_t lastSuccessfulUploadTime = 0; |
38domo | 0:48863a0964f5 | 250 | printf("\n Init touchJPA1 ...\n"); |
38domo | 0:48863a0964f5 | 251 | int yy; |
38domo | 0:48863a0964f5 | 252 | printf("\n Init initDisplayTemp ...\n"); |
38domo | 0:48863a0964f5 | 253 | yy = initDisplayTemp(); // from guijpa.cpp - Init display |
38domo | 0:48863a0964f5 | 254 | printf("\ninit touchInitJPA1 ...\n"); |
38domo | 0:48863a0964f5 | 255 | yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen |
38domo | 10:41aff2b7acc6 | 256 | yy = touchInitGuiJPA1(); // from touchscreen.cpp - display buttons |
38domo | 0:48863a0964f5 | 257 | printf("\ninit initDatasGuiJPA ...\n"); |
38domo | 10:41aff2b7acc6 | 258 | yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons - ethernet connection |
38domo | 0:48863a0964f5 | 259 | ////lcd.printf("Starting..."); |
38domo | 0:48863a0964f5 | 260 | printf("Starting...\n"); |
38domo | 0:48863a0964f5 | 261 | lastToucheTime = time(NULL); |
38domo | 0:48863a0964f5 | 262 | char data[5]; |
jeanpierreaulas | 2:462b5c0d3472 | 263 | |
jeanpierreaulas | 2:462b5c0d3472 | 264 | // config can -------------------------------------- |
jeanpierreaulas | 2:462b5c0d3472 | 265 | can.frequency(125000); // set CAN bit rate to 125 kbps |
jeanpierreaulas | 2:462b5c0d3472 | 266 | //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID |
jeanpierreaulas | 3:2de8e4771674 | 267 | can.attach(onCanReceived, CAN::RxIrq); |
jeanpierreaulas | 2:462b5c0d3472 | 268 | |
jeanpierreaulas | 5:ceefd0cfa233 | 269 | BSP_LCD_DisplayOff(); |
jeanpierreaulas | 5:ceefd0cfa233 | 270 | BSP_LCD_DisplayOn(); |
38domo | 10:41aff2b7acc6 | 271 | //BSP_LCD_SetBackColor(LCD_COLOR_RED); |
38domo | 10:41aff2b7acc6 | 272 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 10:41aff2b7acc6 | 273 | BSP_LCD_SetBackColor(LCD_COLOR_RED); |
38domo | 10:41aff2b7acc6 | 274 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 10:41aff2b7acc6 | 275 | int pp = setTemp1("temp1"); // display temp1 on lcd |
38domo | 10:41aff2b7acc6 | 276 | BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"displ temp1", CENTER_MODE); |
38domo | 10:41aff2b7acc6 | 277 | |
jeanpierreaulas | 3:2de8e4771674 | 278 | // main loop --------------------------------------------------- |
38domo | 10:41aff2b7acc6 | 279 | while (true) { |
jeanpierreaulas | 2:462b5c0d3472 | 280 | if (CanRcv > 0) |
38domo | 10:41aff2b7acc6 | 281 | { CanRcv = 0; |
jeanpierreaulas | 2:462b5c0d3472 | 282 | printMsg(rxMsg,1); |
jeanpierreaulas | 2:462b5c0d3472 | 283 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE); |
38domo | 10:41aff2b7acc6 | 284 | if (rxMsg.id == RX_ID) |
38domo | 10:41aff2b7acc6 | 285 | { rxMsg >> counter; |
jeanpierreaulas | 2:462b5c0d3472 | 286 | rxMsg >> voltage; |
jeanpierreaulas | 3:2de8e4771674 | 287 | //serialUSB.printf(" counter = %d\r\n", counter); |
jeanpierreaulas | 3:2de8e4771674 | 288 | //serialUSB.printf(" voltage = %e V\r\n", voltage); |
jeanpierreaulas | 2:462b5c0d3472 | 289 | } |
38domo | 10:41aff2b7acc6 | 290 | } |
jeanpierreaulas | 3:2de8e4771674 | 291 | if (msgSerialUSB > 0) {receiveSerialUSB();} |
jeanpierreaulas | 9:332bd237b98f | 292 | if (stringSerialUSBok == 1) {printf("Trame SerialUSB : %s",stringSerialUSB);stringSerialUSBok=0;} |
jeanpierreaulas | 8:275ae4382788 | 293 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 294 | if (msgSerial2 > 0) {receiveSerial2();} |
38domo | 10:41aff2b7acc6 | 295 | if (stringSerial2ok == 1) |
38domo | 10:41aff2b7acc6 | 296 | { printf("Trame Serial2 : %s",stringSerial2); |
38domo | 10:41aff2b7acc6 | 297 | stringSerial2ok=0; |
38domo | 10:41aff2b7acc6 | 298 | // decodage json datas |
38domo | 10:41aff2b7acc6 | 299 | // trame reçue : {"Temp1":"25","Temp2":"30"} |
38domo | 10:41aff2b7acc6 | 300 | char resultBuffer[100]= {0}; |
38domo | 10:41aff2b7acc6 | 301 | //resultBuffer = stringSerial2; |
38domo | 10:41aff2b7acc6 | 302 | //if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') |
38domo | 10:41aff2b7acc6 | 303 | if (strlen(stringSerial2) > 0 && stringSerial2[0] == '{') |
38domo | 10:41aff2b7acc6 | 304 | { MbedJSONValue mbedJson; |
38domo | 10:41aff2b7acc6 | 305 | //parse(mbedJson, resultBuffer); |
38domo | 10:41aff2b7acc6 | 306 | parse(mbedJson, stringSerial2); |
38domo | 10:41aff2b7acc6 | 307 | //sprintf((char*)text, "HTTP string : %s\n", resultBuffer); |
38domo | 10:41aff2b7acc6 | 308 | sprintf((char*)text, "HTTP string : %s\n", stringSerial2); |
38domo | 10:41aff2b7acc6 | 309 | //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE); |
38domo | 10:41aff2b7acc6 | 310 | if (mbedJson.hasMember("Temp1")) { |
38domo | 10:41aff2b7acc6 | 311 | printf("Serial2 temp1: %s",stringSerial2); |
38domo | 10:41aff2b7acc6 | 312 | //int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); |
38domo | 10:41aff2b7acc6 | 313 | int pp = setTemp1(mbedJson["Temp1"].get<std::string>()); // display temp1 on lcd |
38domo | 10:41aff2b7acc6 | 314 | |
38domo | 10:41aff2b7acc6 | 315 | } |
38domo | 10:41aff2b7acc6 | 316 | if (mbedJson.hasMember("Temp2")) { |
38domo | 10:41aff2b7acc6 | 317 | int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); |
38domo | 10:41aff2b7acc6 | 318 | |
38domo | 10:41aff2b7acc6 | 319 | } |
38domo | 10:41aff2b7acc6 | 320 | |
38domo | 10:41aff2b7acc6 | 321 | } |
38domo | 10:41aff2b7acc6 | 322 | |
38domo | 10:41aff2b7acc6 | 323 | |
38domo | 10:41aff2b7acc6 | 324 | |
38domo | 10:41aff2b7acc6 | 325 | } |
jeanpierreaulas | 4:fbbf5d1785e7 | 326 | if (msgSerial7 > 0) {receiveSerial7();} |
jeanpierreaulas | 9:332bd237b98f | 327 | if (stringSerial7ok == 1) {printf("Trame Serial7 : %s",stringSerial7);stringSerial7ok=0;} |
jeanpierreaulas | 3:2de8e4771674 | 328 | |
38domo | 0:48863a0964f5 | 329 | // timer send can |
jeanpierreaulas | 3:2de8e4771674 | 330 | if(timer.read_ms() >= 10000) // check for timeout |
38domo | 10:41aff2b7acc6 | 331 | { timer.stop(); // stop the timer |
38domo | 0:48863a0964f5 | 332 | timer.reset(); // reset the timer |
jeanpierreaulas | 2:462b5c0d3472 | 333 | counter = (counter+1) & 1; // increment the counter |
jeanpierreaulas | 2:462b5c0d3472 | 334 | voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input |
38domo | 0:48863a0964f5 | 335 | txMsg.clear(); // clear the Tx message storage |
jeanpierreaulas | 2:462b5c0d3472 | 336 | txMsg.id = 0x100130CA;//TX_ID; // set the message ID |
38domo | 0:48863a0964f5 | 337 | txMsg.format = CANExtended ; //extended |
jeanpierreaulas | 2:462b5c0d3472 | 338 | txMsg.len=2; |
38domo | 10:41aff2b7acc6 | 339 | txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!) |
38domo | 0:48863a0964f5 | 340 | if(can.write(txMsg)) // transmit message |
38domo | 0:48863a0964f5 | 341 | { //if(can->write(txMsg)) { // transmit the CAN message |
38domo | 0:48863a0964f5 | 342 | printMsg(txMsg,0); |
38domo | 0:48863a0964f5 | 343 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:48863a0964f5 | 344 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 345 | } |
38domo | 0:48863a0964f5 | 346 | else |
jeanpierreaulas | 3:2de8e4771674 | 347 | { //serialUSB.printf("Transmission error\r\n"); |
38domo | 0:48863a0964f5 | 348 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:48863a0964f5 | 349 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 350 | } |
jeanpierreaulas | 2:462b5c0d3472 | 351 | timer.start(); // insert transmission lag |
38domo | 0:48863a0964f5 | 352 | } // end if timer |
38domo | 0:48863a0964f5 | 353 | //touch screen |
38domo | 0:48863a0964f5 | 354 | int xx = touchJPA1(); // |
38domo | 0:48863a0964f5 | 355 | if (xx > 0) |
38domo | 10:41aff2b7acc6 | 356 | { if (xx == 4) |
38domo | 0:48863a0964f5 | 357 | { // send trame to can |
jeanpierreaulas | 3:2de8e4771674 | 358 | txMsg.id = 0x100130CB;//TX_ID; // set the message ID |
jeanpierreaulas | 3:2de8e4771674 | 359 | txMsg.format = CANExtended ; //extended |
jeanpierreaulas | 3:2de8e4771674 | 360 | txMsg.len=2; |
jeanpierreaulas | 3:2de8e4771674 | 361 | txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!) |
jeanpierreaulas | 3:2de8e4771674 | 362 | |
38domo | 0:48863a0964f5 | 363 | if(can.write(txMsg)) // transmit message |
38domo | 10:41aff2b7acc6 | 364 | { printMsg(txMsg,0); |
38domo | 0:48863a0964f5 | 365 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:48863a0964f5 | 366 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
jeanpierreaulas | 3:2de8e4771674 | 367 | } |
38domo | 0:48863a0964f5 | 368 | else |
38domo | 10:41aff2b7acc6 | 369 | { BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:48863a0964f5 | 370 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 371 | } |
38domo | 0:48863a0964f5 | 372 | } |
38domo | 10:41aff2b7acc6 | 373 | xx = sendTouchJPA(xx); |
38domo | 10:41aff2b7acc6 | 374 | lastToucheTime = time(NULL); |
38domo | 0:48863a0964f5 | 375 | } |
38domo | 0:48863a0964f5 | 376 | else |
38domo | 0:48863a0964f5 | 377 | { lastToucheTime = 0; |
38domo | 0:48863a0964f5 | 378 | } // send mqtt |
38domo | 0:48863a0964f5 | 379 | // Update sensor data to GroveStreams |
jeanpierreaulas | 3:2de8e4771674 | 380 | time_t seconds = time(NULL); |
38domo | 0:48863a0964f5 | 381 | if(seconds - lastSuccessfulUploadTime > updateFrequency) { |
38domo | 0:48863a0964f5 | 382 | ////lcd.clear(); |
38domo | 0:48863a0964f5 | 383 | ////lcd.printf("Getting Samples..."); |
38domo | 0:48863a0964f5 | 384 | printf("Getting Samples...\n"); |
38domo | 0:48863a0964f5 | 385 | //Assemble the samples into URL parameters which are seperated with the "&" character |
38domo | 0:48863a0964f5 | 386 | // Example: &s1=6.2&s2=78.231 |
jeanpierreaulas | 2:462b5c0d3472 | 387 | int temperature = 0; //adc_temp.read() * 100.0f; |
jeanpierreaulas | 2:462b5c0d3472 | 388 | int voltage = 0; //adc_vref.read() * 100.0f; |
38domo | 0:48863a0964f5 | 389 | char samples[64] = {0}; |
38domo | 0:48863a0964f5 | 390 | sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature); |
38domo | 0:48863a0964f5 | 391 | //Append on command requests (request stream values) |
38domo | 0:48863a0964f5 | 392 | //This will indicate to GroveStreams to return the last value |
38domo | 0:48863a0964f5 | 393 | // of each request stream during the sample upload |
38domo | 0:48863a0964f5 | 394 | strcat(samples, "&rsid=freq&rsid=led"); |
38domo | 0:48863a0964f5 | 395 | char resultBuffer[700]= {0}; |
38domo | 0:48863a0964f5 | 396 | //Sending Samples (and returning current command stream values) |
38domo | 0:48863a0964f5 | 397 | time_t connectAttemptTime = time(NULL); |
38domo | 0:48863a0964f5 | 398 | int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt |
38domo | 0:48863a0964f5 | 399 | |
38domo | 0:48863a0964f5 | 400 | if (sendResult == 0) { |
38domo | 0:48863a0964f5 | 401 | ////lcd.printf("Send Successful"); |
38domo | 0:48863a0964f5 | 402 | printf("Send Successful\n"); |
38domo | 0:48863a0964f5 | 403 | lastSuccessfulUploadTime = connectAttemptTime; |
38domo | 0:48863a0964f5 | 404 | //Handle command streams |
38domo | 0:48863a0964f5 | 405 | if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') { |
38domo | 0:48863a0964f5 | 406 | MbedJSONValue mbedJson; |
38domo | 0:48863a0964f5 | 407 | parse(mbedJson, resultBuffer); |
38domo | 0:48863a0964f5 | 408 | sprintf((char*)text, "HTTP string : %s\n", resultBuffer); |
38domo | 0:48863a0964f5 | 409 | //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:48863a0964f5 | 410 | if (mbedJson.hasMember("Temp1")) { |
38domo | 0:48863a0964f5 | 411 | int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); |
38domo | 0:48863a0964f5 | 412 | } |
38domo | 0:48863a0964f5 | 413 | if (mbedJson.hasMember("Temp2")) { |
38domo | 0:48863a0964f5 | 414 | int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); |
38domo | 0:48863a0964f5 | 415 | } |
38domo | 0:48863a0964f5 | 416 | if (mbedJson.hasMember("led")) { |
38domo | 0:48863a0964f5 | 417 | //Change LED |
38domo | 0:48863a0964f5 | 418 | myled = mbedJson["led"].get<bool>() ? 1 : 0; |
38domo | 0:48863a0964f5 | 419 | ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off"); |
38domo | 0:48863a0964f5 | 420 | printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off"); |
38domo | 0:48863a0964f5 | 421 | } |
38domo | 0:48863a0964f5 | 422 | } |
38domo | 0:48863a0964f5 | 423 | } |
38domo | 0:48863a0964f5 | 424 | } |
38domo | 0:48863a0964f5 | 425 | |
38domo | 0:48863a0964f5 | 426 | } |
38domo | 0:48863a0964f5 | 427 | } |
38domo | 0:48863a0964f5 | 428 | |
38domo | 0:48863a0964f5 | 429 |