@@ -136,8 +136,7 @@ const byte millisCorrectionInterval = 30; //used to calibrate millis() to RTC fo
136
136
unsigned long millisAtLastCheck = 0 ;
137
137
word unoffRemain = 0 ; // un-off (briefly turn on tubes during full night/away shutoff) timeout counter, seconds
138
138
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
141
140
142
141
// If we need to temporarily display a value (or values in series), we can put them here. Can't be zero.
143
142
// This is used by network to display IP addresses, and various other bits.
@@ -152,7 +151,7 @@ int daysInYear(word y); //used by network
152
151
byte daysInMonth (word y, byte m); // used by network, rtcMillis
153
152
bool isDSTByHour (int y, byte m, byte d, byte h, bool setFlag); // used by network
154
153
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
156
155
void updateDisplay (); // used by network
157
156
void goToFn (byte thefn); // used by network
158
157
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)
191
190
// //////// Main code control //////////
192
191
193
192
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
199
200
initInputs ();
201
+ initDisplay ();
202
+ initOutputs (); // depends on some EEPROM settings
200
203
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
+
203
212
// Some settings need to be set to a fixed value per the configuration.
204
213
// These settings will also be skipped in fnOptScroll so the user can't change them.
205
214
@@ -238,11 +247,6 @@ void setup(){
238
247
if (!ENABLE_SHUTOFF_AWAY) writeEEPROM (32 ,0 ,false ); // away shutoff off
239
248
// if backlight circuit is not switched (v5.0 board), the backlight menu setting (eeprom 26) doesn't matter
240
249
findFnAndPageNumbers (); // initial values
241
- initDisplay ();
242
- #ifdef NETWORK_SUPPORTED
243
- initNetwork ();
244
- #endif
245
- initOutputs (); // depends on some EEPROM settings
246
250
}
247
251
248
252
void loop (){
@@ -264,12 +268,26 @@ void loop(){
264
268
265
269
// //////// Input handling and value setting //////////
266
270
267
- void ctrlEvt (byte ctrl, byte evt){
271
+ void ctrlEvt (byte ctrl, byte evt, byte evtLast ){
268
272
// 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.
270
274
// We only handle press evts for up/down ctrls, as that's the only evt encoders generate,
271
275
// and input.cpp sends repeated presses if up/down buttons are held.
272
276
// 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
273
291
274
292
// If the signal is going, any press should silence it
275
293
if (signalRemain>0 && evt==1 ){
@@ -315,13 +333,6 @@ void ctrlEvt(byte ctrl, byte evt){
315
333
// checkEffects(true);
316
334
// return;
317
335
// }
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
- }
325
336
326
337
// Is it a press for an un-off?
327
338
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){
331
342
return ;
332
343
}
333
344
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
+
334
362
if (fn < fnOpts) { // normal fn running/setting (not in settings menu)
335
363
336
- // TODO support evt==4 and evt==5 by removing inputStop() from eg evt==3 without clashing
337
-
338
364
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
340
366
fn = fnOpts;
341
367
clearSet (); // don't need updateDisplay() here because this calls updateRTC with force=true
342
368
return ;
@@ -384,7 +410,7 @@ void ctrlEvt(byte ctrl, byte evt){
384
410
if (!(timerState&1 )){ // stopped
385
411
timerStart ();
386
412
} else { // running
387
- #if CTRL_UPDN_TYPE==2 // rotary encoder
413
+ #ifdef INPUT_UPDN_ROTARY
388
414
if ((timerState>>1 )&1 ) timerLap (); // chrono: lap
389
415
else timerRunoutToggle (); // timer: runout option
390
416
#else // button
@@ -393,7 +419,7 @@ void ctrlEvt(byte ctrl, byte evt){
393
419
}
394
420
} else { // CTRL_DN
395
421
if (!(timerState&1 )){ // stopped
396
- #if CTRL_UPDN_TYPE==1 // buttons
422
+ #ifdef INPUT_UPDN_BUTTONS
397
423
timerClear ();
398
424
// if we wanted to reset to the previous time, we could use this; but sel hold is easy enough to get there
399
425
// //same as //save timer secs
@@ -405,7 +431,7 @@ void ctrlEvt(byte ctrl, byte evt){
405
431
updateDisplay ();
406
432
#endif
407
433
} else { // running
408
- #if CTRL_UPDN_TYPE==2 // rotary encoder
434
+ #ifdef INPUT_UPDN_ROTARY
409
435
timerStop ();
410
436
#else
411
437
if ((timerState>>1 )&1 ) timerLap (); // chrono: lap
@@ -418,44 +444,36 @@ void ctrlEvt(byte ctrl, byte evt){
418
444
}
419
445
// else do nothing
420
446
} // 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
459
477
} // end fn running
460
478
461
479
else { // fn setting
@@ -464,6 +482,7 @@ void ctrlEvt(byte ctrl, byte evt){
464
482
// currently no, because we don't inputStop() when short hold goes into fn setting, in case long hold may go to settings menu
465
483
// so we can't handle a release because it would immediately save if releasing from the short hold.
466
484
// 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
467
486
if (ctrl==CTRL_SEL) { // CTRL_SEL push: go to next setting or save and exit setting mode
468
487
inputStop (); // not waiting for CTRL_SELHold, so can stop listening here
469
488
// We will set rtc time parts directly
@@ -577,7 +596,7 @@ void ctrlEvt(byte ctrl, byte evt){
577
596
}
578
597
579
598
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
581
600
startSet (readEEPROM (optsLoc[opt],optsMax[opt]>255 ?true :false ),optsMin[opt],optsMax[opt],1 );
582
601
}
583
602
if (ctrl==CTRL_UP && evt==1 ) fnOptScroll (1 ); // next one up or cycle to beginning
@@ -889,9 +908,6 @@ void checkRTC(bool force){
889
908
if (unoffRemain>0 ) {
890
909
unoffRemain--; // updateDisplay will naturally put it back to off state if applicable
891
910
}
892
- if (versionRemain>0 ) {
893
- versionRemain--;
894
- }
895
911
} // end natural second
896
912
897
913
// Things to do at specific times
@@ -926,7 +942,7 @@ void checkRTC(bool force){
926
942
} // end alarm trigger
927
943
}
928
944
// 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 && */
930
946
if (readEEPROM (18 ,false )>=2 ) { goToFn (fnIsDate); fnPg = 254 ; updateDisplay (); }
931
947
// if(readEEPROM(18,false)==3) { startScroll(); }
932
948
}
@@ -1351,7 +1367,7 @@ void updateDisplay(){
1351
1367
// }
1352
1368
// } //todo move cleanRemain, scrollRemain to dispNixie
1353
1369
// else
1354
- if (versionRemain> 0 ) {
1370
+ if (versionShowing ) {
1355
1371
editDisplay (vMajor, 0 , 1 , false , false );
1356
1372
editDisplay (vMinor, 2 , 3 , false , false );
1357
1373
editDisplay (vPatch, 4 , 5 , false , false );
0 commit comments