Skip to content

Commit

Permalink
Merge pull request #598 from sparkfun/addChargingtime
Browse files Browse the repository at this point in the history
Add shutdown timer and setup ignore
  • Loading branch information
nseidle authored Aug 12, 2023
2 parents 5dfa221 + 6328757 commit 255ac3a
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 501 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compile-rtk-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
env:
FILENAME_PREFIX: RTK_Surveyor_Firmware
FIRMWARE_VERSION_MAJOR: 3
FIRMWARE_VERSION_MINOR: 6
FIRMWARE_VERSION_MINOR: 7
POINTPERFECT_TOKEN: ${{ secrets.POINTPERFECT_TOKEN }}

jobs:
Expand Down
5 changes: 4 additions & 1 deletion Firmware/RTK_Surveyor/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ void beginBoard()
}
}

//We need some settings before we are completely powered on
//ie, disablePowerFiltering, enableResetDisplay, resetCount, etc
loadSettingsPartial(); // Loads settings from LFS

// Setup hardware pins
if (productVariant == RTK_SURVEYOR)
{
Expand Down Expand Up @@ -244,7 +248,6 @@ void beginBoard()
ethernetMACAddress[5] += 3; // Convert MAC address to Ethernet MAC (add 3)

// For all boards, check reset reason. If reset was due to wdt or panic, append last log
loadSettingsPartial(); // Loads settings from LFS
if ((esp_reset_reason() == ESP_RST_POWERON) || (esp_reset_reason() == ESP_RST_SW))
{
reuseLastLog = false; // Start new log
Expand Down
2 changes: 1 addition & 1 deletion Firmware/RTK_Surveyor/Buttons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void powerOnCheck()
if (digitalRead(pin_powerSenseAndControl) == LOW)
delay(500);

if (ENABLE_DEVELOPER == false)
if (settings.powerButtonFiltering == true)
{
if (pin_powerSenseAndControl >= 0)
if (digitalRead(pin_powerSenseAndControl) != LOW)
Expand Down
11 changes: 10 additions & 1 deletion Firmware/RTK_Surveyor/NVM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ void recordSystemSettingsToFile(File *settingsFile)
settingsFile->printf("%s=%d\r\n", "lbandFixTimeout_seconds", settings.lbandFixTimeout_seconds);
settingsFile->printf("%s=%d\r\n", "minCNO_F9R", settings.minCNO_F9R);
settingsFile->printf("%s=%d\r\n", "minCNO_F9P", settings.minCNO_F9P);
settingsFile->printf("%s=%d\r\n", "shutdownNoChargeTimeout_s", settings.shutdownNoChargeTimeout_s);
settingsFile->printf("%s=%d\r\n", "disableSetupButton", settings.disableSetupButton);
settingsFile->printf("%s=%d\r\n", "powerButtonFiltering", settings.powerButtonFiltering);

// Record constellation settings
for (int x = 0; x < MAX_CONSTELLATIONS; x++)
Expand Down Expand Up @@ -1303,6 +1306,12 @@ bool parseLine(char *str, Settings *settings)
settings->bluetoothInterruptsCore = d;
else if (strcmp(settingName, "i2cInterruptsCore") == 0)
settings->i2cInterruptsCore = d;
else if (strcmp(settingName, "shutdownNoChargeTimeout_s") == 0)
settings->shutdownNoChargeTimeout_s = d;
else if (strcmp(settingName, "disableSetupButton") == 0)
settings->disableSetupButton = d;
else if (strcmp(settingName, "powerButtonFiltering") == 0)
settings->powerButtonFiltering = d;

// Network layer
else if (strcmp(settingName, "defaultNetworkType") == 0)
Expand Down Expand Up @@ -1445,7 +1454,7 @@ bool parseLine(char *str, Settings *settings)
// Last catch
if (knownSetting == false)
{
systemPrintf("Unknown setting %s\r\n", settingName);
log_d("Unknown setting %s", settingName);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Firmware/RTK_Surveyor/RTK_Surveyor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ unsigned long lbandLastReport = 0;

volatile PeriodicDisplay_t periodicDisplay;

unsigned long shutdownNoChargeTimer = 0;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/*
+---------------------------------------+ +----------+
Expand Down
38 changes: 26 additions & 12 deletions Firmware/RTK_Surveyor/System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool configureUbloxModule()
if (ENABLE_DEVELOPER && productVariant == REFERENCE_STATION)
theGNSS.enableDebugging(serialGNSS); // Output all debug messages over serialGNSS
else
#endif // REF_STN_GNSS_DEBUG
#endif // REF_STN_GNSS_DEBUG
theGNSS.enableDebugging(Serial, true); // Enable only the critical debug messages over Serial
}
else
Expand Down Expand Up @@ -333,21 +333,20 @@ void checkBatteryLevels()
battChangeRate = 0;
}

if (battChangeRate >= -0.01)
externalPowerConnected = true;
else
externalPowerConnected = false;

if (settings.enablePrintBatteryMessages)
{
systemPrintf("Batt (%d%%): Voltage: %0.02fV", battLevel, battVoltage);

char tempStr[25];
if (battChangeRate >= -0.01)
{
if (externalPowerConnected)
snprintf(tempStr, sizeof(tempStr), "C");
externalPowerConnected = true;
}
else
{
snprintf(tempStr, sizeof(tempStr), "Disc");
externalPowerConnected = false;
}

systemPrintf("Batt (%d%%): Voltage: %0.02fV", battLevel, battVoltage);

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

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

// Check if we need to shutdown due to no charging
if (settings.shutdownNoChargeTimeout_s > 0)
{
if (externalPowerConnected == false)
{
int secondsSinceLastCharger = (millis() - shutdownNoChargeTimer) / 1000;
if (secondsSinceLastCharger > settings.shutdownNoChargeTimeout_s)
powerDown(true);
}
else
{
shutdownNoChargeTimer = millis(); // Reset timer because power is attached
}
}

if (productVariant == RTK_SURVEYOR)
{
if (battLevel < 10)
Expand Down Expand Up @@ -430,7 +444,7 @@ bool createTestFile()
SD_MMC.remove(testFileName);
return (!SD_MMC.exists(testFileName));
}
#endif // COMPILE_SD_MMC
#endif // COMPILE_SD_MMC

return (false);
}
Expand Down Expand Up @@ -1153,7 +1167,7 @@ const char *coordinatePrintableInputType(CoordinateInputType coordinateInputType
}

// Print the error message every 15 seconds
void reportFatalError(const char * errorMsg)
void reportFatalError(const char *errorMsg)
{
while (1)
{
Expand Down
Loading

0 comments on commit 255ac3a

Please sign in to comment.