Skip to content

Commit de204f5

Browse files
committed
Make getProfileNumberFromUnit return -1 on fail
Also fix NTP clock blinking
1 parent 5d989ff commit de204f5

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

Firmware/RTK_Everywhere/Display.ino

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,14 +1308,17 @@ void paintHorizontalAccuracy(displayCoords textCoords)
13081308
// Display clock with moving hands
13091309
void paintClock(std::vector<iconPropertyBlinking> *iconList, bool blinking)
13101310
{
1311-
// Animate icon to show system running
1312-
static uint8_t clockIconDisplayed = CLOCK_ICON_STATES - 1;
1313-
clockIconDisplayed++; // Goto next icon
1314-
clockIconDisplayed %= CLOCK_ICON_STATES; // Wrap
1311+
// Animate icon to show system running. The 2* makes the blink correct
1312+
static uint8_t clockIconDisplayed = (2 * CLOCK_ICON_STATES) - 1;
1313+
clockIconDisplayed++; // Goto next icon
1314+
clockIconDisplayed %= (2 * CLOCK_ICON_STATES); // Wrap
13151315

13161316
iconPropertyBlinking prop;
1317-
prop.icon = ClockIconProperties.iconDisplay[clockIconDisplayed][present.display_type];
1318-
prop.duty = 0b01010101;
1317+
prop.icon = ClockIconProperties.iconDisplay[clockIconDisplayed / 2][present.display_type];
1318+
if (blinking)
1319+
prop.duty = 0b01010101;
1320+
else
1321+
prop.duty = 0b11111111;
13191322
iconList->push_back(prop);
13201323

13211324
displayCoords textCoords;
@@ -2257,19 +2260,29 @@ void paintProfile(uint8_t profileUnit)
22572260
if (getProfileNameFromUnit(profileUnit, profileName, sizeof(profileName)) ==
22582261
true) // Load the profile name, limited to 8 chars
22592262
{
2260-
settings.updateGNSSSettings = true; // When this profile is loaded next, force system to update GNSS settings.
2261-
recordSystemSettings(); // Before switching, we need to record the current settings to LittleFS and SD
2263+
// Lookup profileNumber based on unit.
2264+
// getProfileNumberFromUnit should not fail (return -1), because we have already called getProfileNameFromUnit.
2265+
int8_t profileNumber = getProfileNumberFromUnit(profileUnit);
22622266

2263-
// Lookup profileNumber based on unit
2264-
uint8_t profileNumber = getProfileNumberFromUnit(profileUnit);
2265-
recordProfileNumber(profileNumber); // Update internal settings with user's choice, mark unit for config update
2267+
if (profileNumber >= 0)
2268+
{
2269+
settings.updateGNSSSettings = true; // When this profile is loaded next, force system to update GNSS settings.
2270+
recordSystemSettings(); // Before switching, we need to record the current settings to LittleFS and SD
22662271

2267-
log_d("Going to profile number %d from unit %d, name '%s'", profileNumber, profileUnit, profileName);
2272+
recordProfileNumber((uint8_t)profileNumber); // Update internal settings with user's choice, mark unit for config update
22682273

2269-
snprintf(profileMessage, sizeof(profileMessage), "Loading %s", profileName);
2270-
displayMessage(profileMessage, 2000);
2271-
ESP.restart(); // Profiles require full restart to take effect
2274+
log_d("Going to profile number %d from unit %d, name '%s'", profileNumber, profileUnit, profileName);
2275+
2276+
snprintf(profileMessage, sizeof(profileMessage), "Loading %s", profileName);
2277+
displayMessage(profileMessage, 2000);
2278+
ESP.restart(); // Profiles require full restart to take effect
2279+
}
22722280
}
2281+
2282+
log_d("Cannot go to profileUnit %d. No profile name / number. Restarting...", profileUnit);
2283+
snprintf(profileMessage, sizeof(profileMessage), "Invalid profile%d", profileUnit);
2284+
displayMessage(profileMessage, 2000);
2285+
ESP.restart(); // Something bad happened. Restart...
22732286
}
22742287

22752288
// Display unit self-tests until user presses a button to exit

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,8 +1888,8 @@ bool getProfileNameFromUnit(uint8_t profileUnit, char *profileName, uint8_t prof
18881888

18891889
// Return profile number based on units
18901890
// Profiles may not be sequential (user might have empty profile #2, but filled #3) so we look up the profile unit and
1891-
// return the count
1892-
uint8_t getProfileNumberFromUnit(uint8_t profileUnit)
1891+
// return the count. Return -1 if profileUnit is not found.
1892+
int8_t getProfileNumberFromUnit(uint8_t profileUnit)
18931893
{
18941894
uint8_t located = 0;
18951895

@@ -1906,7 +1906,7 @@ uint8_t getProfileNumberFromUnit(uint8_t profileUnit)
19061906
}
19071907
log_d("Profile unit %d not found", profileUnit);
19081908

1909-
return (0);
1909+
return (-1);
19101910
}
19111911

19121912
// Record large character blob to file

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TwoWire *i2cDisplay = nullptr;
175175

176176
#define MAX_PROFILE_COUNT 8
177177
uint8_t activeProfiles; // Bit vector indicating which profiles are active
178-
uint8_t displayProfile; // Range: 0 - (MAX_PROFILE_COUNT - 1)
178+
uint8_t displayProfile; // Profile Unit - Range: 0 - (MAX_PROFILE_COUNT - 1)
179179
uint8_t profileNumber = MAX_PROFILE_COUNT; // profileNumber gets set once at boot to save loading time
180180
char profileNames[MAX_PROFILE_COUNT][50]; // Populated based on names found in LittleFS and SD
181181
char settingsFileName[60]; // Contains the %s_Settings_%d.txt with current profile number set

Firmware/RTK_Everywhere/States.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,17 +1238,17 @@ void constructSetupDisplay(std::vector<setupButton> *buttons)
12381238
}
12391239
addSetupButton(buttons, "E-Pair", STATE_ESPNOW_PAIRING_NOT_STARTED);
12401240
// If only one active profile do not show any profiles
1241-
if (getProfileNumberFromUnit(1) > 0)
1241+
if (getProfileNumberFromUnit(1) >= 0)
12421242
{
12431243
for (int x = 0; x < MAX_PROFILE_COUNT; x++)
12441244
{
1245-
int activeProfile = getProfileNumberFromUnit(x);
1246-
if ((x == 0) || (activeProfile > 0))
1245+
int profile = getProfileNumberFromUnit(x);
1246+
if (profile >= 0)
12471247
{
12481248
setupButton button;
1249-
button.name = &profileNames[activeProfile][0];
1249+
button.name = &profileNames[profile][0];
12501250
button.newState = STATE_PROFILE;
1251-
button.newProfile = x;
1251+
button.newProfile = x; // paintProfile needs the unit
12521252
buttons->push_back(button);
12531253
}
12541254
}

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,8 +1490,8 @@ void buttonCheckTask(void *e)
14901490

14911491
if (theButton.newState == STATE_PROFILE)
14921492
{
1493-
displayProfile = theButton.newProfile;
1494-
requestChangeState(theButton.newState);
1493+
displayProfile = theButton.newProfile; // paintProfile needs the unit
1494+
requestChangeState(STATE_PROFILE);
14951495
}
14961496
else if (theButton.newState == STATE_NOT_SET) // Exit
14971497
requestChangeState(lastSystemState);

0 commit comments

Comments
 (0)