init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: main.cpp
- Revision:
- 14:9a54b1b65bc8
- Parent:
- 13:29f67f256709
- Child:
- 15:7aad9a7f970c
--- a/main.cpp Sun Dec 16 15:21:38 2018 +0000 +++ b/main.cpp Sun Dec 16 21:34:52 2018 +0000 @@ -250,20 +250,52 @@ } } +//------------------------------------------------------------------------------ +// UPDATE OPERATING SETTINGS +//------------------------------------------------------------------------------ +bool saveSettings(char* settingsBuffer) { + //process result + int matchCount = 0; + time_t TEMP_a = 0; + int TEMP_b = 0; + int TEMP_c = 0; + int TEMP_d = 0; + int TEMP_e = 0; + int TEMP_f = 0; + int TEMP_g = 0; + int TEMP_h = 0; + int TEMP_i = 0; + int TEMP_j = 0; + int TEMP_k = 0; + int TEMP_l = 0; + int TEMP_m = 0; + int TEMP_n = 0; + if ( (matchCount = sscanf(settingsBuffer,"a:%u,b:%d,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d", + &TEMP_a,&TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n) ) > 0 ) { + DEBUG("VALUES: a:%u,b:%d,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d",TEMP_a,TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n); + return true; + } else { + return false; + } +} + //------------------------------------------------------------------------------ // SETUP //------------------------------------------------------------------------------ bool setup() { bool pass = true; + Modem modem(PN_UART_TX, PN_UART_RX, PN_UART_CTS, PN_UART_RTS, PN_GSM_PWR_KEY, PN_VREG_EN); if (modem.on()) { RET_imei = modem.getIMEI(); + GLOBAL_imei = RET_imei; DEBUG("imei: %lld \n",RET_imei); if (modem.registerOnNetwork(3,60000)) { char* result = modem.USSDmessage("blahblah\0", true, 2); if (result != "err") { DEBUG("result: %s \n",result); + saveSettings(result); } } else { //modem failed to register on network @@ -295,6 +327,7 @@ case MODE_SETUP : factoryReset(); if (setup()) { + copyRETtoGLOBAL(); RET_mode = MODE_NORMAL; } break; @@ -314,7 +347,7 @@ } //Environmental if(RET_RTCunixtime > RET_eventTime_environmental_log && RET_eventTime_environmental_log > 0) { - Filesystem filesystem(PN_SPI_MOSI,PN_SPI_MISO,PN_SPI_CLK,PN_SPI_CS1); + Filesystem filesystem(BD_PAGE_ADDRESS,BD_TOTAL_SIZE); SI7060 temperature(PN_I2C_SDA,PN_I2C_SCL); float temperature_c = temperature.getTemperature(); DEBUG("Temperature log: %u,%f \n", RET_RTCunixtime,temperature_c); @@ -383,6 +416,7 @@ //CHECK FOR FIRST BOOT if (RET_coldBoot != 0) factoryReset(); + //COPY ESSENTIAL VALUES FROM RET TO GLOBAL copyRETtoGLOBAL(); while(true) { @@ -395,11 +429,6 @@ //MAIN LOGIC DEBUG("mode: %i time: %i, %i, %i, %i \n", RET_mode, RET_RTCmicros, RET_RTCunixtime, RET_buttonHoldTime, RET_buttonPressCount); - - Thread::wait(5000); - RET_coldBoot = 0; - system_reset(); - mainStateEngine(); //PRE-SLEEP ACTIONS