Skip to content

Commit 6db6e7f

Browse files
committed
Move printing out of checkBatterLevels()
1 parent 9ff519f commit 6db6e7f

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

Firmware/RTK_Everywhere/System.ino

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void beepOff()
6666

6767
// Update battery levels every 5 seconds
6868
// Update battery charger as needed
69+
// Output serial message if enabled
6970
void updateBattery()
7071
{
7172
if (online.batteryFuelGauge == true)
@@ -77,13 +78,19 @@ void updateBattery()
7778

7879
checkBatteryLevels();
7980

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+
}
8794
}
8895
}
8996

@@ -113,11 +120,25 @@ void updateBattery()
113120
}
114121
}
115122
}
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+
}
116138
}
117139
}
118140

119-
// When called, checks level of battery
120-
// And outputs a serial message to USB
141+
// Updates global variables with battery levels
121142
void checkBatteryLevels()
122143
{
123144
if (online.batteryFuelGauge == false)
@@ -140,35 +161,6 @@ void checkBatteryLevels()
140161
(float)bq40z50Battery->getAverageCurrentMa() / bq40z50Battery->getFullChargeCapacityMah() * 100.0;
141162
}
142163
#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-
}
172164
}
173165

174166
// Ping an I2C device and see if it responds
@@ -356,8 +348,8 @@ void printReports()
356348
lastPrintPosition = millis();
357349
}
358350

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)))
361353
{
362354
lastPrintRoverAccuracy = millis();
363355
PERIODIC_CLEAR(PD_MQTT_CLIENT_DATA);

0 commit comments

Comments
 (0)