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:
Wed Jan 13 19:52:35 2021 +0000
Branch:
jpa
Revision:
17:f3c5ec9ca00f
Parent:
16:f0d946e6da36
version 12/01 without ethernet, only tasmota wifi and can

Who changed what in which revision?

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