Skip to content

Commit 339c0af

Browse files
authored
Correct EEPROM LED checks (#443)
* Correct EEPROM LED checks Corrects logic error where EEPROM LED checks were checking against an enum rather than an absolute value, causing the checks for the wand barrel LED count and bargraph segment count to fail to read correctly after a power cycle. * Switch enums to uint8_t This switches the barrel LED count and bargraph segment count enums to be explicit uint8_t variables with definitions that match the respective counts their names imply to simplify code checks.
1 parent 21f75fe commit 339c0af

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

source/NeutronaWand/include/Header.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,13 @@ const uint8_t frutto_barrel[48] PROGMEM = {0, 25, 24, 48, 1, 26, 23, 47, 2, 27,
157157
* Supported options: Stock (5), GPStar Neturona Barrel (48 + 2 Strobe Tips), GPStar Barrel LED Mini (2) and Frutto Technology (48 + Strobe Tip)
158158
*/
159159
uint8_t i_num_barrel_leds = 5;
160-
enum WAND_BARREL_LED_COUNTS { LEDS_5, LEDS_48, LEDS_50, LEDS_2 };
161-
enum WAND_BARREL_LED_COUNTS WAND_BARREL_LED_COUNT;
160+
enum WAND_BARREL_LED_COUNTS : uint8_t {
161+
LEDS_UNKNOWN = 0,
162+
LEDS_2 = 2,
163+
LEDS_5 = 5,
164+
LEDS_48 = 48,
165+
LEDS_50 = 50
166+
} WAND_BARREL_LED_COUNT;
162167

163168
/*
164169
* Delay for fastled to update the addressable LEDs.
@@ -301,9 +306,13 @@ HT16K33 ht_bargraph;
301306
* The Frutto 28-segment bargraph is automatically detected on boot and sets this to true.
302307
* Part #: BL28Z-3005SA04Y
303308
*/
304-
enum BARGRAPH_TYPES { SEGMENTS_5, SEGMENTS_28, SEGMENTS_30 };
305-
enum BARGRAPH_TYPES BARGRAPH_TYPE;
306-
enum BARGRAPH_TYPES BARGRAPH_TYPE_EEPROM;
309+
enum BARGRAPH_TYPES : uint8_t {
310+
SEGMENTS_UNKNOWN = 0,
311+
SEGMENTS_5 = 5,
312+
SEGMENTS_28 = 28,
313+
SEGMENTS_30 = 30
314+
} BARGRAPH_TYPE;
315+
BARGRAPH_TYPES BARGRAPH_TYPE_EEPROM = SEGMENTS_28;
307316

308317
const uint8_t i_bargraph_interval = 4;
309318
const uint8_t i_bargraph_wait = 180;

source/NeutronaWand/include/Preferences.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ void readEEPROM() {
463463
}
464464

465465
// Only override the bargraph LED count if we are not using a stock bargraph.
466-
BARGRAPH_TYPE = BARGRAPH_TYPE_EEPROM;
466+
if(BARGRAPH_TYPE != SEGMENTS_5) {
467+
BARGRAPH_TYPE = BARGRAPH_TYPE_EEPROM;
468+
}
467469
}
468470

469471
if(obj_led_eeprom.rgb_vent_light > 0 && obj_led_eeprom.rgb_vent_light < 3) {
@@ -498,24 +500,10 @@ void clearLEDEEPROM() {
498500
void saveLEDEEPROM() {
499501
uint16_t i_eepromLEDAddress = i_eepromAddress + sizeof(objConfigEEPROM);
500502

501-
uint8_t i_barrel_led_count = 5; // 5 = Hasbro, 50 = GPStar Neutrona Barrel, 2 = GPStar Barrel LED Mini, 48 = Frutto.
502-
uint8_t i_bargraph_led_count = 28; // 28 segment, 30 segment.
503+
uint8_t i_barrel_led_count = WAND_BARREL_LED_COUNT; // 5 = Hasbro, 50 = GPStar Neutrona Barrel, 2 = GPStar Barrel LED Mini, 48 = Frutto.
504+
uint8_t i_bargraph_led_count = BARGRAPH_TYPE_EEPROM; // 28 segment, 30 segment.
503505
uint8_t i_rgb_vent_light = 1; // 1 = RGB Vent Light disabled, 2 = RGB Vent Light enabled
504506

505-
if(WAND_BARREL_LED_COUNT == LEDS_48) {
506-
i_barrel_led_count = 48;
507-
}
508-
else if(WAND_BARREL_LED_COUNT == LEDS_50) {
509-
i_barrel_led_count = 50; // Needs to be a 50. However we change it back to 48 after it is saved to the EEPROM.
510-
}
511-
else if(WAND_BARREL_LED_COUNT == LEDS_2) {
512-
i_barrel_led_count = 2;
513-
}
514-
515-
if(BARGRAPH_TYPE_EEPROM == SEGMENTS_30) {
516-
i_bargraph_led_count = 30;
517-
}
518-
519507
if(b_rgb_vent_light) {
520508
i_rgb_vent_light = 2;
521509
}
@@ -533,10 +521,6 @@ void saveLEDEEPROM() {
533521
EEPROM.put(i_eepromLEDAddress, obj_led_eeprom);
534522

535523
updateCRCEEPROM();
536-
537-
if(WAND_BARREL_LED_COUNT == LEDS_50) {
538-
i_barrel_led_count = 48; // Needs to be reset back to 48 while 50 is stored in the EEPROM. 2 are for the tip.
539-
}
540524
}
541525

542526
void clearConfigEEPROM() {

0 commit comments

Comments
 (0)