@@ -66,6 +66,7 @@ void beepOff()
66
66
67
67
// Update battery levels every 5 seconds
68
68
// Update battery charger as needed
69
+ // Output serial message if enabled
69
70
void updateBattery ()
70
71
{
71
72
if (online.batteryFuelGauge == true )
@@ -77,13 +78,19 @@ void updateBattery()
77
78
78
79
checkBatteryLevels ();
79
80
80
- // tickerBatteryLedUpdate will take care of this. Doing it here creates error "IO 0 is not set as GPIO"
81
- // if (present.fuelgauge_bq40z50 == true)
82
- // {
83
- // // Turn on green battery LED if battery is above 50%
84
- // if (batteryLevelPercent > 50)
85
- // batteryStatusLedOn();
86
- // }
81
+ // Display the battery data
82
+ if (settings.enablePrintBatteryMessages )
83
+ {
84
+ char tempStr[25 ];
85
+ if (isCharging ())
86
+ snprintf (tempStr, sizeof (tempStr), " C" );
87
+ else
88
+ snprintf (tempStr, sizeof (tempStr), " Disc" );
89
+
90
+ systemPrintf (" Batt (%d%%): Voltage: %0.02fV" , batteryLevelPercent, batteryVoltage);
91
+
92
+ systemPrintf (" %sharging: %0.02f%%/hr\r\n " , tempStr, batteryChargingPercentPerHour);
93
+ }
87
94
}
88
95
}
89
96
@@ -113,11 +120,25 @@ void updateBattery()
113
120
}
114
121
}
115
122
}
123
+
124
+ // Check if we need to shutdown due to no charging
125
+ if (settings.shutdownNoChargeTimeout_s > 0 )
126
+ {
127
+ if (isCharging () == false )
128
+ {
129
+ int secondsSinceLastCharger = (millis () - shutdownNoChargeTimer) / 1000 ;
130
+ if (secondsSinceLastCharger > settings.shutdownNoChargeTimeout_s )
131
+ powerDown (true );
132
+ }
133
+ else
134
+ {
135
+ shutdownNoChargeTimer = millis (); // Reset timer because power is attached
136
+ }
137
+ }
116
138
}
117
139
}
118
140
119
- // When called, checks level of battery
120
- // And outputs a serial message to USB
141
+ // Updates global variables with battery levels
121
142
void checkBatteryLevels ()
122
143
{
123
144
if (online.batteryFuelGauge == false )
@@ -140,35 +161,6 @@ void checkBatteryLevels()
140
161
(float )bq40z50Battery->getAverageCurrentMa () / bq40z50Battery->getFullChargeCapacityMah () * 100.0 ;
141
162
}
142
163
#endif // COMPILE_BQ40Z50
143
-
144
- // Display the battery data
145
- if (settings.enablePrintBatteryMessages )
146
- {
147
- char tempStr[25 ];
148
- if (isCharging ())
149
- snprintf (tempStr, sizeof (tempStr), " C" );
150
- else
151
- snprintf (tempStr, sizeof (tempStr), " Disc" );
152
-
153
- systemPrintf (" Batt (%d%%): Voltage: %0.02fV" , batteryLevelPercent, batteryVoltage);
154
-
155
- systemPrintf (" %sharging: %0.02f%%/hr\r\n " , tempStr, batteryChargingPercentPerHour);
156
- }
157
-
158
- // Check if we need to shutdown due to no charging
159
- if (settings.shutdownNoChargeTimeout_s > 0 )
160
- {
161
- if (isCharging () == false )
162
- {
163
- int secondsSinceLastCharger = (millis () - shutdownNoChargeTimer) / 1000 ;
164
- if (secondsSinceLastCharger > settings.shutdownNoChargeTimeout_s )
165
- powerDown (true );
166
- }
167
- else
168
- {
169
- shutdownNoChargeTimer = millis (); // Reset timer because power is attached
170
- }
171
- }
172
164
}
173
165
174
166
// Ping an I2C device and see if it responds
@@ -356,8 +348,8 @@ void printReports()
356
348
lastPrintPosition = millis ();
357
349
}
358
350
359
- if ((settings.enablePrintRoverAccuracy && (millis () - lastPrintRoverAccuracy > 2000 ))
360
- || (PERIODIC_DISPLAY (PD_MQTT_CLIENT_DATA)))
351
+ if ((settings.enablePrintRoverAccuracy && (millis () - lastPrintRoverAccuracy > 2000 )) ||
352
+ (PERIODIC_DISPLAY (PD_MQTT_CLIENT_DATA)))
361
353
{
362
354
lastPrintRoverAccuracy = millis ();
363
355
PERIODIC_CLEAR (PD_MQTT_CLIENT_DATA);
0 commit comments