@@ -147,28 +147,16 @@ void beginBoard()
147147 unitMACAddress[5 ] += 2 ; // Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
148148
149149 // For all boards, check reset reason. If reset was due to wdt or panic, append last log
150+ loadSettingsPartial (); // Get resetCount
150151 if (esp_reset_reason () == ESP_RST_POWERON)
151152 {
152153 reuseLastLog = false ; // Start new log
153-
154- loadSettingsPartial ();
155- if (settings.enableResetDisplay == true )
156- {
157- settings.resetCount = 0 ;
158- recordSystemSettings (); // Record to NVM
159- }
154+ settings.resetCount = 0 ;
160155 }
161156 else
162157 {
163158 reuseLastLog = true ; // Attempt to reuse previous log
164-
165- loadSettingsPartial ();
166- if (settings.enableResetDisplay == true )
167- {
168- settings.resetCount ++;
169- Serial.printf (" resetCount: %d\n\r " , settings.resetCount );
170- recordSystemSettings (); // Record to NVM
171- }
159+ settings.resetCount ++;
172160
173161 Serial.print (" Reset reason: " );
174162 switch (esp_reset_reason ())
@@ -186,6 +174,8 @@ void beginBoard()
186174 default : Serial.println (" Unknown" );
187175 }
188176 }
177+
178+ recordSystemSettings (); // Record resetCount to NVM
189179}
190180
191181void beginSD ()
@@ -202,7 +192,7 @@ void beginSD()
202192 else if (xSemaphoreTake (sdCardSemaphore, fatSemaphore_shortWait_ms) != pdPASS)
203193 {
204194 // This is OK since a retry will occur next loop
205- log_d (" sdCardSemaphore failed to yield, Begin.ino line %d\r\n " , __LINE__);
195+ log_d (" sdCardSemaphore failed to yield, Begin.ino line %d" , __LINE__);
206196 break ;
207197 }
208198 gotSemaphore = true ;
@@ -395,13 +385,15 @@ void beginFS()
395385{
396386 if (online.fs == false )
397387 {
398- if (! LittleFS.begin (true )) // Format LittleFS if begin fails
388+ if (LittleFS.begin (true ) == false ) // Format LittleFS if begin fails
399389 {
400- log_d (" Error: LittleFS not online" );
401- return ;
390+ Serial.println (" Error: LittleFS not online" );
391+ }
392+ else
393+ {
394+ Serial.println (" LittleFS Started" );
395+ online.fs = true ;
402396 }
403- Serial.println (" LittleFS Started" );
404- online.fs = true ;
405397 }
406398}
407399
@@ -552,6 +544,8 @@ void beginFuelGauge()
552544 return ;
553545 }
554546
547+ online.battery = true ;
548+
555549 // Always use hibernate mode
556550 if (lipo.getHIBRTActThr () < 0xFF ) lipo.setHIBRTActThr ((uint8_t )0xFF );
557551 if (lipo.getHIBRTHibThr () < 0xFF ) lipo.setHIBRTHibThr ((uint8_t )0xFF );
@@ -561,7 +555,7 @@ void beginFuelGauge()
561555 checkBatteryLevels (); // Force check so you see battery level immediately at power on
562556
563557 // Check to see if we are dangerously low
564- if (battLevel < 5 && battChangeRate < 0 ) // 5% and not charging
558+ if (battLevel < 5 && battChangeRate < 0.5 ) // 5% and not charging
565559 {
566560 Serial.println (" Battery too low. Please charge. Shutting down..." );
567561
@@ -573,7 +567,6 @@ void beginFuelGauge()
573567 powerDown (false ); // Don't display 'Shutting Down'
574568 }
575569
576- online.battery = true ;
577570}
578571
579572// Begin accelerometer if available
@@ -712,20 +705,23 @@ bool beginExternalTriggers()
712705
713706void beginIdleTasks ()
714707{
715- char taskName[32 ];
716-
717- for (int index = 0 ; index < MAX_CPU_CORES; index++)
708+ if (settings.enablePrintIdleTime == true )
718709 {
719- sprintf (taskName, " IdleTask%d" , index);
720- if (idleTaskHandle[index] == NULL )
721- xTaskCreatePinnedToCore (
722- idleTask,
723- taskName, // Just for humans
724- 2000 , // Stack Size
725- NULL , // Task input parameter
726- 0 , // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
727- &idleTaskHandle[index], // Task handle
728- index); // Core where task should run, 0=core, 1=Arduino
710+ char taskName[32 ];
711+
712+ for (int index = 0 ; index < MAX_CPU_CORES; index++)
713+ {
714+ sprintf (taskName, " IdleTask%d" , index);
715+ if (idleTaskHandle[index] == NULL )
716+ xTaskCreatePinnedToCore (
717+ idleTask,
718+ taskName, // Just for humans
719+ 2000 , // Stack Size
720+ NULL , // Task input parameter
721+ 0 , // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
722+ &idleTaskHandle[index], // Task handle
723+ index); // Core where task should run, 0=core, 1=Arduino
724+ }
729725 }
730726}
731727
@@ -741,11 +737,27 @@ void beginI2C()
741737 // SCL/GND shorted: 1000ms, response 5
742738 // SDA/VCC shorted: 1000ms, reponse 5
743739 // SDA/GND shorted: 14ms, response 5
744- unsigned long startTime = millis ();
745740 Wire.beginTransmission (0x15 ); // Dummy address
746741 int endValue = Wire.endTransmission ();
747742 if (endValue == 2 )
748743 online.i2c = true ;
749744 else
750745 Serial.println (" Error: I2C Bus Not Responding" );
751746}
747+
748+ // Depending on radio selection, begin hardware
749+ void radioStart ()
750+ {
751+ #ifdef COMPILE_ESPNOW
752+ if (settings.radioType == RADIO_EXTERNAL)
753+ {
754+ espnowStop ();
755+
756+ // Nothing to start. UART2 of ZED is connected to external Radio port and is configured at configureUbloxModule()
757+ }
758+ else if (settings.radioType == RADIO_ESPNOW)
759+ {
760+ espnowStart ();
761+ }
762+ #endif
763+ }
0 commit comments