Skip to content

Commit e87910f

Browse files
committed
Bugfixes: fix to unoff when dim=0; alarm switch beep with quickBeep; delays in countdown date setting; display changes written to console (commented out)
1 parent 239e70f commit e87910f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

sixtube_lm/sixtube_lm.ino

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//Include the config file that matches your hardware setup. If needed, duplicate an existing one.
1414

1515
#include "configs/v8c-6tube-relayswitch-pwm-top.h"
16+
// #include "configs/v5-6tube-red.h"
1617

1718

1819
////////// Other includes, global consts, and vars //////////
@@ -133,6 +134,7 @@ void setup(){
133134
if(!enableSoftAlarmSwitch) writeEEPROM(2,1,false); //force alarm on if software switch is disabled
134135
//if LED circuit is not switched (v5.0 board), the LED menu setting (eeprom 26) doesn't matter
135136
initOutputs(); //depends on some EEPROM settings
137+
quickBeep(); //primes the beeper I think
136138
}
137139

138140
unsigned long pollCleanLast = 0; //every cleanSpeed ms
@@ -245,9 +247,7 @@ void ctrlEvt(byte ctrl, byte evt){
245247
if(signalSource==fnIsAlarm) { //If this was the alarm
246248
//If the alarm is using the switched relay and this is the Alt button, don't set the snooze
247249
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
251251
} else { //start snooze
252252
snoozeRemain = readEEPROM(24,false)*60; //snoozeRemain is seconds, but snooze duration is minutes
253253
}
@@ -259,9 +259,7 @@ void ctrlEvt(byte ctrl, byte evt){
259259
stoppingSignal = false;
260260
if(evt==2 && snoozeRemain>0) {
261261
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
265263
}
266264
btnStop();
267265
return;
@@ -372,9 +370,11 @@ void ctrlEvt(byte ctrl, byte evt){
372370
case fnIsDayCount: //set like date, save in eeprom like finishOpt
373371
switch(fnSetPg){
374372
case 1: //save year, set month
373+
delay(300); //blink display to indicate save. Safe b/c we've btnStopped. See below for why
375374
writeEEPROM(3,fnSetVal,true);
376375
startSet(readEEPROM(5,false),1,12,2); break;
377376
case 2: //save month, set date
377+
delay(300); //blink display to indicate save. Needed if set month == date: without blink, nothing changes.
378378
writeEEPROM(5,fnSetVal,false);
379379
startSet(readEEPROM(6,false),1,daysInMonth(fnSetValDate[0],fnSetValDate[1]),3); break;
380380
case 3: //save date
@@ -759,10 +759,11 @@ void setDST(char dir){
759759
void switchAlarm(char dir){
760760
if(enableSoftAlarmSwitch){
761761
signalStop(); //snoozeRemain = 0;
762+
byte itWas = readEEPROM(2,false);
762763
if(dir==1) writeEEPROM(2,1,false);
763764
if(dir==-1) writeEEPROM(2,0,false);
764765
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
766767
updateDisplay();
767768
}
768769
}
@@ -878,15 +879,14 @@ void updateDisplay(){
878879
//Set displayDim per night/away settings - fnIsAlarm may override this
879880
//issue: moving from off alarm to next fn briefly shows alarm in full brightness. I think because of the display delays. TODO
880881
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?
884883
//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
886886
//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);
888888
//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)
890890
//normal
891891
else displayDim = 2;
892892
updateLEDs();
@@ -981,6 +981,10 @@ void updateDisplay(){
981981
}
982982
Serial.println();
983983
}
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();
984988

985989
} //end updateDisplay()
986990

@@ -1197,6 +1201,11 @@ word getHz(byte note){
11971201
char getSignalOutput(){ //for current signal: time, timer, or (default) alarm: 0=piezo, 1=relay
11981202
return readEEPROM((signalSource==fnIsTime?44:(signalSource==fnIsTimer?43:42)),false);
11991203
}
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+
}
12001209

12011210
const byte ledFadeStep = 10; //fade speed – with every loop() we'll increment/decrement the LED brightness (between 0-255) by this amount
12021211
byte ledStateNow = 0;

0 commit comments

Comments
 (0)