Skip to content

Commit be82657

Browse files
committed
WIP input support for verylong/superlong (not working)
1 parent c831b15 commit be82657

File tree

11 files changed

+134
-107
lines changed

11 files changed

+134
-107
lines changed

INSTRUCTIONS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Operating instructions, v2.0+
22

3+
> [Instructions for earlier versions are here.](https://github.com/clockspot/arduino-clock/releases) To see your clock’s software version, hold **Select** briefly while powering up the clock.
4+
35
Your clock has four main functions: [time of day](#time-of-day), [calendar](#calendar), [alarm](#alarm), and [chrono/timer](#chronotimer). To cycle through these functions, press **Select**.
46

57
To set anything, simply hold **Select** until the display blinks; use **Up/Down** to set, and **Select** to save.

arduino-nixie/arduino-nixie.ino

Lines changed: 90 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ const byte millisCorrectionInterval = 30; //used to calibrate millis() to RTC fo
136136
unsigned long millisAtLastCheck = 0;
137137
word unoffRemain = 0; //un-off (briefly turn on tubes during full night/away shutoff) timeout counter, seconds
138138
byte displayDim = 2; //dim per display or function: 2=normal, 1=dim, 0=off
139-
140-
byte versionRemain = 0; //display version at start //TODO with button held at start, long hold reset
139+
bool versionShowing = false; //display version if Select held at start - until it is released or long-held
141140

142141
//If we need to temporarily display a value (or values in series), we can put them here. Can't be zero.
143142
//This is used by network to display IP addresses, and various other bits.
@@ -152,7 +151,7 @@ int daysInYear(word y); //used by network
152151
byte daysInMonth(word y, byte m); //used by network, rtcMillis
153152
bool isDSTByHour(int y, byte m, byte d, byte h, bool setFlag); //used by network
154153
void calcSun(); //used by rtc
155-
void ctrlEvt(byte ctrl, byte evt); //used by input
154+
void ctrlEvt(byte ctrl, byte evt, byte evtLast); //used by input
156155
void updateDisplay(); //used by network
157156
void goToFn(byte thefn); //used by network
158157
int dateComp(int y, byte m, byte d, byte mt, byte dt, bool countUp); //used by network
@@ -191,15 +190,25 @@ void quickBeep(int pitch); //used by network (alarm switch change)
191190
////////// Main code control //////////
192191

193192
void setup(){
194-
// Serial.begin(9600);
195-
// #ifndef __AVR__ //SAMD only
196-
// while(!Serial);
197-
// #endif
198-
rtcInit(); //TODO change nomenclature to match
193+
Serial.begin(9600);
194+
#ifndef __AVR__ //SAMD only
195+
while(!Serial);
196+
#endif
197+
rtcInit();
198+
initStorage(); //pulls persistent storage data into volatile vars - see storage.cpp
199+
initEEPROM(false); //do a soft init to make sure vals in range
199200
initInputs();
201+
initDisplay();
202+
initOutputs(); //depends on some EEPROM settings
200203
delay(100); //prevents the below from firing in the event there's a capacitor stabilizing the input, which can read low falsely
201-
initStorage(); //pulls persistent storage data into volatile vars - see storage.cpp
202-
initEEPROM(checkForHeldButtonAtStartup()); //Do a hard init of EEPROM if button is held; else do a soft init to make sure vals in range
204+
if(readBtn(CTRL_SEL)){ //if Sel is held at startup, show version, and skip init network for now (since wifi connect hangs)
205+
versionShowing = 1; inputCur = CTRL_SEL;
206+
} else {
207+
#ifdef NETWORK_SUPPORTED
208+
initNetwork();
209+
#endif
210+
}
211+
203212
//Some settings need to be set to a fixed value per the configuration.
204213
//These settings will also be skipped in fnOptScroll so the user can't change them.
205214

@@ -238,11 +247,6 @@ void setup(){
238247
if(!ENABLE_SHUTOFF_AWAY) writeEEPROM(32,0,false); //away shutoff off
239248
//if backlight circuit is not switched (v5.0 board), the backlight menu setting (eeprom 26) doesn't matter
240249
findFnAndPageNumbers(); //initial values
241-
initDisplay();
242-
#ifdef NETWORK_SUPPORTED
243-
initNetwork();
244-
#endif
245-
initOutputs(); //depends on some EEPROM settings
246250
}
247251

248252
void loop(){
@@ -264,12 +268,26 @@ void loop(){
264268

265269
////////// Input handling and value setting //////////
266270

267-
void ctrlEvt(byte ctrl, byte evt){
271+
void ctrlEvt(byte ctrl, byte evt, byte evtLast){
268272
//Handle control events from inputs, based on current fn and set state.
269-
//evt: 1=press, 2=short hold, 3=long hold, 0=release.
273+
//evt: 1=press, 2=short hold, 3=long hold, 4=verylong, 5=superlong, 0=release.
270274
//We only handle press evts for up/down ctrls, as that's the only evt encoders generate,
271275
//and input.cpp sends repeated presses if up/down buttons are held.
272276
//But for sel/alt (always buttons), we can handle different hold states here.
277+
if(evt==1 && ctrl==CTRL_ALT){
278+
Serial.println(F("alt press"));
279+
}
280+
281+
//If the version display is showing, ignore all else until Sel is released (cancel) or long-held (cancel and eeprom reset)
282+
if(versionShowing){
283+
if(ctrl==CTRL_SEL && (evt==0 || evt==5)){ //SEL release or superlong hold
284+
if(evt==5) initEEPROM(true); //superlong hold: reset EEPROM
285+
versionShowing = false; inputStop(); updateDisplay();
286+
#ifdef NETWORK_SUPPORTED
287+
initNetwork(); //we didn't do this earlier since the wifi connect makes the clock hang
288+
#endif
289+
} else return; //ignore other controls
290+
} //end if versionShowing
273291

274292
//If the signal is going, any press should silence it
275293
if(signalRemain>0 && evt==1){
@@ -315,13 +333,6 @@ void ctrlEvt(byte ctrl, byte evt){
315333
// checkEffects(true);
316334
// return;
317335
// }
318-
//If the version display is going, any press should cancel it, with a display update
319-
if(versionRemain>0 && evt==1){
320-
versionRemain = 0;
321-
inputStop();
322-
updateDisplay();
323-
return;
324-
}
325336

326337
//Is it a press for an un-off?
327338
unoffRemain = UNOFF_DUR; //always do this so continued button presses during an unoff keep it alive
@@ -331,12 +342,27 @@ void ctrlEvt(byte ctrl, byte evt){
331342
return;
332343
}
333344

345+
//#ifdef NETWORK_SUPPORTED
346+
//Short hold, Alt; or very long hold, Sel if no Alt: start admin
347+
if((evt==2 && ctrl==CTRL_ALT)||(evt==4 && ctrl==CTRL_SEL && CTRL_ALT<0)) {
348+
inputStop();
349+
//networkStartAdmin();
350+
Serial.println(F("networkStartAdmin would happen here"));
351+
return;
352+
}
353+
//Super long hold, Alt, or Sel if no Alt: start AP (TODO would we rather it forget wifi?)
354+
if(evt==5 && (ctrl==CTRL_ALT || (ctrl==CTRL_SEL && CTRL_ALT<0))) {
355+
inputStop();
356+
//networkStartAP();
357+
Serial.println(F("networkStartAP would happen here"));
358+
return;
359+
}
360+
//#endif
361+
334362
if(fn < fnOpts) { //normal fn running/setting (not in settings menu)
335363

336-
//TODO support evt==4 and evt==5 by removing inputStop() from eg evt==3 without clashing
337-
338364
if(evt==3 && ctrl==CTRL_SEL) { //CTRL_SEL long hold: enter settings menu
339-
inputStop();
365+
//inputStop(); to enable evt==4 and evt==5 per above
340366
fn = fnOpts;
341367
clearSet(); //don't need updateDisplay() here because this calls updateRTC with force=true
342368
return;
@@ -384,7 +410,7 @@ void ctrlEvt(byte ctrl, byte evt){
384410
if(!(timerState&1)){ //stopped
385411
timerStart();
386412
} else { //running
387-
#if CTRL_UPDN_TYPE==2 //rotary encoder
413+
#ifdef INPUT_UPDN_ROTARY
388414
if((timerState>>1)&1) timerLap(); //chrono: lap
389415
else timerRunoutToggle(); //timer: runout option
390416
#else //button
@@ -393,7 +419,7 @@ void ctrlEvt(byte ctrl, byte evt){
393419
}
394420
} else { //CTRL_DN
395421
if(!(timerState&1)){ //stopped
396-
#if CTRL_UPDN_TYPE==1 //buttons
422+
#ifdef INPUT_UPDN_BUTTONS
397423
timerClear();
398424
//if we wanted to reset to the previous time, we could use this; but sel hold is easy enough to get there
399425
// //same as //save timer secs
@@ -405,7 +431,7 @@ void ctrlEvt(byte ctrl, byte evt){
405431
updateDisplay();
406432
#endif
407433
} else { //running
408-
#if CTRL_UPDN_TYPE==2 //rotary encoder
434+
#ifdef INPUT_UPDN_ROTARY
409435
timerStop();
410436
#else
411437
if((timerState>>1)&1) timerLap(); //chrono: lap
@@ -418,44 +444,36 @@ void ctrlEvt(byte ctrl, byte evt){
418444
}
419445
//else do nothing
420446
} //end sel release or adj press
421-
else if(CTRL_ALT>0 && ctrl==CTRL_ALT) { //alt sel press
422-
#ifdef NETWORK_SUPPORTED
423-
if(evt==3){
424-
//Forget wifi? remove inputStop() from below
425-
}
426-
if(evt==2){
427-
inputStop();
428-
networkStartAdmin();
429-
}
430-
#else
431-
//if switch signal, and soft switch enabled, we'll switch power.
432-
if(ENABLE_SOFT_POWER_SWITCH && SWITCH_PIN>=0) { switchPower(2); inputStop(); }
433-
//Otherwise, this becomes our function preset.
434-
else {
435-
//On long hold, if this is not currently the preset, we'll set it, double beep, and inputStop.
436-
//(Decided not to let this button set things, because then it steps on the toes of Sel's functionality.)
437-
if(evt==2) {
438-
if(readEEPROM(7,false)!=fn) {
439-
inputStop();
440-
writeEEPROM(7,fn,false);
441-
quickBeep(76);
442-
displayBlink();
443-
}
444-
}
445-
//On short release, jump to the preset fn.
446-
else if(evt==0) {
447-
inputStop();
448-
if(fn!=readEEPROM(7,false)) fn=readEEPROM(7,false);
449-
else {
450-
//Special case: if this is the alarm, toggle the alarm switch
451-
if(fn==fnIsAlarm) switchAlarm(2);
452-
}
453-
fnPg = 0; //reset page counter in case we were in a paged display
454-
updateDisplay();
455-
}
456-
}
457-
#endif
458-
}
447+
else if(CTRL_ALT>0 && ctrl==CTRL_ALT) {
448+
//if switch signal, and soft switch enabled, we'll switch power on release.
449+
if(ENABLE_SOFT_POWER_SWITCH && SWITCH_PIN>=0) { if(evt==0){ switchPower(2); inputStop(); } }
450+
// #ifndef NETWORK_SUPPORTED
451+
// //Otherwise - if holds aren't used for network stuff above - this becomes our function preset.
452+
// else {
453+
// //On long hold, if this is not currently the preset, we'll set it, double beep, and inputStop.
454+
// //(Decided not to let this button set things, because then it steps on the toes of Sel's functionality.)
455+
// if(evt==2) {
456+
// if(readEEPROM(7,false)!=fn) {
457+
// inputStop();
458+
// writeEEPROM(7,fn,false);
459+
// quickBeep(76);
460+
// displayBlink();
461+
// }
462+
// }
463+
// //On short release, jump to the preset fn.
464+
// else if(evt==0) {
465+
// inputStop();
466+
// if(fn!=readEEPROM(7,false)) fn=readEEPROM(7,false);
467+
// else {
468+
// //Special case: if this is the alarm, toggle the alarm switch
469+
// if(fn==fnIsAlarm) switchAlarm(2);
470+
// }
471+
// fnPg = 0; //reset page counter in case we were in a paged display
472+
// updateDisplay();
473+
// }
474+
// }
475+
// #endif
476+
} //end alt
459477
} //end fn running
460478

461479
else { //fn setting
@@ -464,6 +482,7 @@ void ctrlEvt(byte ctrl, byte evt){
464482
//currently no, because we don't inputStop() when short hold goes into fn setting, in case long hold may go to settings menu
465483
//so we can't handle a release because it would immediately save if releasing from the short hold.
466484
//Consider recording the input start time when going into fn setting so we can distinguish its release from a future one
485+
//TODO the above can be revisited now that we pass evtLast
467486
if(ctrl==CTRL_SEL) { //CTRL_SEL push: go to next setting or save and exit setting mode
468487
inputStop(); //not waiting for CTRL_SELHold, so can stop listening here
469488
//We will set rtc time parts directly
@@ -577,7 +596,7 @@ void ctrlEvt(byte ctrl, byte evt){
577596
}
578597

579598
if(!fnSetPg){ //setting number
580-
if(ctrl==CTRL_SEL && evt==0) { //CTRL_SEL release: enter setting value
599+
if(ctrl==CTRL_SEL && evt==0 && evtLast<3) { //CTRL_SEL release (but not after holding to get into the menu): enter setting value
581600
startSet(readEEPROM(optsLoc[opt],optsMax[opt]>255?true:false),optsMin[opt],optsMax[opt],1);
582601
}
583602
if(ctrl==CTRL_UP && evt==1) fnOptScroll(1); //next one up or cycle to beginning
@@ -889,9 +908,6 @@ void checkRTC(bool force){
889908
if(unoffRemain>0) {
890909
unoffRemain--; //updateDisplay will naturally put it back to off state if applicable
891910
}
892-
if(versionRemain>0) {
893-
versionRemain--;
894-
}
895911
} //end natural second
896912

897913
//Things to do at specific times
@@ -926,7 +942,7 @@ void checkRTC(bool force){
926942
} //end alarm trigger
927943
}
928944
//At bottom of minute, see if we should show the date
929-
if(rtcGetSecond()==30 && fn==fnIsTime && fnSetPg==0 && unoffRemain==0 && versionRemain==0) { /*cleanRemain==0 && scrollRemain==0 && */
945+
if(rtcGetSecond()==30 && fn==fnIsTime && fnSetPg==0 && unoffRemain==0 && versionShowing==false) { /*cleanRemain==0 && scrollRemain==0 && */
930946
if(readEEPROM(18,false)>=2) { goToFn(fnIsDate); fnPg = 254; updateDisplay(); }
931947
//if(readEEPROM(18,false)==3) { startScroll(); }
932948
}
@@ -1351,7 +1367,7 @@ void updateDisplay(){
13511367
// }
13521368
// } //todo move cleanRemain, scrollRemain to dispNixie
13531369
// else
1354-
if(versionRemain>0) {
1370+
if(versionShowing) {
13551371
editDisplay(vMajor, 0, 1, false, false);
13561372
editDisplay(vMinor, 2, 3, false, false);
13571373
editDisplay(vPatch, 4, 5, false, false);

arduino-nixie/configs/led-iot.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
///// Functionality /////
88

99
// Which functionality is enabled in this clock?
10-
// Related options will also be enabled in the options menu.
10+
// Related settings will also be enabled in the settings menu.
1111
// The operating instructions assume all of these are enabled except temp and tubetest.
1212
#define ENABLE_DATE_FN true // Date function, optionally including pages below
1313
#define ENABLE_DATE_COUNTER true // Adds date page with an anniversary counter
@@ -42,9 +42,9 @@
4242
//For all input types:
4343
//How long (in ms) are the hold durations?
4444
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
45-
#define CTRL_HOLD_LONG_DUR 3000 //for entering options menu, or hold-setting at high velocity (x10)
46-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
47-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
45+
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
46+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
47+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
4848
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
4949
#define SETTING_TIMEOUT 300 //sec
5050
#define FN_TEMP_TIMEOUT 5 //sec
@@ -91,7 +91,7 @@
9191
// 1 = yes. Alarm can be switched on and off when clock is displaying the alarm time (fnIsAlarm).
9292
// 0 = no. Alarm will be permanently on. Use with switch signal if the appliance has its own switch on this circuit (and note that, if another signal type(s) is available and selected for the alarm, the user won't be able to switch it off). Also disables skip feature. Note that the instructions do not reflect this option.
9393
#define ENABLE_SOFT_POWER_SWITCH 1 //switch signal only
94-
// 1 = yes. Switch signal can be toggled on and off directly with Alt button at any time (except in options menu). This is useful if connecting an appliance (e.g. radio) that doesn't have its own switch, or if replacing the clock unit in a clock radio where the clock does all the switching (e.g. Telechron).
94+
// 1 = yes. Switch signal can be toggled on and off directly with Alt button at any time (except in settings menu). This is useful if connecting an appliance (e.g. radio) that doesn't have its own switch, or if replacing the clock unit in a clock radio where the clock does all the switching (e.g. Telechron).
9595
// 0 = no. Use if the connected appliance has its own power switch (independent of this circuit, e.g. some Sony Digimatic clock radios) or does not need to be manually switched. In this case (and/or if there is no switch signal option, and if no Wi-Fi support) Alt will act as a function preset. Note that the instructions do not reflect this option.
9696

9797
//Backlighting control

arduino-nixie/configs/undb-v5.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
//How long (in ms) are the hold durations?
4747
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
4848
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
49-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
50-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
49+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
50+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
5151
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
5252
#define SETTING_TIMEOUT 300 //sec
5353
#define FN_TEMP_TIMEOUT 5 //sec

arduino-nixie/configs/undb-v8-simplified.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
//How long (in ms) are the hold durations?
5151
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
5252
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
53-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
54-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
53+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
54+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
5555
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
5656
#define SETTING_TIMEOUT 300 //sec
5757
#define FN_TEMP_TIMEOUT 5 //sec

arduino-nixie/configs/undb-v8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
//How long (in ms) are the hold durations?
5151
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
5252
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
53-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
54-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
53+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
54+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
5555
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
5656
#define SETTING_TIMEOUT 300 //sec
5757
#define FN_TEMP_TIMEOUT 5 //sec

arduino-nixie/configs/undb-v9-relay.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//How long (in ms) are the hold durations?
5252
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
5353
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
54-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
55-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
54+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
55+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
5656
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
5757
#define SETTING_TIMEOUT 300 //sec
5858
#define FN_TEMP_TIMEOUT 5 //sec

arduino-nixie/configs/undb-v9-simplified.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//How long (in ms) are the hold durations?
5252
#define CTRL_HOLD_SHORT_DUR 1000 //for entering setting mode, or hold-setting at low velocity (x1)
5353
#define CTRL_HOLD_LONG_DUR 3000 //for entering settings menu, or hold-setting at high velocity (x10)
54-
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi IP info / admin start (Nano IoT only)
55-
#define CTRL_HOLD_SUPERLONG_DUR 15000 //for wifi forget (Nano IoT only)
54+
#define CTRL_HOLD_VERYLONG_DUR 5000 //for wifi info / admin start (Nano IoT without Alt only)
55+
#define CTRL_HOLD_SUPERLONG_DUR 10000 //for wifi disconnect (Nano IoT) or EEPROM reset on startup
5656
//What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
5757
#define SETTING_TIMEOUT 300 //sec
5858
#define FN_TEMP_TIMEOUT 5 //sec

0 commit comments

Comments
 (0)