@@ -31,6 +31,7 @@ These ones are set outside the options menu (defaults defined in initEEPROM()):
3131 3-4 Day count year
3232 5 Day count month
3333 6 Day count date
34+ 7 Alt function (if not power switching)
3435( 7-15 are available )
3536
3637These ones are set inside the options menu (defaults defined in arrays below).
@@ -312,10 +313,29 @@ void ctrlEvt(byte ctrl, byte evt){
312313 // if(fn==fnIsTime) TODO volume in I2C radio
313314 }
314315 }
315- else if (altSel!= 0 && ctrl==altSel) { // alt sel press
316+ else if (altSel> 0 && ctrl==altSel) { // alt sel press
316317 // TODO switch I2C radio
317- switchPower (0 );
318- btnStop ();
318+ // if switched relay, and soft switch enabled, we'll switch power.
319+ if (enableSoftPowerSwitch && relayPin>=0 && relayMode==0 ) switchPower (0 );
320+ // Otherwise, this becomes our function preset.
321+ else {
322+ // On long hold, if this is not currently the preset, we'll set it, double beep, and btnStop.
323+ // (Decided not to let this button set things, because then it steps on the toes of Sel's functionality.)
324+ if (evt==2 ) {
325+ if (readEEPROM (7 ,false )!=fn) {
326+ writeEEPROM (7 ,fn,false );
327+ quickBeep ();
328+ delay (250 );
329+ quickBeep ();
330+ }
331+ }
332+ // On short release, toggle between fnIsTime and the preset fn.
333+ else if (evt==0 ) {
334+ if (fn==readEEPROM (7 ,false )) fn=fnIsTime; else fn=readEEPROM (7 ,false );
335+ updateDisplay ();
336+ }
337+ }
338+ btnStop (); // In any case, this button should only do one action at a time
319339 }
320340 } // end fn running
321341
@@ -515,6 +535,29 @@ void initEEPROM(bool hard){
515535 if (hard || readEEPROM (3 ,true )<2018 ) writeEEPROM (3 ,2018 ,true ); // day counter target: 2018...
516536 if (hard || readEEPROM (5 ,false )<1 || readEEPROM (5 ,false )>12 ) writeEEPROM (5 ,1 ,false ); // ...January...
517537 if (hard || readEEPROM (6 ,false )<1 || readEEPROM (6 ,false )>31 ) writeEEPROM (6 ,1 ,false ); // ...first.
538+ Serial.println (F (" Hello world" ));
539+ Serial.println (F (" Hello world" ));
540+ Serial.println (F (" Hello world" ));
541+ Serial.print (F (" Alt preset is currently " ));
542+ Serial.println (readEEPROM (7 ,false ),DEC);
543+ bool foundAltFn = false ;
544+ for (byte fni=0 ; fni<sizeof (fnsEnabled); fni++) {
545+ Serial.print (F (" Let's see if fnsEnabled[" ));
546+ Serial.print (fni,DEC);
547+ Serial.print (F (" ] (which is " ));
548+ Serial.print (fnsEnabled[fni],DEC);
549+ Serial.print (F (" ) is " ));
550+ Serial.print (readEEPROM (7 ,false ));
551+ if (fnsEnabled[fni]==readEEPROM (7 ,false )) { foundAltFn = true ; Serial.println (F (" ...it is!" )); break ; }
552+ else Serial.println (F (" ...it is not" ));
553+ }
554+ Serial.print (F (" foundAltFn is " ));
555+ Serial.println (foundAltFn?F (" true" ):F (" false" ));
556+ if (hard || !foundAltFn) writeEEPROM (7 ,0 ,false ); // Alt function preset – make sure it is not set to a function that isn't enabled in this clock
557+ Serial.print (F (" Alt preset is now " ));
558+ Serial.println (readEEPROM (7 ,false ),DEC);
559+ Serial.println ();
560+
518561 // then the options menu defaults
519562 bool isWord = false ;
520563 for (byte opt=0 ; opt<sizeof (optsLoc); opt++) {
@@ -593,8 +636,8 @@ void checkRTC(bool force){
593636 if (fnSetPg || fn>=fnOpts){
594637 if ((unsigned long )(now-inputLast)>=timeoutSet*1000 ) { fnSetPg = 0 ; fn = fnIsTime; force=true ; } // Time out after 2 mins
595638 }
596- // Temporary-display mode timeout: if we're *not* in a permanent one (time, day counter, temp, tester , or running/signaling timer)
597- else if (fn!=fnIsTime && fn!=fnIsTubeTester && fn!=fnIsDayCount && fn!=fnIsTemp && !(fn==fnIsTimer && (timerRemain>0 || signalRemain>0 ))){
639+ // Temporary-display mode timeout: if we're *not* in a permanent one (time, Alt preset , or running/signaling timer)
640+ else if (fn!=fnIsTime && fn!=readEEPROM ( 7 , false ) && !(fn==fnIsTimer && (timerRemain>0 || signalRemain>0 ))){
598641 if ((unsigned long )(now-inputLast)>=timeoutTempFn*1000 ) { fnSetPg = 0 ; fn = fnIsTime; force=true ; }
599642 }
600643 // Stop a signal pulse if it's time to
@@ -767,30 +810,24 @@ void switchAlarm(char dir){
767810 }
768811}
769812void switchPower (char dir){
770- if (enableSoftPowerSwitch && relayPin>=0 && relayMode==0 ) { // if switched relay, and soft switch enabled
771- signalRemain = 0 ; snoozeRemain = 0 ; // in case alarm is going now - alternatively use signalStop()?
772- // If the timer is running and is using the switched relay, this instruction conflicts with it, so cancel it
773- if (timerRemain>0 && readEEPROM (43 ,false )==1 ) {
774- timerRemain=0 ;
775- updateDisplay ();
776- }
777- // relayPin state is the reverse of the appliance state: LOW = device on, HIGH = device off
778- // Serial.print(millis(),DEC);
779- // Serial.print(F(" Relay requested to "));
780- if (dir==0 ) { // toggle
781- dir = (digitalRead (relayPin)?1 :-1 ); // LOW = device on, so this effectively does our dir reversion for us
782- // Serial.print(dir==1?F("toggle on"):F("toggle off"));
783- } else {
784- // Serial.print(dir==1?F("switch on"):F("switch off"));
785- }
786- digitalWrite (relayPin,(dir==1 ?0 :1 )); // LOW = device on
787- // Serial.println(F(", switchPower"));
788- updateLEDs (); // LEDs following switch relay
789- } else {
790- // If we can't switch power (no switched relay, or no soft power switch), toggle to altSelFn instead
791- if (fn==altSelFn && altSelFn>-1 ) fn=fnIsTime; else fn=altSelFn;
813+ signalRemain = 0 ; snoozeRemain = 0 ; // in case alarm is going now - alternatively use signalStop()?
814+ // If the timer is running and is using the switched relay, this instruction conflicts with it, so cancel it
815+ if (timerRemain>0 && readEEPROM (43 ,false )==1 ) {
816+ timerRemain=0 ;
792817 updateDisplay ();
793818 }
819+ // relayPin state is the reverse of the appliance state: LOW = device on, HIGH = device off
820+ // Serial.print(millis(),DEC);
821+ // Serial.print(F(" Relay requested to "));
822+ if (dir==0 ) { // toggle
823+ dir = (digitalRead (relayPin)?1 :-1 ); // LOW = device on, so this effectively does our dir reversion for us
824+ // Serial.print(dir==1?F("toggle on"):F("toggle off"));
825+ } else {
826+ // Serial.print(dir==1?F("switch on"):F("switch off"));
827+ }
828+ digitalWrite (relayPin,(dir==1 ?0 :1 )); // LOW = device on
829+ // Serial.println(F(", switchPower"));
830+ updateLEDs (); // LEDs following switch relay
794831}
795832
796833bool isTimeInRange (word tstart, word tend, word ttest) {
0 commit comments