version with updated libs

Dependencies:   F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON

Committer:
38domo
Date:
Thu Sep 17 20:32:02 2020 +0000
Branch:
jpa
Revision:
12:15ae35cfb03f
Parent:
11:b198b2f2676f
Child:
13:fdec444a7b30
version with buttons operational

Who changed what in which revision?

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