Skip to content

Commit 33d37d4

Browse files
committed
Finish signalPulseStart and signalPulseStop
1 parent 998c9bf commit 33d37d4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

sixtube_lm/sixtube_lm.ino

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Some are skipped when they wouldn't apply to a given clock's hardware config, se
134134
39 Alarm beeper pitch - skipped when no piezo
135135
40 Timer beeper pitch - skipped when no piezo
136136
41 Strike beeper pitch - skipped when no piezo
137-
42 Alarm signal - skipped when no relay (start=0) or no piezo (start=0)
137+
42 Alarm signal, 0=beeper, 1=relay - skipped when no relay (start=0) or no piezo (start=0)
138138
43 Timer signal - skipped when no relay (start=0) or no piezo (start=1)
139139
44 Strike signal - skipped when no pulse relay (start=0) or no piezo (start=1)
140140
*/
@@ -175,7 +175,6 @@ word signalRemain = 0; //alarm/timer signal timeout counter, seconds
175175
word snoozeRemain = 0; //snooze timeout counter, seconds
176176
word timerInitial = 0; //timer original setting, seconds - up to 18 hours (64,800 seconds - fits just inside a word)
177177
word timerRemain = 0; //timer actual counter
178-
word signalPitch = 440; //current signal pitch - set by what started the signal going
179178
unsigned long signalPulseStopTime = 0; //to stop beeps after a time
180179
word unoffRemain = 0; //un-off (briefly turn on tubes during full night-off or day-off) timeout counter, seconds
181180
byte displayNext[6] = {15,15,15,15,15,15}; //Internal representation of display. Blank to start. Change this to change tubes.
@@ -1157,7 +1156,6 @@ void signalStart(byte sigFn, byte sigDur, word pulseDur){ //make some noise! or
11571156
//If doing a single beep, pulseDur is the number of ms it should last, or 0 for signal source's chosen output's pulse length (which will be used anyway if pulsed relay)
11581157
signalStop();
11591158
signalSource = sigFn;
1160-
signalPitch = getHz(readEEPROM((sigFn==fnIsTime?41:(sigFn==fnIsTimer?40:39)),false)); //use pitch for time, timer, or (default) alarm
11611159
if(sigDur==0) signalPulseStart(pulseDur); //single immediate beep
11621160
else { //long-duration signal (alarm, sleep, etc)
11631161
if(sigFn==fnIsAlarm) signalRemain = (readEEPROM(42,false)==1 && relayPin>=0 && relayMode==0 ? switchDur : signalDur);
@@ -1179,21 +1177,28 @@ void signalStop(){ //stop current signal and clear out signal timer if applicabl
11791177
}
11801178
//beep start and stop should only be called by signalStart/signalStop and checkRTC
11811179
void signalPulseStart(word pulseDur){
1182-
//Stopping point: This function needs to know which pin to pulse, per the settings of the current signaling thing. That comes from eeprom so it needs to go into a var like signalPitch, or convert both to read from eeprom every time per signalSource.
1183-
if(signalType==0) { tone(signalPin, signalPitch, (pulseDur==0?signalPulseDur:pulseDur)); }
1184-
else if(signalType==1) {
1185-
digitalWrite(signalPin,HIGH); signalPulseStopTime = millis()+(pulseDur==0?signalPulseDur:pulseDur);
1180+
//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
1182+
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
1184+
tone(piezoPin, pitch, (pulseDur==0?piezoPulse:pulseDur));
1185+
}
1186+
if(output==1 && relayPin>=0 && relayMode==1) { //pulsed relay
1187+
if(relayPin!=127) digitalWrite(relayPin,HIGH);
1188+
signalPulseStopTime = millis()+relayPulse; //(pulseDur==0?relayPulse:pulseDur); //TODO danger of a duration that's not relayPulse?
11861189
Serial.print(millis(),DEC); Serial.println(F(" Relay on, signalPulseStart"));
11871190
}
1188-
//signalType==2 do nothing
11891191
}
11901192
void signalPulseStop(){
1191-
if(signalType==0) { noTone(signalPin); }
1192-
else if(signalType==1) {
1193-
digitalWrite(signalPin,LOW); signalPulseStopTime = 0;
1194-
Serial.print(millis(),DEC); Serial.println(F(" Relay off, signalPulseStop"));
1193+
char output = readEEPROM((sigFn==fnIsTime?44:(sigFn==fnIsTimer?43:42)),false); //get output for time, timer, or (default) alarm
1194+
if(output==0 && piezoPin>=0) { //beeper
1195+
noTone(signalPin);
1196+
}
1197+
if(output==1 && relayPin>=0 && relayMode==1) { //pulsed relay
1198+
if(relayPin!=127) digitalWrite(relayPin,LOW);
1199+
signalPulseStopTime = 0;
1200+
Serial.print(millis(),DEC); Serial.println(F(" Relay off, signalPulseStart"));
11951201
}
1196-
//signalType==2 do nothing
11971202
}
11981203
word getHz(byte note){
11991204
//Given a piano key note, return frequency

0 commit comments

Comments
 (0)