diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp
index b840c45..0dc2bf3 100644
--- a/vulpes/src/main.cpp
+++ b/vulpes/src/main.cpp
@@ -34,15 +34,20 @@ const char* ssid = WIFI_SSID;
const char* password = WIFI_PASSWORD;
const char* PARAM_STRING = "inputString";
-const char* PARAM_INT = "inputInt";
+const char* PARAM_SEND = "inputSend";
+const char* PARAM_WPM = "inputWPM";
+const char* PARAM_MSG = "inputMsg";
const char* PARAM_FLOAT = "inputFloat";
// Global variables
String yourInputString;
-int yourInputInt;
+int yourInputSend;
+int yourInputWPM;
+int yourInputMsg;
+int yourInputMsg_old; // to save previous state and check changes
float yourInputFloat;
-// HTML web page to handle 3 input fields (inputString, inputInt, inputFloat)
+// HTML web page to handle 3 input fields (inputString, inputSend, inputFloat)
const char index_html[] PROGMEM = R"rawliteral(
ESP Input Form
@@ -55,17 +60,26 @@ const char index_html[] PROGMEM = R"rawliteral(
@@ -103,11 +117,6 @@ bool toggle_gpio_26(void *) {
return true; // keep timer active? true
}
-// defaults
-// String yourInputString;
-// int yourInputInt;
-// float yourInputFloat;
-
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
@@ -144,14 +153,20 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
file.close();
}
-// Replaces placeholder with stored values
+// Replaces placeholder in web UI with stored values
String processor(const String& var){
//Serial.println(var);
if(var == "inputString"){
return readFile(SPIFFS, "/inputString.txt");
}
- else if(var == "inputInt"){
- return readFile(SPIFFS, "/inputInt.txt");
+ else if(var == "inputSend"){
+ return readFile(SPIFFS, "/inputSend.txt");
+ }
+ else if(var == "inputWPM"){
+ return readFile(SPIFFS, "/inputWPM.txt");
+ }
+ else if(var == "inputMsg"){
+ return readFile(SPIFFS, "/inputMsg.txt");
}
else if(var == "inputFloat"){
return readFile(SPIFFS, "/inputFloat.txt");
@@ -247,9 +262,30 @@ class MorseEffect : public jled::BrightnessEvaluator {
// Speed is milliseconds per dit, which is 1000 * (60 / (50 * WPM))
// 60 is 20 wpm, 120 is 10 wpm, 90 is 15 wpm, etc.
// https://morsecode.world/international/timing.html
-MorseEffect morseEffect("CQ CQ CQ DE W1CDN", 120);
-auto morseLed =
- JLed(output26).UserFunc(&morseEffect).DelayAfter(2000).Forever();
+float wpm = 10;
+float ms_per_dit = 1000 * (60 / (50 * wpm));
+int word_space_ms = ms_per_dit * 7;
+// Hardcoding these for now, will come back and make it more flexible.
+MorseEffect morseEffectCQ("CQ CQ CQ DE W1CDN", ms_per_dit);
+MorseEffect morseEffectMOE("MOE", ms_per_dit);
+MorseEffect morseEffectMOI("MOI", ms_per_dit);
+MorseEffect morseEffectMOS("MOS", ms_per_dit);
+MorseEffect morseEffectMOH("MOH", ms_per_dit);
+MorseEffect morseEffectMO5("MO5", ms_per_dit);
+
+auto morseCQ =
+ JLed(output26).UserFunc(&morseEffectCQ).DelayAfter(word_space_ms).Forever();
+auto morseMOE =
+ JLed(output26).UserFunc(&morseEffectMOE).DelayAfter(word_space_ms).Forever();
+auto morseMOI =
+ JLed(output26).UserFunc(&morseEffectMOI).DelayAfter(word_space_ms).Forever();
+auto morseMOS =
+ JLed(output26).UserFunc(&morseEffectMOS).DelayAfter(word_space_ms).Forever();
+auto morseMOH =
+ JLed(output26).UserFunc(&morseEffectMOH).DelayAfter(word_space_ms).Forever();
+auto morseMO5 =
+ JLed(output26).UserFunc(&morseEffectMO5).DelayAfter(word_space_ms).Forever();
+auto morseToSend = morseCQ; // set this up to overwrite later
//================================================================================
// setup(): stuff that only gets done once, after power up (KB1OIQ's description)
@@ -285,11 +321,48 @@ void setup() {
}
//#endif
+ // Make sure files exist, maybe with defaults here
+ // if(SPIFFS.exists("/inputString.txt") == 0){
+ // writeFile(SPIFFS, "/inputString.txt", "CQ");
+ // }
+ // if(SPIFFS.exists("/inputSend.txt") == 0){
+ // writeFile(SPIFFS, "/inputSend.txt", "0");
+ // }
+ // if(SPIFFS.exists("/inputWPM.txt") == 0){
+ // writeFile(SPIFFS, "/inputWPM.txt", "10");
+ // }
+ // if(SPIFFS.exists("/inputMsg.txt") == 0){
+ // writeFile(SPIFFS, "/inputMsg.txt", "0");
+ // }
+ // if(SPIFFS.exists("/inputFloat.txt") == 0){
+ // writeFile(SPIFFS, "/inputFloat.txt", "1.1");
+ // }
+
+
// Read in existing data
yourInputString = readFile(SPIFFS, "/inputString.txt");
- yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
+ yourInputSend = readFile(SPIFFS, "/inputSend.txt").toInt();
+ yourInputWPM = readFile(SPIFFS, "/inputWPM.txt").toInt();
+ yourInputMsg = readFile(SPIFFS, "/inputMsg.txt").toInt();
yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
+
+ // On restart, keep doing what you were doing before
+ yourInputMsg_old = yourInputMsg;
+ if(yourInputMsg == 0){
+ morseToSend = morseCQ;
+ } else if(yourInputMsg == 1){
+ morseToSend = morseMOE;
+ } else if(yourInputMsg == 2){
+ morseToSend = morseMOI;
+ } else if(yourInputMsg == 3){
+ morseToSend = morseMOS;
+ } else if(yourInputMsg == 4){
+ morseToSend = morseMOH;
+ } else if(yourInputMsg == 5){
+ morseToSend = morseMO5;
+ }
+
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
@@ -314,11 +387,25 @@ void setup() {
writeFile(SPIFFS, "/inputString.txt", inputMessage.c_str());
yourInputString = inputMessage;
}
- // GET inputInt value on /get?inputInt=
- if (request->hasParam(PARAM_INT)) {
- inputMessage = request->getParam(PARAM_INT)->value();
- writeFile(SPIFFS, "/inputInt.txt", inputMessage.c_str());
- yourInputInt = inputMessage.toInt();
+ // GET inputSend value on /get?inputSend=
+ if (request->hasParam(PARAM_SEND)) {
+ inputMessage = request->getParam(PARAM_SEND)->value();
+ writeFile(SPIFFS, "/inputSend.txt", inputMessage.c_str());
+ yourInputSend = inputMessage.toInt();
+ }
+ // GET inputWPM value on /get?inputWPM=
+ if (request->hasParam(PARAM_WPM)) {
+ inputMessage = request->getParam(PARAM_WPM)->value();
+ writeFile(SPIFFS, "/inputWPM.txt", inputMessage.c_str());
+ yourInputWPM = inputMessage.toInt();
+ }
+ // GET inputMsg value on /get?inputMsg=
+ if (request->hasParam(PARAM_MSG)) {
+ inputMessage = request->getParam(PARAM_MSG)->value();
+ writeFile(SPIFFS, "/inputMsg.txt", inputMessage.c_str());
+ // save previous state
+ yourInputMsg_old = yourInputMsg;
+ yourInputMsg = inputMessage.toInt();
}
// GET inputFloat value on /get?inputFloat=
if (request->hasParam(PARAM_FLOAT)) {
@@ -331,10 +418,6 @@ void setup() {
// }
request->send(200, "text/plain", inputMessage);
- // // Update data from files
- // String yourInputString = readFile(SPIFFS, "/inputString.txt");
- // int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
- // float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
});
server.onNotFound(notFound);
server.begin();
@@ -360,26 +443,51 @@ void loop() {
//arduinomorse
//sender.continueSending();
- //String yourInputString = readFile(SPIFFS, "/inputString.txt");
- //int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
- // float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
+ // See which message we are sending
+ // Only do this when the message has been updated.
+ if(yourInputMsg != yourInputMsg_old){
+ //morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update();
+ if(yourInputMsg == 0){
+ morseToSend = morseCQ;
+ } else if(yourInputMsg == 1){
+ morseToSend = morseMOE;
+ } else if(yourInputMsg == 2){
+ morseToSend = morseMOI;
+ } else if(yourInputMsg == 3){
+ morseToSend = morseMOS;
+ } else if(yourInputMsg == 4){
+ morseToSend = morseMOH;
+ } else if(yourInputMsg == 5){
+ morseToSend = morseMO5;
+ }
+ }
- // if you want to send code, and it's not sending, then start it up
- if((yourInputInt != 0) & (morseLed.IsRunning() == false)){
+
+ // if you want to send continuous code, and it's not sending, then start it up
+ if((yourInputSend == 1) & (morseToSend.IsRunning() == false)){
//jled
- morseLed.Reset().Update();
+ morseToSend.Reset().Update();
//morse.send("CQ CQ CQ DE W1CDN K"); //etherkit morse
//telegraph26.send("CQ CQ CQ DE W1CDN K"); //telegraph
- // if you want to send code, and it is sending, keep sending
- } else if((yourInputInt != 0) & (morseLed.IsRunning() == true)){
- morseLed.Update();
+ // if you want to send continuous code, and it is sending, keep sending
+ } else if((yourInputSend == 1) & (morseToSend.IsRunning() == true)){
+ morseToSend.Update();
+
+ // if you want to send cycle code and it is sending, keep sending
+ } else if((yourInputSend == 2) & (morseToSend.IsRunning() == true)){
+ morseToSend.Update();
+
+ // if you want to send cycle code and it's not sending, then start it up
+ } else if((yourInputSend == 2) & (morseToSend.IsRunning() == true)){
+ morseToSend.Reset().Update();
+
// if you don't want to send code
} else {
// stop sending and make sure the pin is off
- morseLed.Stop(JLed::eStopMode::FULL_OFF).Update();
+ morseToSend.Stop(JLed::eStopMode::FULL_OFF).Update();
}
- morseLed.Update();
+ morseToSend.Update();
@@ -398,18 +506,4 @@ void loop() {
// output26State = "off";
// }
-
-// // To access your stored values on inputString, inputInt, inputFloat
-// String yourInputString = readFile(SPIFFS, "/inputString.txt");
-// Serial.print("*** Your inputString: ");
-// Serial.println(yourInputString);
-
-// int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
-// Serial.print("*** Your inputInt: ");
-// Serial.println(yourInputInt);
-
-// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
-// Serial.print("*** Your inputFloat: ");
-// Serial.println(yourInputFloat);
-// delay(5000);
}
\ No newline at end of file