Skip to content

Commit 9eb4c18

Browse files
committed
Bugfixes
1 parent 33d37d4 commit 9eb4c18

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

sixtube_lm/sixtube_lm.ino

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const byte fnsEnabled[] = {fnIsTime, fnIsDate, fnIsAlarm, fnIsTimer, fnIsDayCoun
3737
// A6-A7 are analog-only pins that aren't quite as responsive and require a physical pullup resistor (1K to +5V), and can't be used with rotary encoders because they don't support pin change interrupts.
3838

3939
// What input is associated with each control?
40-
const byte mainSel = A1; //main select button - must be equipped
41-
const byte mainAdjUp = A3; //main up/down buttons or rotary encoder - must be equipped
42-
const byte mainAdjDn = A2;
40+
const byte mainSel = A2; //main select button - must be equipped
41+
const byte mainAdjUp = A1; //main up/down buttons or rotary encoder - must be equipped
42+
const byte mainAdjDn = A0;
4343
const byte altSel = 0; //alt select button - if unequipped, set to 0
4444
const byte altAdjUp = 0; //A6; //alt up/down buttons or rotary encoder - if unequipped, set to 0
4545
const byte altAdjDn = 0; //A3;
@@ -92,8 +92,8 @@ const word cleanSpeed = 200; //ms
9292
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
9393

9494
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
95-
const word timeoutSet = 120; //sec
96-
const word timeoutTempFn = 5; //sec
95+
const unsigned long timeoutSet = 120; //sec
96+
const unsigned long timeoutTempFn = 5; //sec
9797

9898

9999
////////// Other global consts and vars //////////
@@ -192,13 +192,16 @@ void setup(){
192192
initOutputs();
193193
initInputs();
194194
//Initialize EEPROM if requested
195-
//if(readInput(mainSel)==LOW) initEEPROM(); TODO why is this firing so much
195+
if(readInput(mainSel)==LOW) initEEPROM(); //TODO why is this firing so much
196196
//Some options need to be set to a fixed value per the hardware configuration
197-
if(relayPin<0 || piezoPin<0) { //If no relay or no piezo, set each signal setting to [if no relay then beeper else relay]
197+
if(relayPin<0 || piezoPin<0) { //If no relay or no piezo, set each signal setting to [if no relay then piezo else relay]
198198
writeEEPROM(42,(relayPin<0?0:1),false); //alarm
199199
writeEEPROM(43,(relayPin<0?0:1),false); //timer
200200
writeEEPROM(44,(relayPin<0?0:1),false); //strike
201201
}
202+
if(piezoPin>=0 && relayMode==0) { //If piezo and relay is switch
203+
writeEEPROM(44,0,false); //strike forced to piezo
204+
}
202205
if(piezoPin<0 && relayMode==0) { //If no piezo and relay is switch
203206
writeEEPROM(21,0,false); //turn off strike
204207
writeEEPROM(25,0,false); //turn off timer interval mode
@@ -336,9 +339,9 @@ void ctrlEvt(byte ctrl, byte evt){
336339
//Before all else, is it a press to stop the signal? Silence it
337340
if(signalRemain>0 && evt==1){
338341
stoppingSignal = true;
339-
//If we're displaying the clock (as alarm trigger does), start snooze. 0 will have no effect.
340-
if(signalSource==fnIsAlarm) snoozeRemain = readEEPROM(24,false)*60; //snoozeRemain is seconds, but snooze duration is minutes
341342
signalStop();
343+
//If source is alarm, start snooze. 0 will have no effect.
344+
if(signalSource==fnIsAlarm) snoozeRemain = readEEPROM(24,false)*60; //snoozeRemain is seconds, but snooze duration is minutes
342345
return;
343346
}
344347
//After pressing to silence, short hold cancels a snooze; ignore other btn evts
@@ -698,7 +701,6 @@ void checkRTC(bool force){
698701
if(tod.hour()*60+tod.minute()==(readEEPROM(30,true)==0?readEEPROM(0,true):readEEPROM(30,true))) {
699702
cleanRemain = 11; //loop() will pick this up
700703
} //end cleaner check
701-
//
702704
}
703705
if(tod.second()==30 && fn==fnIsTime && fnSetPg==0 && unoffRemain==0) { //At bottom of minute, maybe show date - not when unoffing
704706
if(readEEPROM(18,false)>=2) { fn = fnIsDate; inputLast = pollLast; updateDisplay(); }
@@ -827,8 +829,8 @@ void switchPower(char dir){
827829
}
828830
Serial.print(millis(),DEC);
829831
Serial.print(F(" Relay "));
830-
if(dir==0) Serial.print(F("toggled "));
831-
Serial.print(digitalRead(relayPin)==HIGH?F("on"):F("off"));
832+
if(dir==0) { Serial.print(F("toggled")); if(relayPin!=127) { Serial.print(digitalRead(relayPin)==HIGH?F(" on"):F(" off")); } }
833+
else Serial.print(dir==1?F("switched on"):F("switched off"));
832834
Serial.println(F(", switchPower"));
833835
}
834836
}
@@ -1178,9 +1180,9 @@ void signalStop(){ //stop current signal and clear out signal timer if applicabl
11781180
//beep start and stop should only be called by signalStart/signalStop and checkRTC
11791181
void signalPulseStart(word pulseDur){
11801182
//Only act if the signal source output is pulsable
1181-
char output = readEEPROM((sigFn==fnIsTime?44:(sigFn==fnIsTimer?43:42)),false); //get output for time, timer, or (default) alarm
1183+
char output = readEEPROM((signalSource==fnIsTime?44:(signalSource==fnIsTimer?43:42)),false);
11821184
if(output==0 && piezoPin>=0) { //beeper
1183-
word pitch = getHz(readEEPROM((sigFn==fnIsTime?41:(sigFn==fnIsTimer?40:39)),false)); //get pitch for time, timer, or (default) alarm
1185+
word pitch = getHz(readEEPROM((signalSource==fnIsTime?41:(signalSource==fnIsTimer?40:39)),false));
11841186
tone(piezoPin, pitch, (pulseDur==0?piezoPulse:pulseDur));
11851187
}
11861188
if(output==1 && relayPin>=0 && relayMode==1) { //pulsed relay
@@ -1190,9 +1192,9 @@ void signalPulseStart(word pulseDur){
11901192
}
11911193
}
11921194
void signalPulseStop(){
1193-
char output = readEEPROM((sigFn==fnIsTime?44:(sigFn==fnIsTimer?43:42)),false); //get output for time, timer, or (default) alarm
1195+
char output = readEEPROM((signalSource==fnIsTime?44:(signalSource==fnIsTimer?43:42)),false);
11941196
if(output==0 && piezoPin>=0) { //beeper
1195-
noTone(signalPin);
1197+
noTone(piezoPin);
11961198
}
11971199
if(output==1 && relayPin>=0 && relayMode==1) { //pulsed relay
11981200
if(relayPin!=127) digitalWrite(relayPin,LOW);

0 commit comments

Comments
 (0)