Skip to content

Commit 7044b47

Browse files
committed
Add getProfileCount()
1 parent 388670d commit 7044b47

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,20 @@ int8_t getProfileNumberFromUnit(uint8_t profileUnit)
14241424
return (-1);
14251425
}
14261426

1427+
// Returns the number of available profiles
1428+
// https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation
1429+
uint8_t getProfileCount()
1430+
{
1431+
int count = 0;
1432+
uint8_t n = activeProfiles;
1433+
while (n != 0)
1434+
{
1435+
n = n & (n - 1);
1436+
count++;
1437+
}
1438+
return (count);
1439+
}
1440+
14271441
// Record large character blob to file
14281442
void recordFile(const char *fileID, char *fileContents, uint32_t fileSize)
14291443
{

Firmware/RTK_Everywhere/States.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,9 @@ void constructSetupDisplay(std::vector<setupButton> *buttons)
12301230
}
12311231
addSetupButton(buttons, "E-Pair", STATE_ESPNOW_PAIRING_NOT_STARTED);
12321232
// If only one active profile do not show any profiles
1233-
if (getProfileNumberFromUnit(1) >= 0)
1233+
if (getProfileCount() > 1)
12341234
{
1235-
for (int x = 0; x < MAX_PROFILE_COUNT; x++)
1235+
for (int x = 0; x < getProfileCount(); x++)
12361236
{
12371237
int profile = getProfileNumberFromUnit(x);
12381238
if (profile >= 0)

0 commit comments

Comments
 (0)