13
13
// Include the config file that matches your hardware setup. If needed, duplicate an existing one.
14
14
15
15
#include " configs/v8c-6tube-relayswitch-pwm-top.h"
16
+ // #include "configs/v5-6tube-red.h"
16
17
17
18
18
19
// //////// Other includes, global consts, and vars //////////
@@ -133,6 +134,7 @@ void setup(){
133
134
if (!enableSoftAlarmSwitch) writeEEPROM (2 ,1 ,false ); // force alarm on if software switch is disabled
134
135
// if LED circuit is not switched (v5.0 board), the LED menu setting (eeprom 26) doesn't matter
135
136
initOutputs (); // depends on some EEPROM settings
137
+ quickBeep (); // primes the beeper I think
136
138
}
137
139
138
140
unsigned long pollCleanLast = 0 ; // every cleanSpeed ms
@@ -245,9 +247,7 @@ void ctrlEvt(byte ctrl, byte evt){
245
247
if (signalSource==fnIsAlarm) { // If this was the alarm
246
248
// If the alarm is using the switched relay and this is the Alt button, don't set the snooze
247
249
if (relayMode==0 && readEEPROM (42 ,false )==1 && altSel!=0 && ctrl==altSel) {
248
- // Short signal to indicate the alarm has been silenced until tomorrow - on beeper if relay is switched
249
- if (getSignalOutput ()==1 && relayMode==0 ) { if (piezoPin>=0 ) { tone (piezoPin, getSignalPitch (), 100 ); }}
250
- else signalStart (fnIsAlarm,0 ,100 );
250
+ quickBeep (); // Short signal to indicate the alarm has been silenced until tomorrow
251
251
} else { // start snooze
252
252
snoozeRemain = readEEPROM (24 ,false )*60 ; // snoozeRemain is seconds, but snooze duration is minutes
253
253
}
@@ -259,9 +259,7 @@ void ctrlEvt(byte ctrl, byte evt){
259
259
stoppingSignal = false ;
260
260
if (evt==2 && snoozeRemain>0 ) {
261
261
snoozeRemain = 0 ;
262
- // Short signal to indicate the alarm has been silenced until tomorrow - on beeper if relay is switched
263
- if (getSignalOutput ()==1 && relayMode==0 ) { if (piezoPin>=0 ) { tone (piezoPin, getSignalPitch (), 100 ); }}
264
- else signalStart (fnIsAlarm,0 ,100 );
262
+ quickBeep (); // Short signal to indicate the alarm has been silenced until tomorrow
265
263
}
266
264
btnStop ();
267
265
return ;
@@ -372,9 +370,11 @@ void ctrlEvt(byte ctrl, byte evt){
372
370
case fnIsDayCount: // set like date, save in eeprom like finishOpt
373
371
switch (fnSetPg){
374
372
case 1 : // save year, set month
373
+ delay (300 ); // blink display to indicate save. Safe b/c we've btnStopped. See below for why
375
374
writeEEPROM (3 ,fnSetVal,true );
376
375
startSet (readEEPROM (5 ,false ),1 ,12 ,2 ); break ;
377
376
case 2 : // save month, set date
377
+ delay (300 ); // blink display to indicate save. Needed if set month == date: without blink, nothing changes.
378
378
writeEEPROM (5 ,fnSetVal,false );
379
379
startSet (readEEPROM (6 ,false ),1 ,daysInMonth (fnSetValDate[0 ],fnSetValDate[1 ]),3 ); break ;
380
380
case 3 : // save date
@@ -759,10 +759,11 @@ void setDST(char dir){
759
759
void switchAlarm (char dir){
760
760
if (enableSoftAlarmSwitch){
761
761
signalStop (); // snoozeRemain = 0;
762
+ byte itWas = readEEPROM (2 ,false );
762
763
if (dir==1 ) writeEEPROM (2 ,1 ,false );
763
764
if (dir==-1 ) writeEEPROM (2 ,0 ,false );
764
765
if (dir==0 ) writeEEPROM (2 ,!readEEPROM (2 ,false ),false );
765
- if (readEEPROM (2 ,false )) signalStart (fnIsAlarm, 0 , 100 ); // Short beep at alarm pitch
766
+ if (readEEPROM (2 ,false ) && itWas== false ) quickBeep ( ); // Short signal to indicate we just turned the alarm on
766
767
updateDisplay ();
767
768
}
768
769
}
@@ -878,15 +879,14 @@ void updateDisplay(){
878
879
// Set displayDim per night/away settings - fnIsAlarm may override this
879
880
// issue: moving from off alarm to next fn briefly shows alarm in full brightness. I think because of the display delays. TODO
880
881
word todmins = tod.hour ()*60 +tod.minute ();
881
- // In order of precedence:
882
- // temporary unoff, if off (not dim)
883
- if (unoffRemain>0 && displayDim==0 ) displayDim = 2 ; // TODO can we fade between dim states?
882
+ // In order of precedence: //TODO can we fade between dim states?
884
883
// clock at work: away on weekends, all day
885
- else if ( readEEPROM (32 ,false )==1 && !isDayInRange (readEEPROM (33 ,false ),readEEPROM (34 ,false ),toddow) ) displayDim = 0 ;
884
+ if ( readEEPROM (32 ,false )==1 && !isDayInRange (readEEPROM (33 ,false ),readEEPROM (34 ,false ),toddow) )
885
+ displayDim = (unoffRemain>0 ? 2 : 0 ); // unoff overrides this
886
886
// clock at home: away on weekdays, during office hours only
887
- else if ( readEEPROM (32 ,false )==2 && isDayInRange (readEEPROM (33 ,false ),readEEPROM (34 ,false ),toddow) && isTimeInRange (readEEPROM (35 ,true ), readEEPROM (37 ,true ), todmins) ) displayDim = 0 ;
887
+ else if ( readEEPROM (32 ,false )==2 && isDayInRange (readEEPROM (33 ,false ),readEEPROM (34 ,false ),toddow) && isTimeInRange (readEEPROM (35 ,true ), readEEPROM (37 ,true ), todmins) ) displayDim = (unoffRemain> 0 ? 2 : 0 ) ;
888
888
// night mode - if night end is 0:00, use alarm time instead
889
- else if ( readEEPROM (27 ,false ) && isTimeInRange (readEEPROM (28 ,true ), (readEEPROM (30 ,true )==0 ?readEEPROM (0 ,true ):readEEPROM (30 ,true )), todmins) ) displayDim = (readEEPROM (27 ,false )==1 ?1 :0 ) ; // dim or off
889
+ else if ( readEEPROM (27 ,false ) && isTimeInRange (readEEPROM (28 ,true ), (readEEPROM (30 ,true )==0 ?readEEPROM (0 ,true ):readEEPROM (30 ,true )), todmins) ) displayDim = (readEEPROM (27 ,false )==1 ?1 :(unoffRemain> 0 ? 2 : 0 )) ; // dim or (unoff? bright: off)
890
890
// normal
891
891
else displayDim = 2 ;
892
892
updateLEDs ();
@@ -981,6 +981,10 @@ void updateDisplay(){
981
981
}
982
982
Serial.println ();
983
983
}
984
+
985
+ // Write display changes to console
986
+ // for(byte w=0; w<6; w++) { if(displayNext[w]>9) Serial.print(F("-")); else Serial.print(displayNext[w],DEC); }
987
+ // Serial.println();
984
988
985
989
} // end updateDisplay()
986
990
@@ -1197,6 +1201,11 @@ word getHz(byte note){
1197
1201
char getSignalOutput (){ // for current signal: time, timer, or (default) alarm: 0=piezo, 1=relay
1198
1202
return readEEPROM ((signalSource==fnIsTime?44 :(signalSource==fnIsTimer?43 :42 )),false );
1199
1203
}
1204
+ void quickBeep (){
1205
+ // Short beeper signal at alarm pitch (if equipped), even if relay is switched. Used when silencing snooze or switching alarm on.
1206
+ if (getSignalOutput ()==1 && relayMode==0 ) { if (piezoPin>=0 ) { signalSource=fnIsAlarm; tone (piezoPin, getSignalPitch (), 100 ); }}
1207
+ else signalStart (fnIsAlarm,0 ,100 );
1208
+ }
1200
1209
1201
1210
const byte ledFadeStep = 10 ; // fade speed – with every loop() we'll increment/decrement the LED brightness (between 0-255) by this amount
1202
1211
byte ledStateNow = 0 ;
0 commit comments