Set up scheduled program cycles #24

Merged
W1CDN merged 41 commits from program-cycle into main 2023-09-15 16:51:45 -05:00
Showing only changes of commit 4380a56055 - Show all commits

View File

@ -63,12 +63,12 @@ bool programRunning;
int yourInputStepLength; int yourInputStepLength;
int yourInputCycleID; int yourInputCycleID;
int yourInputNtransmitters; int yourInputNtransmitters;
int step_length = 10000; // 10 secs //int step_length = 10000; // 10 secs
int cycle_id = 1; // number of this transmitter in cycle //int cycle_id = 1; // number of this transmitter in cycle
int n_transmitters = 2; //number of transmitters total //int n_transmitters = 2; //number of transmitters total
long start_millis = 0; long start_millis = 0;
long stop_millis = 0; long stop_millis = 0;
long pause_millis = 0; long pause_until_millis = 0;
// HTML web page to handle 3 input fields (inputString, inputSend, inputFloat) // HTML web page to handle 3 input fields (inputString, inputSend, inputFloat)
const char index_html[] PROGMEM = R"rawliteral( const char index_html[] PROGMEM = R"rawliteral(
@ -247,7 +247,7 @@ String processor(const String& var){
// Set up arduinomorse pin and default WPM // Set up arduinomorse pin and default WPM
LEDMorseSender sender(blinker, 10.0f); // the 'f' makes sure this is a float LEDMorseSender sender(blinker, 10.0f) ; // the 'f' makes sure this is a float
// TODO also for keyer once blinker works // TODO also for keyer once blinker works
// Speed is milliseconds per dit, which is 1000 * (60 / (50 * WPM)) // Speed is milliseconds per dit, which is 1000 * (60 / (50 * WPM))
@ -370,10 +370,11 @@ void setup() {
writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str()); writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str());
yourInputSend = inputMessage.toInt(); yourInputSend = inputMessage.toInt();
// if not running a program, set the program running off // if not running a program, set the program running off
if(yourInputSend != 2){ //if(yourInputSend != 2){
// Cease all programs on new input
startProgram = false; startProgram = false;
programRunning = false; programRunning = false;
} //}
} }
// GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage> // GET inputWPM value on <ESP_IP>/get?inputWPM=<inputMessage>
if (request->hasParam(PARAM_WPM)) { if (request->hasParam(PARAM_WPM)) {
@ -388,6 +389,21 @@ void setup() {
// save previous state // save previous state
yourInputMsg_old = yourInputMsg; yourInputMsg_old = yourInputMsg;
yourInputMsg = inputMessage.toInt(); yourInputMsg = inputMessage.toInt();
// Check the message every time the form is submitted.
if(yourInputMsg == 0){
sender.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){
sender.setMessage(String("moe "));
} else if(yourInputMsg == 2){
sender.setMessage(String("moi "));
} else if(yourInputMsg == 3){
sender.setMessage(String("mos "));
} else if(yourInputMsg == 4){
sender.setMessage(String("moh "));
} else if(yourInputMsg == 5){
sender.setMessage(String("mo5 "));
}
} }
// GET inputStepLength value on <ESP_IP>/get?inputStepLength=<inputMessage> // GET inputStepLength value on <ESP_IP>/get?inputStepLength=<inputMessage>
if (request->hasParam(PARAM_STEPLENGTH)) { if (request->hasParam(PARAM_STEPLENGTH)) {
@ -483,23 +499,23 @@ void loop() {
// See which message we are sending // See which message we are sending
// Only do this when the message has been updated. // Only do this when the message has been updated.
if(yourInputMsg != yourInputMsg_old){ // if(yourInputMsg != yourInputMsg_old){
if(yourInputMsg == 0){ // if(yourInputMsg == 0){
sender.setMessage(String("test test test de w1cdn ")); // sender.setMessage(String("test test test de w1cdn "));
} else if(yourInputMsg == 1){ // } else if(yourInputMsg == 1){
sender.setMessage(String("moe ")); // sender.setMessage(String("moe "));
} else if(yourInputMsg == 2){ // } else if(yourInputMsg == 2){
sender.setMessage(String("moi ")); // sender.setMessage(String("moi "));
} else if(yourInputMsg == 3){ // } else if(yourInputMsg == 3){
sender.setMessage(String("mos ")); // sender.setMessage(String("mos "));
} else if(yourInputMsg == 4){ // } else if(yourInputMsg == 4){
sender.setMessage(String("moh ")); // sender.setMessage(String("moh "));
} else if(yourInputMsg == 5){ // } else if(yourInputMsg == 5){
sender.setMessage(String("mo5 ")); // sender.setMessage(String("mo5 "));
} // }
// Keeps the key/led from locking up // // Keeps the key/led from locking up
yourInputMsg_old = yourInputMsg; // yourInputMsg_old = yourInputMsg;
} // }
// This statement from https://github.com/garrysblog/DS3231-Alarm-With-Adafruit-RTClib-Library/blob/master/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired.ino // This statement from https://github.com/garrysblog/DS3231-Alarm-With-Adafruit-RTClib-Library/blob/master/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired/DS3231-RTClib-Adafruit-Alarm-Poll-alarmFired.ino
// Check if alarm by polling SQW alarm pin // Check if alarm by polling SQW alarm pin
@ -516,35 +532,40 @@ void loop() {
} }
// Once alarm has started the program, set things up to run // Once alarm has started the program, set things up to run
if(startProgram == true){ if (startProgram == true){
//Serial.println("Start sending"); //Serial.println("Start sending");
start_millis = millis() + ((yourInputCycleID - 1) * yourInputStepLength);
start_millis = millis(); stop_millis = start_millis + yourInputStepLength;
stop_millis = start_millis + step_length; // Subtract 2 rather than 1 here to account for start_millis duration at beginning of repeat.
pause_millis = stop_millis + step_length; pause_until_millis = stop_millis + (yourInputStepLength * (yourInputNtransmitters - 2));
sender.startSending(); //arduinomorse //sender.startSending();
programRunning = true; programRunning = true;
startProgram = false; startProgram = false;
} }
// if you want to send continuous code, and it's not sending, then start it up // if you want to send continuous code, and it's not sending, then start it up
if((yourInputSend == 1)){;// & (morseToSend.IsRunning() == false)){ if((yourInputSend == 1)){
if (!sender.continueSending()){ if (!sender.continueSending()){
// Set the internal counters to the message's beginning. // Set the internal counters to the message's beginning.
// Here, this results in repeating the message indefinitely. // Here, this results in repeating the message indefinitely.
sender.startSending(); sender.startSending();
} }
// if you want to send cycle code and it's not sending, then start it up // 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) } else if((yourInputSend == 2) & (programRunning == true)){
if((millis() > start_millis) & (millis() < stop_millis)){ if((millis() < start_millis)){
// Shut the pin off manually
digitalWrite(blinker, LOW);
} else if((millis() >= start_millis) & (millis() <= stop_millis)){
if (!sender.continueSending()){ if (!sender.continueSending()){
// Set the internal counters to the message's beginning. // Set the internal counters to the message's beginning.
// Here, this results in repeating the message indefinitely. // Here, this results in repeating the message indefinitely.
sender.startSending(); sender.startSending();
} }
} else if((millis() > stop_millis) & (millis() < pause_millis)){ } else if((millis() >= stop_millis) & (millis() <= pause_until_millis)){
// do nothing in this case -- in between cycles // do nothing in this case -- in between cycles
} else if((millis() > pause_millis)){ // Shut the pin off manually
digitalWrite(blinker, LOW);
} else if((millis() >= pause_until_millis)){
startProgram = true; startProgram = true;
} }
// if the cycle program is not running // if the cycle program is not running
@ -552,7 +573,9 @@ void loop() {
// do we need something here? // do we need something here?
// if you don't want to send code // if you don't want to send code
} else if(yourInputSend == 0){ } else if(yourInputSend == 0){
sender.setMessage(String("")); // Not sure this is the right way to stop things. //sender.setMessage(String("")) ; // Not sure this is the right way to stop things.
// Shut the pin off manually
digitalWrite(blinker, LOW);
} }
} }