Skip to content

Commit 9dd6e79

Browse files
LeeLeahy2nseidle
authored andcommitted
Allow more than 4 profile states
Use a bit vector to specify the active profiles. The number of profiles may be increased to 8 without any changes. Changing activeProfiles to a uint32_t enables up to 32 profiles, or 64 profiles by using a uint64_t. The uint8_t for profileNumber, displayProfile and index do not need to be increased unless the total number of profiles exceeds 256. The following changes were made: * At reset, assume no profiles are active * Change the activeProfiles variable to a bit vector * Remove the STATE_PROFILE_* values * Add the STATE_PROFILE value * Change the NVM routines to support a bit vector * Change the display routines to use the bit vector * Change the button routine to use the bit vector * Combine display code that displays the profiles
1 parent eea8a52 commit 9dd6e79

File tree

7 files changed

+101
-223
lines changed

7 files changed

+101
-223
lines changed

Firmware/RTK_Surveyor/Display.ino

Lines changed: 55 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,8 @@ void updateDisplay()
243243
case (STATE_BUBBLE_LEVEL):
244244
paintBubbleLevel();
245245
break;
246-
case (STATE_PROFILE_1):
247-
paintProfile(0);
248-
break;
249-
case (STATE_PROFILE_2):
250-
paintProfile(1);
251-
break;
252-
case (STATE_PROFILE_3):
253-
paintProfile(2);
254-
break;
255-
case (STATE_PROFILE_4):
256-
paintProfile(3);
246+
case (STATE_PROFILE):
247+
paintProfile(displayProfile);
257248
break;
258249
case (STATE_MARK_EVENT):
259250
//Do nothing. Static display shown during state change.
@@ -1271,7 +1262,7 @@ void paintProfile(uint8_t profileUnit)
12711262
char profileMessage[20]; //'Loading HomeStar' max of ~18 chars
12721263

12731264
char profileName[8 + 1];
1274-
if (getProfileNameFromUnit(profileUnit, profileName, 8) == true) //Load the profile name, limited to 8 chars
1265+
if (getProfileNameFromUnit(profileUnit, profileName, sizeof(profileName)) == true) //Load the profile name, limited to 8 chars
12751266
{
12761267
settings.updateZEDSettings = true; //When this profile is loaded next, force system to update ZED settings.
12771268
recordSystemSettings(); //Before switching, we need to record the current settings to LittleFS and SD
@@ -1544,6 +1535,54 @@ void getAngles()
15441535
}
15451536
}
15461537

1538+
//Display the setup profiles
1539+
void paintDisplaySetupProfile(const char * firstState)
1540+
{
1541+
int index;
1542+
int itemsDisplayed;
1543+
char profileName[8 + 1];
1544+
1545+
//Display the first state if this is the first profile
1546+
itemsDisplayed = 0;
1547+
if (displayProfile == 0)
1548+
{
1549+
printTextCenter(firstState, 12 * itemsDisplayed, QW_FONT_8X16, 1, false);
1550+
itemsDisplayed++;
1551+
}
1552+
1553+
//Display Bubble if this is the second profile
1554+
if (displayProfile <= 1)
1555+
{
1556+
printTextCenter("Bubble", 12 * itemsDisplayed, QW_FONT_8X16, 1, false);
1557+
itemsDisplayed++;
1558+
}
1559+
1560+
//Display Config if this is the third profile
1561+
if (displayProfile <= 2)
1562+
{
1563+
printTextCenter("Config", 12 * itemsDisplayed, QW_FONT_8X16, 1, false);
1564+
itemsDisplayed++;
1565+
}
1566+
1567+
// displayProfile itemsDisplayed index
1568+
// 0 3 0
1569+
// 1 2 0
1570+
// 2 1 0
1571+
// 3 0 0
1572+
// 4 0 1
1573+
// 5 0 2
1574+
// n >= 3 0 n - 3
1575+
1576+
//Display the profile names
1577+
for (index = (displayProfile >= 3) ? displayProfile - 3 : 0; itemsDisplayed < 4; itemsDisplayed++)
1578+
{
1579+
//Lookup next available profile, limit to 8 characters
1580+
getProfileNameFromUnit(index, profileName, sizeof(profileName));
1581+
printTextCenter(profileName, 12 * itemsDisplayed, QW_FONT_8X16, 1, itemsDisplayed == 3);
1582+
index++;
1583+
}
1584+
}
1585+
15471586
//Show different menu 'buttons' to allow user to pause on one to select it
15481587
void paintDisplaySetup()
15491588
{
@@ -1584,61 +1623,8 @@ void paintDisplaySetup()
15841623
printTextCenter("Bubble", 12 * 2, QW_FONT_8X16, 1, false);
15851624
printTextCenter("Config", 12 * 3, QW_FONT_8X16, 1, true);
15861625
}
1587-
else if (setupState == STATE_PROFILE_1)
1588-
{
1589-
char profileName[8 + 1];
1590-
1591-
printTextCenter("Base", 12 * 0, QW_FONT_8X16, 1, false);
1592-
printTextCenter("Bubble", 12 * 1, QW_FONT_8X16, 1, false);
1593-
printTextCenter("Config", 12 * 2, QW_FONT_8X16, 1, false);
1594-
1595-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1596-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1597-
}
1598-
else if (setupState == STATE_PROFILE_2)
1599-
{
1600-
char profileName[8 + 1];
1601-
1602-
printTextCenter("Bubble", 12 * 0, QW_FONT_8X16, 1, false);
1603-
printTextCenter("Config", 12 * 1, QW_FONT_8X16, 1, false);
1604-
1605-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1606-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1607-
1608-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1609-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1610-
}
1611-
else if (setupState == STATE_PROFILE_3)
1612-
{
1613-
char profileName[8 + 1];
1614-
1615-
printTextCenter("Config", 12 * 0, QW_FONT_8X16, 1, false);
1616-
1617-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1618-
printTextCenter(profileName, 12 * 1, QW_FONT_8X16, 1, false);
1619-
1620-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1621-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1622-
1623-
getProfileNameFromUnit(2, profileName, 8); //Lookup third available profile, limit to 8 characters
1624-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1625-
}
1626-
else if (setupState == STATE_PROFILE_4)
1627-
{
1628-
char profileName[8 + 1];
1629-
1630-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1631-
printTextCenter(profileName, 12 * 0, QW_FONT_8X16, 1, false);
1632-
1633-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1634-
printTextCenter(profileName, 12 * 1, QW_FONT_8X16, 1, false);
1635-
1636-
getProfileNameFromUnit(2, profileName, 8); //Lookup third available profile, limit to 8 characters
1637-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1638-
1639-
getProfileNameFromUnit(3, profileName, 8); //Lookup forth available profile, limit to 8 characters
1640-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1641-
}
1626+
else if (setupState == STATE_PROFILE)
1627+
paintDisplaySetupProfile("Base");
16421628
} //end type F9P
16431629
else if (zedModuleType == PLATFORM_F9R)
16441630
{
@@ -1670,61 +1656,8 @@ void paintDisplaySetup()
16701656
printTextCenter("Bubble", 12 * 2, QW_FONT_8X16, 1, false);
16711657
printTextCenter("Config", 12 * 3, QW_FONT_8X16, 1, true);
16721658
}
1673-
else if (setupState == STATE_PROFILE_1)
1674-
{
1675-
char profileName[8 + 1];
1676-
1677-
printTextCenter("Rover", 12 * 0, QW_FONT_8X16, 1, false);
1678-
printTextCenter("Bubble", 12 * 1, QW_FONT_8X16, 1, false);
1679-
printTextCenter("Config", 12 * 2, QW_FONT_8X16, 1, false);
1680-
1681-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1682-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1683-
}
1684-
else if (setupState == STATE_PROFILE_2)
1685-
{
1686-
char profileName[8 + 1];
1687-
1688-
printTextCenter("Bubble", 12 * 0, QW_FONT_8X16, 1, false);
1689-
printTextCenter("Config", 12 * 1, QW_FONT_8X16, 1, false);
1690-
1691-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1692-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1693-
1694-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1695-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1696-
}
1697-
else if (setupState == STATE_PROFILE_3)
1698-
{
1699-
char profileName[8 + 1];
1700-
1701-
printTextCenter("Config", 12 * 0, QW_FONT_8X16, 1, false);
1702-
1703-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1704-
printTextCenter(profileName, 12 * 1, QW_FONT_8X16, 1, false);
1705-
1706-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1707-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1708-
1709-
getProfileNameFromUnit(2, profileName, 8); //Lookup third available profile, limit to 8 characters
1710-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1711-
}
1712-
else if (setupState == STATE_PROFILE_4)
1713-
{
1714-
char profileName[8 + 1];
1715-
1716-
getProfileNameFromUnit(0, profileName, 8); //Lookup first available profile, limit to 8 characters
1717-
printTextCenter(profileName, 12 * 0, QW_FONT_8X16, 1, false);
1718-
1719-
getProfileNameFromUnit(1, profileName, 8); //Lookup second available profile, limit to 8 characters
1720-
printTextCenter(profileName, 12 * 1, QW_FONT_8X16, 1, false);
1721-
1722-
getProfileNameFromUnit(2, profileName, 8); //Lookup third available profile, limit to 8 characters
1723-
printTextCenter(profileName, 12 * 2, QW_FONT_8X16, 1, false);
1724-
1725-
getProfileNameFromUnit(3, profileName, 8); //Lookup forth available profile, limit to 8 characters
1726-
printTextCenter(profileName, 12 * 3, QW_FONT_8X16, 1, true);
1727-
}
1659+
else if (setupState == STATE_PROFILE)
1660+
paintDisplaySetupProfile("Rover");
17281661
} //end type F9R
17291662
}
17301663

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ void loadSettings()
2929
//Record these settings to LittleFS and SD file to be sure they are the same
3030
recordSystemSettings();
3131

32-
activeProfiles = loadProfileNames(); //Count is used during menu display
32+
//Get bitmask of active profiles
33+
activeProfiles = loadProfileNames();
3334

3435
Serial.printf("Profile '%s' loaded\n\r", profileNames[profileNumber]);
3536
}
@@ -917,7 +918,7 @@ void loadProfileNumber()
917918
fileProfileNumber.close();
918919
}
919920

920-
//We have arbitrary limit of 4 user profiles
921+
//We have arbitrary limit of user profiles
921922
if (profileNumber >= MAX_PROFILE_COUNT)
922923
{
923924
log_d("ProfileNumber invalid. Going to zero.");
@@ -946,7 +947,7 @@ void recordProfileNumber(uint8_t profileNumber)
946947
//If both SD and LittleFS contain a profile, SD wins.
947948
uint8_t loadProfileNames()
948949
{
949-
int profileCount = 0;
950+
int profiles = 0;
950951

951952
for (int x = 0 ; x < MAX_PROFILE_COUNT ; x++)
952953
profileNames[x][0] = '\0'; //Ensure every profile name is terminated
@@ -958,16 +959,12 @@ uint8_t loadProfileNames()
958959
sprintf(fileName, "/%s_Settings_%d.txt", platformFilePrefix, x);
959960

960961
if (getProfileName(fileName, profileNames[x], sizeof(profileNames[x])) == true)
961-
profileCount++;
962+
//Mark this profile as active
963+
profiles |= 1 << x;
962964
}
963965

964-
// Serial.printf("profileCount: %d\n\r", profileCount);
965-
// Serial.println("Profiles:");
966-
// for (int x = 0 ; x < MAX_PROFILE_COUNT ; x++)
967-
// Serial.printf("%d) %s\n\r", x, profileNames[x]);
968-
// Serial.println();
969-
970-
return (profileCount);
966+
Serial.printf("profiles: 0x%02x\r\n", profiles);
967+
return (profiles);
971968
}
972969

973970
//Open the clear text file, scan for 'profileName' and return the string
@@ -982,8 +979,9 @@ bool getProfileName(char *fileName, char *profileName, uint8_t profileNameLength
982979
bool responseLFS = loadSystemSettingsFromFileLFS(fileName, tempSettings);
983980
bool responseSD = loadSystemSettingsFromFileSD(fileName, tempSettings);
984981

982+
//Zero terminate the profile name
983+
*profileName = 0;
985984
if (responseLFS == true || responseSD == true)
986-
//strncpy(profileName, tempSettings->profileName, profileNameLength); //strncpy does not automatically null terminate
987985
snprintf(profileName, profileNameLength, "%s", tempSettings->profileName); //snprintf handles null terminator
988986

989987
delete tempSettings;
@@ -998,10 +996,10 @@ bool getProfileNameFromUnit(uint8_t profileUnit, char *profileName, uint8_t prof
998996
{
999997
uint8_t located = 0;
1000998

1001-
//Step through possible profiles looking for the 1st, 2nd, 3rd, or 4th unit
999+
//Step through possible profiles looking for the specified unit
10021000
for (int x = 0 ; x < MAX_PROFILE_COUNT ; x++)
10031001
{
1004-
if (strlen(profileNames[x]) > 0)
1002+
if (activeProfiles & (1 << x))
10051003
{
10061004
if (located == profileUnit)
10071005
{
@@ -1026,7 +1024,7 @@ uint8_t getProfileNumberFromUnit(uint8_t profileUnit)
10261024
//Step through possible profiles looking for the 1st, 2nd, 3rd, or 4th unit
10271025
for (int x = 0 ; x < MAX_PROFILE_COUNT ; x++)
10281026
{
1029-
if (strlen(profileNames[x]) > 0)
1027+
if (activeProfiles & (1 << x))
10301028
{
10311029
if (located == profileUnit)
10321030
return (x);

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ int pin_radio_rts;
8484
#include <LittleFS.h>
8585

8686
#define MAX_PROFILE_COUNT 4
87-
uint8_t activeProfiles = 1;
87+
uint8_t activeProfiles = 0; //Bit vector indicating which profiles are active
88+
uint8_t displayProfile; //Range: 0 - (MAX_PROFILE_COUNT - 1)
8889
uint8_t profileNumber = MAX_PROFILE_COUNT; //profileNumber gets set once at boot to save loading time
8990
char profileNames[MAX_PROFILE_COUNT][50]; //Populated based on names found in LittleFS and SD
9091
char settingsFileName[40]; //Contains the %s_Settings_%d.txt with current profile number set

Firmware/RTK_Surveyor/States.ino

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -412,25 +412,7 @@ void updateSystemState()
412412
}
413413
break;
414414

415-
case (STATE_PROFILE_1):
416-
{
417-
//Do nothing - display only
418-
}
419-
break;
420-
421-
case (STATE_PROFILE_2):
422-
{
423-
//Do nothing - display only
424-
}
425-
break;
426-
427-
case (STATE_PROFILE_3):
428-
{
429-
//Do nothing - display only
430-
}
431-
break;
432-
433-
case (STATE_PROFILE_4):
415+
case (STATE_PROFILE):
434416
{
435417
//Do nothing - display only
436418
}
@@ -1009,17 +991,8 @@ void changeState(SystemState newState)
1009991
case (STATE_TESTING):
1010992
Serial.print(F("State: System Testing"));
1011993
break;
1012-
case (STATE_PROFILE_1):
1013-
Serial.print(F("State: Profile 1"));
1014-
break;
1015-
case (STATE_PROFILE_2):
1016-
Serial.print(F("State: Profile 2"));
1017-
break;
1018-
case (STATE_PROFILE_3):
1019-
Serial.print(F("State: Profile 3"));
1020-
break;
1021-
case (STATE_PROFILE_4):
1022-
Serial.print(F("State: Profile 4"));
994+
case (STATE_PROFILE):
995+
Serial.print(F("State: Profile"));
1023996
break;
1024997
case (STATE_KEYS_STARTED):
1025998
Serial.print(F("State: Keys Started "));

0 commit comments

Comments
 (0)