@@ -136,8 +136,7 @@ const byte millisCorrectionInterval = 30; //used to calibrate millis() to RTC fo
136136unsigned long millisAtLastCheck = 0 ;
137137word unoffRemain = 0 ; // un-off (briefly turn on tubes during full night/away shutoff) timeout counter, seconds
138138byte 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
152151byte daysInMonth (word y, byte m); // used by network, rtcMillis
153152bool isDSTByHour (int y, byte m, byte d, byte h, bool setFlag); // used by network
154153void 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
156155void updateDisplay (); // used by network
157156void goToFn (byte thefn); // used by network
158157int 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
193192void 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
248252void 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 );
0 commit comments