This commit is contained in:
mattbk 2023-09-13 21:06:16 -05:00
parent 087ad27c8c
commit dd085635a2

View File

@ -29,6 +29,10 @@
AsyncWebServer server(80);
// Assign output variables to GPIO pins
const int keyer = 32; //LED_BUILTIN for on-board (dev);//26 for LED; //32 for transmitter keyer
const int blinker = LED_BUILTIN;
RTC_DS3231 rtc; // set up RTC
const int alarmPin = 4; // pin to monitor for RTC alarms
@ -167,21 +171,6 @@ const char index_html[] PROGMEM = R"rawliteral(
</script>
</body></html>)rawliteral";
// Assign output variables to GPIO pins
const int keyer = 32; //LED_BUILTIN for on-board (dev);//26 for LED; //32 for transmitter keyer
const int blinker = LED_BUILTIN;
// Timers
//auto timer = timer_create_default();
Timer<1> timer;
// Example from https://github.com/contrem/arduino-timer#examples
bool toggle_led(void *) {
//Serial.print("Timer time: ");
//Serial.println(rtc.now().timestamp());
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
return true; // keep timer active? true
}
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
@ -256,6 +245,15 @@ String processor(const String& var){
return String();
}
// Set up arduinomorse pin and default WPM
LEDMorseSender sender(blinker, 10.0f); // the 'f' makes sure this is a float
// TODO also for keyer once blinker works
// Timers
Timer<1> timer;
//jled from https://github.com/jandelgado/jled/blob/master/examples/morse/morse_effect.h
class MorseEffect : public jled::BrightnessEvaluator {
Morse morse_;
@ -379,7 +377,8 @@ JLedSequence* morses_sequence_blink_test = make_sequence(sequence, "MOE", 10, 10
void setup() {
Serial.begin(115200);
// Get arduinomorse ready to go
sender.setup();
pinMode(alarmPin, INPUT_PULLUP); // Set alarm pin as pullup
@ -444,21 +443,27 @@ void setup() {
if(yourInputMsg == 0){
morseToSend = morseTEST;
morseToSend_blink = morseTEST_blink;
sender.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){
morseToSend = morseMOE;
morseToSend_blink = morseMOE_blink;
sender.setMessage(String("moe "));
} else if(yourInputMsg == 2){
morseToSend = morseMOI;
morseToSend_blink = morseMOI_blink;
sender.setMessage(String("moi "));
} else if(yourInputMsg == 3){
morseToSend = morseMOS;
morseToSend_blink = morseMOS_blink;
sender.setMessage(String("mos "));
} else if(yourInputMsg == 4){
morseToSend = morseMOH;
morseToSend_blink = morseMOH_blink;
sender.setMessage(String("moh "));
} else if(yourInputMsg == 5){
morseToSend = morseMO5;
morseToSend_blink = morseMO5_blink;
sender.setMessage(String("mo5 "));
}
WiFi.mode(WIFI_STA);
@ -583,13 +588,6 @@ void setup() {
yourInputStartTimeUnix = atol(inputMessage.c_str());
//}
Serial.println(yourInputStartTimeUnix);
// We can't use arduino-timer for starting a program because
// it relies on millis(), which reset on power cycle.
// timer.at(millis() + 10000, toggle_led);
// Serial.println(millis());
// auto active_tasks = timer.size();
// Serial.println(active_tasks);
// Use alarm built into RTC
rtc.setAlarm1(DateTime(yourInputStartTimeUnix), DS3231_A1_Date);
@ -611,7 +609,7 @@ void loop() {
// Timers
timer.tick();
morses_sequence_blink_test->Forever().Update();
//morses_sequence_blink_test->Forever().Update();
// See which message we are sending
// Only do this when the message has been updated.
@ -620,20 +618,26 @@ void loop() {
if(yourInputMsg == 0){
morseToSend = morseTEST;
morseToSend_blink = morseTEST_blink;
sender.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){
morseToSend = morseMOE;
sender.setMessage(String("moe "));
morseToSend_blink = morseMOE_blink;
} else if(yourInputMsg == 2){
morseToSend = morseMOI;
sender.setMessage(String("moi "));
morseToSend_blink = morseMOI_blink;
} else if(yourInputMsg == 3){
morseToSend = morseMOS;
sender.setMessage(String("mos "));
morseToSend_blink = morseMOS_blink;
} else if(yourInputMsg == 4){
morseToSend = morseMOH;
sender.setMessage(String("moh "));
morseToSend_blink = morseMOH_blink;
} else if(yourInputMsg == 5){
morseToSend = morseMO5;
sender.setMessage(String("mo5 "));
morseToSend_blink = morseMO5_blink;
}
// Keeps the key/led from locking up
@ -670,10 +674,14 @@ void loop() {
// blinker_continuous_wait
// };
// auto morses_sequence_blink = JLedSequence(JLedSequence::eMode::SEQUENCE, morses_blink);
morses_sequence_blink.Forever().Update();
//morses_sequence_blink.Forever().Update();
Serial.println("Start sending");
sender.startSending(); //arduinomorse
programRunning = true;
startProgram = false;
// Serial.println(yourInputSend);
// Serial.println(programRunning);
}
// if you want to send continuous code, and it's not sending, then start it up
@ -688,26 +696,33 @@ void loop() {
morseToSend_blink.Update();
// if you want to send cycle code and it is sending, keep sending
} else if((yourInputSend == 2) & (programRunning == true) &(morses_sequence_blink.Update() == true)){
morseToSend.Update();
} else if((yourInputSend == 2) & (programRunning == true)){//&(morses_sequence_blink.Update() == true)
//morseToSend.Update();
//morseToSend_blink.Update();
morses_sequence_blink.Update();
//morses_sequence_blink.Update();
sender.continueSending();
// if you want to send cycle code and it's not sending, then start it up
} else if((yourInputSend == 2) & (programRunning == true) & (morses_sequence_blink.Update() == false)){
morseToSend.Reset().Update();
//morseToSend_blink.Reset().Update();
morses_sequence_blink.Reset();
// } else if((yourInputSend == 2) & (programRunning == true) & !sender.continueSending()){//& (morses_sequence_blink.Update() == false)
// //morseToSend.Reset().Update();
// //morseToSend_blink.Reset().Update();
// //morses_sequence_blink.Reset();
// Serial.println("Start up cycle");
// sender.startSending();
// if the cycle program is not running
} else if((yourInputSend == 2) & (programRunning == false)){
morses_sequence_blink.Stop();
//Serial.println("Program is over, stop sending")
//morses_sequence_blink.Stop();
//sender.setMessage(String(""));
// if you don't want to send code
} else {
Serial.println("Stop sending");
// stop sending and make sure the pin is off
morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update();
morseToSend_blink.Stop(JLed::eStopMode::FULL_OFF).Update();
morses_sequence_blink.Stop();
//morses_sequence_blink.Stop();
sender.setMessage(String(""));
}
//morseToSend.Update();
//sender.continueSending();
}