Skip to content

Commit 255ac3a

Browse files
authored
Merge pull request #598 from sparkfun/addChargingtime
Add shutdown timer and setup ignore
2 parents 5dfa221 + 6328757 commit 255ac3a

File tree

12 files changed

+598
-501
lines changed

12 files changed

+598
-501
lines changed

.github/workflows/compile-rtk-firmware.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
env:
77
FILENAME_PREFIX: RTK_Surveyor_Firmware
88
FIRMWARE_VERSION_MAJOR: 3
9-
FIRMWARE_VERSION_MINOR: 6
9+
FIRMWARE_VERSION_MINOR: 7
1010
POINTPERFECT_TOKEN: ${{ secrets.POINTPERFECT_TOKEN }}
1111

1212
jobs:

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ void beginBoard()
116116
}
117117
}
118118

119+
//We need some settings before we are completely powered on
120+
//ie, disablePowerFiltering, enableResetDisplay, resetCount, etc
121+
loadSettingsPartial(); // Loads settings from LFS
122+
119123
// Setup hardware pins
120124
if (productVariant == RTK_SURVEYOR)
121125
{
@@ -244,7 +248,6 @@ void beginBoard()
244248
ethernetMACAddress[5] += 3; // Convert MAC address to Ethernet MAC (add 3)
245249

246250
// For all boards, check reset reason. If reset was due to wdt or panic, append last log
247-
loadSettingsPartial(); // Loads settings from LFS
248251
if ((esp_reset_reason() == ESP_RST_POWERON) || (esp_reset_reason() == ESP_RST_SW))
249252
{
250253
reuseLastLog = false; // Start new log

Firmware/RTK_Surveyor/Buttons.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void powerOnCheck()
88
if (digitalRead(pin_powerSenseAndControl) == LOW)
99
delay(500);
1010

11-
if (ENABLE_DEVELOPER == false)
11+
if (settings.powerButtonFiltering == true)
1212
{
1313
if (pin_powerSenseAndControl >= 0)
1414
if (digitalRead(pin_powerSenseAndControl) != LOW)

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ void recordSystemSettingsToFile(File *settingsFile)
362362
settingsFile->printf("%s=%d\r\n", "lbandFixTimeout_seconds", settings.lbandFixTimeout_seconds);
363363
settingsFile->printf("%s=%d\r\n", "minCNO_F9R", settings.minCNO_F9R);
364364
settingsFile->printf("%s=%d\r\n", "minCNO_F9P", settings.minCNO_F9P);
365+
settingsFile->printf("%s=%d\r\n", "shutdownNoChargeTimeout_s", settings.shutdownNoChargeTimeout_s);
366+
settingsFile->printf("%s=%d\r\n", "disableSetupButton", settings.disableSetupButton);
367+
settingsFile->printf("%s=%d\r\n", "powerButtonFiltering", settings.powerButtonFiltering);
365368

366369
// Record constellation settings
367370
for (int x = 0; x < MAX_CONSTELLATIONS; x++)
@@ -1303,6 +1306,12 @@ bool parseLine(char *str, Settings *settings)
13031306
settings->bluetoothInterruptsCore = d;
13041307
else if (strcmp(settingName, "i2cInterruptsCore") == 0)
13051308
settings->i2cInterruptsCore = d;
1309+
else if (strcmp(settingName, "shutdownNoChargeTimeout_s") == 0)
1310+
settings->shutdownNoChargeTimeout_s = d;
1311+
else if (strcmp(settingName, "disableSetupButton") == 0)
1312+
settings->disableSetupButton = d;
1313+
else if (strcmp(settingName, "powerButtonFiltering") == 0)
1314+
settings->powerButtonFiltering = d;
13061315

13071316
// Network layer
13081317
else if (strcmp(settingName, "defaultNetworkType") == 0)
@@ -1445,7 +1454,7 @@ bool parseLine(char *str, Settings *settings)
14451454
// Last catch
14461455
if (knownSetting == false)
14471456
{
1448-
systemPrintf("Unknown setting %s\r\n", settingName);
1457+
log_d("Unknown setting %s", settingName);
14491458
}
14501459
}
14511460

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ unsigned long lbandLastReport = 0;
666666

667667
volatile PeriodicDisplay_t periodicDisplay;
668668

669+
unsigned long shutdownNoChargeTimer = 0;
670+
669671
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
670672
/*
671673
+---------------------------------------+ +----------+

Firmware/RTK_Surveyor/System.ino

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool configureUbloxModule()
1515
if (ENABLE_DEVELOPER && productVariant == REFERENCE_STATION)
1616
theGNSS.enableDebugging(serialGNSS); // Output all debug messages over serialGNSS
1717
else
18-
#endif // REF_STN_GNSS_DEBUG
18+
#endif // REF_STN_GNSS_DEBUG
1919
theGNSS.enableDebugging(Serial, true); // Enable only the critical debug messages over Serial
2020
}
2121
else
@@ -333,21 +333,20 @@ void checkBatteryLevels()
333333
battChangeRate = 0;
334334
}
335335

336+
if (battChangeRate >= -0.01)
337+
externalPowerConnected = true;
338+
else
339+
externalPowerConnected = false;
340+
336341
if (settings.enablePrintBatteryMessages)
337342
{
338-
systemPrintf("Batt (%d%%): Voltage: %0.02fV", battLevel, battVoltage);
339-
340343
char tempStr[25];
341-
if (battChangeRate >= -0.01)
342-
{
344+
if (externalPowerConnected)
343345
snprintf(tempStr, sizeof(tempStr), "C");
344-
externalPowerConnected = true;
345-
}
346346
else
347-
{
348347
snprintf(tempStr, sizeof(tempStr), "Disc");
349-
externalPowerConnected = false;
350-
}
348+
349+
systemPrintf("Batt (%d%%): Voltage: %0.02fV", battLevel, battVoltage);
351350

352351
systemPrintf(" %sharging: %0.02f%%/hr ", tempStr, battChangeRate);
353352

@@ -363,6 +362,21 @@ void checkBatteryLevels()
363362
systemPrintf("%s\r\n", tempStr);
364363
}
365364

365+
// Check if we need to shutdown due to no charging
366+
if (settings.shutdownNoChargeTimeout_s > 0)
367+
{
368+
if (externalPowerConnected == false)
369+
{
370+
int secondsSinceLastCharger = (millis() - shutdownNoChargeTimer) / 1000;
371+
if (secondsSinceLastCharger > settings.shutdownNoChargeTimeout_s)
372+
powerDown(true);
373+
}
374+
else
375+
{
376+
shutdownNoChargeTimer = millis(); // Reset timer because power is attached
377+
}
378+
}
379+
366380
if (productVariant == RTK_SURVEYOR)
367381
{
368382
if (battLevel < 10)
@@ -430,7 +444,7 @@ bool createTestFile()
430444
SD_MMC.remove(testFileName);
431445
return (!SD_MMC.exists(testFileName));
432446
}
433-
#endif // COMPILE_SD_MMC
447+
#endif // COMPILE_SD_MMC
434448

435449
return (false);
436450
}
@@ -1153,7 +1167,7 @@ const char *coordinatePrintableInputType(CoordinateInputType coordinateInputType
11531167
}
11541168

11551169
// Print the error message every 15 seconds
1156-
void reportFatalError(const char * errorMsg)
1170+
void reportFatalError(const char *errorMsg)
11571171
{
11581172
while (1)
11591173
{

0 commit comments

Comments
 (0)