Skip to content

Commit 669fea3

Browse files
committed
Simplify functionality switches in config
1 parent 04a10d1 commit 669fea3

File tree

9 files changed

+132
-292
lines changed

9 files changed

+132
-292
lines changed

arduino-nixie/arduino-nixie.ino

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
////////// Hardware configuration //////////
88
//Include the config file that matches your hardware setup. If needed, duplicate an existing one.
99

10-
#include "configs/v8-6tube.h"
10+
#include "configs/v9-6tube.h"
1111

1212
////////// Software version //////////
1313
const byte vMajor = 1;
@@ -73,7 +73,7 @@ Some are skipped when they wouldn't apply to a given clock's hardware config, se
7373
42 Alarm signal, 0=beeper, 1=relay - skipped when no relay (start=0) or no piezo (start=0)
7474
43 Timer signal - skipped when no relay (start=0) or no piezo (start=1)
7575
44 Strike signal - skipped when no pulse relay (start=0) or no piezo (start=1)
76-
45 Temperature format - skipped when fnIsTemp is not in fnsEnabled TODO also useful for weather display
76+
45 Temperature format - skipped when !enableTemp TODO also useful for weather display
7777
46 Anti-cathode poisoning
7878
47 Alarm beeper pattern - skipped when no piezo
7979
48 Timer beeper pattern - skipped when no piezo
@@ -105,9 +105,16 @@ unsigned long inputLast2 = 0; //Second-to-last of above
105105
//TODO the math between these two may fail very rarely due to millis() rolling over while setting. Need to find a fix. I think it only applies to the rotary encoder though.
106106
int inputLastTODMins = 0; //time of day, in minutes past midnight, when button was pressed. Used in paginated functions so they all reflect the same TOD.
107107

108+
// Functions and pages
109+
// Unique IDs - see also fnScroll
110+
const byte fnIsTime = 0; //time of day
111+
const byte fnIsDate = 1; //date, with optional day counter and sunrise/sunset pages
112+
const byte fnIsAlarm = 2; //alarm time
113+
const byte fnIsTimer = 3; //countdown timer and chronograph
114+
const byte fnIsTemp = 4; //temperature per DS3231 – will likely read high
115+
const byte fnIsTest = 5; //simply cycles all tubes
108116
const byte fnOpts = 201; //fn values from here to 255 correspond to options in the options menu
109-
byte fn = fnIsTime; //currently displayed fn per fnsEnabled in config
110-
byte fnsOn = 0; //which fns are enabled per fnsEnabled in config - one bit per fn unique ID - this limits the available fn unique IDs to 0–7; otherwise it could be 0–200 – if you need more than 7, change from a byte to a bigger data type
117+
byte fn = 0; //currently displayed fn per above
111118
byte fnPg = 0; //allows a function to have multiple pages
112119
byte fnSetPg = 0; //whether this function is currently being set, and which option/page it's on
113120
int fnSetVal; //the value currently being set, if any
@@ -169,35 +176,22 @@ void setup(){
169176
writeEEPROM(21,0,false); //turn off strike
170177
writeEEPROM(50,0,false); //turn off fibonacci mode
171178
}
172-
//Check to see which functions are enabled
173-
for(byte fnct=0; fnct<sizeof(fnsEnabled); fnct++){
174-
switch(fnsEnabled[fnct]){
175-
case fnIsTime: bitWrite(fnsOn,fnIsTime,1); break;
176-
case fnIsDate: bitWrite(fnsOn,fnIsDate,1); break;
177-
case fnIsAlarm: bitWrite(fnsOn,fnIsAlarm,1); break;
178-
case fnIsTimer: bitWrite(fnsOn,fnIsTimer,1); break;
179-
case fnIsTemp: bitWrite(fnsOn,fnIsTemp,1); break;
180-
case fnIsTubeTester: bitWrite(fnsOn,fnIsTubeTester,1); break;
181-
default: break;
182-
}
183-
}
184-
if(!((fnsOn>>fnIsAlarm)&1)) alarmOn = 0; //if alarm is disabled in config
179+
if(!enableAlarm) alarmOn = 0; //if alarm is disabled in config
185180
else if(!enableSoftAlarmSwitch) alarmOn = 1; //force alarm on if software switch is disabled
186181
else alarmOn = (readEEPROM(2,false)>0); //otherwise set alarm per EEPROM backup
187182
switch(readEEPROM(7,false)){ //if the preset is set to a function that is no longer enabled, use alarm if enabled, else use time
188-
case fnIsDate: if(!((fnsOn>>fnIsDate)&1)) writeEEPROM(7,(((fnsOn>>fnIsAlarm)&1)?fnIsAlarm:fnIsTime),false); break;
189-
case fnIsAlarm: if(!((fnsOn>>fnIsAlarm)&1)) writeEEPROM(7,fnIsTime,false); break;
190-
case fnIsTimer: if(!((fnsOn>>fnIsTimer)&1)) writeEEPROM(7,(((fnsOn>>fnIsAlarm)&1)?fnIsAlarm:fnIsTime),false); break;
191-
case fnIsTemp: if(!((fnsOn>>fnIsTemp)&1)) writeEEPROM(7,(((fnsOn>>fnIsAlarm)&1)?fnIsAlarm:fnIsTime),false); break;
192-
case fnIsTubeTester: if(!((fnsOn>>fnIsTubeTester)&1)) writeEEPROM(7,(((fnsOn>>fnIsAlarm)&1)?fnIsAlarm:fnIsTime),false); break;
183+
case fnIsDate: if(!enableDate) writeEEPROM(7,(enableAlarm?fnIsAlarm:fnIsTime),false); break;
184+
case fnIsAlarm: if(!enableAlarm) writeEEPROM(7,fnIsTime,false); break;
185+
case fnIsTimer: if(!enableTimer) writeEEPROM(7,(enableAlarm?fnIsAlarm:fnIsTime),false); break;
186+
case fnIsTemp: if(!enableTemp) writeEEPROM(7,(enableAlarm?fnIsAlarm:fnIsTime),false); break;
187+
case fnIsTest: if(!enableTest) writeEEPROM(7,(enableAlarm?fnIsAlarm:fnIsTime),false); break;
188+
default: writeEEPROM(7,(enableAlarm?fnIsAlarm:fnIsTime),false); break;
193189
}
194190
if(!enableAlarmAutoskip) writeEEPROM(23,0,false); //alarm autoskip off
195191
if(!enableAlarmFibonacci) writeEEPROM(50,0,false); //fibonacci off
196192
if(!enableChime) writeEEPROM(21,0,false); //chime off
197193
if(!enableNightShutoff) writeEEPROM(27,0,false); //night shutoff off
198194
if(!enableAwayShutoff) writeEEPROM(32,0,false); //away shutoff off
199-
//TODO if fnAlarm is not enabled, force alarm off, else
200-
201195
dstOn = (readEEPROM(15,false)>0); //set last known DST state per EEPROM backup
202196
//if LED circuit is not switched (v5.0 board), the LED menu setting (eeprom 26) doesn't matter
203197
findFnAndPageNumbers(); //initial values
@@ -380,7 +374,7 @@ void ctrlEvt(byte ctrl, byte evt){
380374
startSet(timerInitialMins,0,5999,1); break; //minutes
381375
//fnIsDayCount removed in favor of paginated calendar
382376
case fnIsTemp: //could do calibration here if so inclined
383-
case fnIsTubeTester:
377+
case fnIsTest:
384378
default: break;
385379
}
386380
return;
@@ -609,11 +603,27 @@ void ctrlEvt(byte ctrl, byte evt){
609603

610604
void fnScroll(byte dir){
611605
//0=down, 1=up
612-
//Switch to the next (up) or previous (down) fn in fnsEnabled
613-
byte pos;
614-
byte posLast = sizeof(fnsEnabled)-1;
615-
if(dir==1) for(pos=0; pos<=posLast; pos++) if(fnsEnabled[pos]==fn) { fn = (pos==posLast?0:fnsEnabled[pos+1]); break; }
616-
if(dir==0) for(pos=posLast; pos>=0; pos--) if(fnsEnabled[pos]==fn) { fn = (pos==0?posLast:fnsEnabled[pos-1]); break; }
606+
//Switch to the next (up) or previous (down) enabled function. This determines the order.
607+
//We'll use switch blocks *without* breaks to cascade to the next enabled function
608+
if(dir) { // up
609+
switch(fn) {
610+
case fnIsTime: if(enableDate) { fn = fnIsDate; break; }
611+
case fnIsDate: if(enableAlarm) { fn = fnIsAlarm; break; }
612+
case fnIsAlarm: if(enableTimer) { fn = fnIsTimer; break; }
613+
case fnIsTimer: if(enableTemp) { fn = fnIsTemp; break; }
614+
case fnIsTemp: if(enableTest) { fn = fnIsTest; break; }
615+
case fnIsTest: default: fn = fnIsTime; break;
616+
}
617+
} else { // down
618+
switch(fn) {
619+
case fnIsTime: if(enableTest) { fn = fnIsTest; break; }
620+
case fnIsTest: if(enableTemp) { fn = fnIsTemp; break; }
621+
case fnIsTemp: if(enableTimer) { fn = fnIsTimer; break; }
622+
case fnIsTimer: if(enableAlarm) { fn = fnIsAlarm; break; }
623+
case fnIsAlarm: if(enableDate) { fn = fnIsDate; break; }
624+
case fnIsDate: default: fn = fnIsTime; break;
625+
}
626+
}
617627
}
618628
void fnOptScroll(byte dir){
619629
//0=down, 1=up
@@ -632,18 +642,18 @@ void fnOptScroll(byte dir){
632642
|| ((ledPin<0) && (optLoc==26)) //no led pin: no led control
633643
|| ((ledPin<0) && (optLoc==26)) //no led pin: no led control
634644
//Functions disabled
635-
|| (!((fnsOn>>fnIsDate)&1) && (optLoc==17||optLoc==18||optLoc==10||optLoc==12||optLoc==14)) //date fn disabled in config: skip date and geography options
636-
|| (!((fnsOn>>fnIsAlarm)&1) && (optLoc==23||optLoc==42||optLoc==39||optLoc==47||optLoc==24||optLoc==50)) //alarm fn disabled in config: skip alarm options
637-
|| (!((fnsOn>>fnIsTimer)&1) && (optLoc==43||optLoc==40||optLoc==48)) //timer fn disabled in config: skip timer options
638-
|| (!((fnsOn>>fnIsTemp)&1) && (optLoc==45)) //temp fn disabled in config: skip temp format TODO good for weather also
645+
|| (!enableDate && (optLoc==17||optLoc==18||optLoc==10||optLoc==12||optLoc==14)) //date fn disabled in config: skip date and geography options
646+
|| (!enableAlarm && (optLoc==23||optLoc==42||optLoc==39||optLoc==47||optLoc==24||optLoc==50)) //alarm fn disabled in config: skip alarm options
647+
|| (!enableTimer && (optLoc==43||optLoc==40||optLoc==48)) //timer fn disabled in config: skip timer options
648+
|| (!enableTemp && (optLoc==45)) //temp fn disabled in config: skip temp format TODO good for weather also
639649
//Other functionality disabled
640650
|| (!enableDateSunriseSunset && (optLoc==10||optLoc==12||optLoc==14)) //date rise/set disabled in config: skip geography
641651
|| (!enableAlarmAutoskip && (optLoc==23)) //alarm autoskip disabled in config: skip autoskip switch
642652
|| (!enableAlarmFibonacci && (optLoc==50)) //fibonacci mode disabled in config: skip fibonacci switch
643653
|| (!enableChime && (optLoc==21||optLoc==44||optLoc==41||optLoc==49)) //chime disabled in config: skip chime
644654
|| (!enableNightShutoff && (optLoc==27||optLoc==28||optLoc==30)) //night shutoff disabled in config: skip night
645655
|| ((!enableNightShutoff || !enableAwayShutoff) && (optLoc==32||optLoc==35||optLoc==37)) //night or away shutoff disabled in config: skip away (except workweek)
646-
|| ((!enableNightShutoff || !enableAwayShutoff) && (!enableAlarmAutoskip || !((fnsOn>>fnIsAlarm)&1)) && (optLoc==33||optLoc==34)) //(night or away) and alarm autoskip disabled: skip workweek
656+
|| ((!enableNightShutoff || !enableAwayShutoff) && (!enableAlarmAutoskip || !enableAlarm) && (optLoc==33||optLoc==34)) //(night or away) and alarm autoskip disabled: skip workweek
647657
) {
648658
fnOptScroll(dir);
649659
}
@@ -741,7 +751,8 @@ void clearSet(){ //Exit set state
741751
//EEPROM values are exclusively bytes (0-255) or words (unsigned ints, 0-65535)
742752
//If it's a word, high byte is in loc, low byte is in loc+1
743753
void initEEPROM(bool hard){
744-
//Set EEPROM and clock to defaults
754+
//If hard, set EEPROM and clock to defaults
755+
//Otherwise, just make sure stuff is in range
745756
//First prevent the held button from doing anything else
746757
btnCur = mainSel; btnStop();
747758
//If a hard init, set the clock
@@ -755,14 +766,12 @@ void initEEPROM(bool hard){
755766
ds3231.setSecond(0);
756767
}
757768
if(hard || readEEPROM(0,true)>1439) writeEEPROM(0,420,true); //0-1: alarm at 7am
758-
if(hard){ alarmOn = !enableSoftAlarmSwitch; writeEEPROM(2,alarmOn,false); } //2: alarm is off, or on if no software switch
759-
//3 is free
769+
//2: alarm on, handled by init
770+
//3: free
760771
if(hard || readEEPROM(4,false)<0 || readEEPROM(4,false)>1) writeEEPROM(4,1,false); //4: day counter direction: count up...
761772
if(hard || readEEPROM(5,false)<1 || readEEPROM(5,false)>12) writeEEPROM(5,12,false); //5: ...December...
762773
if(hard || readEEPROM(6,false)<1 || readEEPROM(6,false)>31) writeEEPROM(6,31,false); //6: ...31st. (This gives the day of the year)
763-
bool foundAltFn = false;
764-
for(byte fni=0; fni<sizeof(fnsEnabled); fni++) { if(fnsEnabled[fni]==readEEPROM(7,false)) { foundAltFn = true; break; }}
765-
if(hard || !foundAltFn) writeEEPROM(7,0,false); //7: Alt function preset – make sure it is not set to a function that isn't enabled in this clock
774+
if(hard) writeEEPROM(7,0,false); //7: Alt function preset
766775
//8: TODO functions/pages enabled (bitmask)
767776
//9: free
768777
//15: DST on flag (will be set at first RTC check)
@@ -1474,7 +1483,7 @@ void updateDisplay(){
14741483
editDisplay(abs(temp)/100,1,3,(temp<0?true:false),true); //leading zeros if negative
14751484
editDisplay(abs(temp)%100,4,5,true,true);
14761485
break;
1477-
case fnIsTubeTester:
1486+
case fnIsTest:
14781487
editDisplay(tod.second(),0,0,true,false);
14791488
editDisplay(tod.second(),1,1,true,false);
14801489
editDisplay(tod.second(),2,2,true,false);

arduino-nixie/configs/v5-4tube.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
const byte displaySize = 4; //number of tubes in display module. Small display adjustments are made for 4-tube clocks
44

5-
// available clock functions, and unique IDs (between 0 and 200)
6-
const byte fnIsTime = 0;
7-
const byte fnIsDate = 1;
8-
const byte fnIsAlarm = 2;
9-
const byte fnIsTimer = 3;
10-
const byte fnIsTemp = 4;
11-
const byte fnIsTubeTester = 5; //cycles all digits on all tubes 1/second, similar to anti-cathode-poisoning cleaner
12-
// functions enabled in this clock, in their display order. Only fnIsTime is required
13-
const byte fnsEnabled[] = {fnIsTime, fnIsDate, fnIsAlarm, fnIsTimer}; //, fnIsTemp, fnIsTubeTester
14-
// To control which of these display persistently vs. switch back to Time after a few seconds, search "Temporary-display function timeout"
5+
// Which functionality is enabled in this clock?
6+
// Related options will also be enabled in the options menu.
7+
const bool enableDate = true;
8+
const bool enableDateCounter = true; // Adds a "page" to the date with an anniversary counter
9+
const bool enableDateSunriseSunset = true; // Adds "pages" to the date with sunrise/sunset times
10+
const bool enableAlarm = true;
11+
const bool enableAlarmAutoskip = true;
12+
const bool enableAlarmFibonacci = true;
13+
const bool enableTimer = true;
14+
const bool enableChime = true;
15+
const bool enableNightShutoff = true; // If disabled, tubes will be full brightness all the time.
16+
const bool enableAwayShutoff = true; // Requires night shutoff.
17+
const bool enableTemp = false; //Temperature per DS3231 - will read high – leave false for production
18+
const bool enableTest = false; //Cycles through all tubes – leave false for production
1519

1620
// These are the UNDB v5 board connections to Arduino analog input pins.
1721
// S1/PL13 = Reset

arduino-nixie/configs/v5-6tube.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
const byte displaySize = 6; //number of tubes in display module. Small display adjustments are made for 4-tube clocks
44

5-
// available clock functions, and unique IDs (between 0 and 200)
6-
const byte fnIsTime = 0;
7-
const byte fnIsDate = 1;
8-
const byte fnIsAlarm = 2;
9-
const byte fnIsTimer = 3;
10-
const byte fnIsTemp = 5;
11-
const byte fnIsTubeTester = 6; //cycles all digits on all tubes 1/second, similar to anti-cathode-poisoning cleaner
12-
// functions enabled in this clock, in their display order. Only fnIsTime is required
13-
const byte fnsEnabled[] = {fnIsTime, fnIsDate, fnIsAlarm, fnIsTimer}; //, fnIsTemp, fnIsTubeTester
14-
// To control which of these display persistently vs. switch back to Time after a few seconds, search "Temporary-display function timeout"
5+
// Which functionality is enabled in this clock?
6+
// Related options will also be enabled in the options menu.
7+
const bool enableDate = true;
8+
const bool enableDateCounter = true; // Adds a "page" to the date with an anniversary counter
9+
const bool enableDateSunriseSunset = true; // Adds "pages" to the date with sunrise/sunset times
10+
const bool enableAlarm = true;
11+
const bool enableAlarmAutoskip = true;
12+
const bool enableAlarmFibonacci = true;
13+
const bool enableTimer = true;
14+
const bool enableChime = true;
15+
const bool enableNightShutoff = true; // If disabled, tubes will be full brightness all the time.
16+
const bool enableAwayShutoff = true; // Requires night shutoff.
17+
const bool enableTemp = false; //Temperature per DS3231 - will read high – leave false for production
18+
const bool enableTest = false; //Cycles through all tubes – leave false for production
1519

1620
// These are the UNDB v5 board connections to Arduino analog input pins.
1721
// S1/PL13 = Reset

arduino-nixie/configs/v8-4tube.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
const byte displaySize = 4; //number of tubes in display module. Small display adjustments are made for 4-tube clocks
44

5-
// available clock functions, and unique IDs (between 0 and 200)
6-
const byte fnIsTime = 0;
7-
const byte fnIsDate = 1;
8-
const byte fnIsAlarm = 2;
9-
const byte fnIsTimer = 3;
10-
const byte fnIsTemp = 4;
11-
const byte fnIsTubeTester = 5; //cycles all digits on all tubes 1/second, similar to anti-cathode-poisoning cleaner
12-
// functions enabled in this clock, in their display order. Only fnIsTime is required
13-
const byte fnsEnabled[] = {fnIsTime, fnIsDate, fnIsAlarm, fnIsTimer}; //, fnIsTemp, fnIsTubeTester
14-
// To control which of these display persistently vs. switch back to Time after a few seconds, search "Temporary-display function timeout"
5+
// Which functionality is enabled in this clock?
6+
// Related options will also be enabled in the options menu.
7+
const bool enableDate = true;
8+
const bool enableDateCounter = true; // Adds a "page" to the date with an anniversary counter
9+
const bool enableDateSunriseSunset = true; // Adds "pages" to the date with sunrise/sunset times
10+
const bool enableAlarm = true;
11+
const bool enableAlarmAutoskip = true;
12+
const bool enableAlarmFibonacci = true;
13+
const bool enableTimer = true;
14+
const bool enableChime = true;
15+
const bool enableNightShutoff = true; // If disabled, tubes will be full brightness all the time.
16+
const bool enableAwayShutoff = true; // Requires night shutoff.
17+
const bool enableTemp = false; //Temperature per DS3231 - will read high – leave false for production
18+
const bool enableTest = false; //Cycles through all tubes – leave false for production
1519

1620
// These are the RLB board connections to Arduino analog input pins.
1721
// S1/PL13 = Reset

arduino-nixie/configs/v8-6tube.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22

33
const byte displaySize = 6; //number of tubes in display module. Small display adjustments are made for 4-tube clocks
44

5-
// available clock functions (and unique IDs between 0 and 7)
6-
const byte fnIsTime = 0; //time of day
7-
const byte fnIsDate = 1; //date, with optional day counter and sunrise/sunset (per below)
8-
const byte fnIsAlarm = 2; //alarm time
9-
const byte fnIsTimer = 3; //countdown timer and chronograph
10-
const byte fnIsTemp = 4; //temperature per DS3231 – will likely read high
11-
const byte fnIsTubeTester = 5; //simply cycles all tubes
12-
13-
// Which functions are enabled in this clock, and in what order? (fnIsTime is required)
14-
const byte fnsEnabled[] = {fnIsTime, fnIsDate, fnIsAlarm, fnIsTimer};
15-
16-
// Additional functionality
5+
// Which functionality is enabled in this clock?
6+
// Related options will also be enabled in the options menu.
7+
const bool enableDate = true;
178
const bool enableDateCounter = true; // Adds a "page" to the date with an anniversary counter
189
const bool enableDateSunriseSunset = true; // Adds "pages" to the date with sunrise/sunset times
10+
const bool enableAlarm = true;
1911
const bool enableAlarmAutoskip = true;
2012
const bool enableAlarmFibonacci = true;
13+
const bool enableTimer = true;
2114
const bool enableChime = true;
2215
const bool enableNightShutoff = true; // If disabled, tubes will be full brightness all the time.
2316
const bool enableAwayShutoff = true; // Requires night shutoff.
17+
const bool enableTemp = false; //Temperature per DS3231 - will read high – leave false for production
18+
const bool enableTest = false; //Cycles through all tubes – leave false for production
2419

2520
// These are the RLB board connections to Arduino analog input pins.
2621
// S1/PL13 = Reset

0 commit comments

Comments
 (0)