diff --git a/src/button.cpp b/src/button.cpp index 735388d02519424722509fe719b319eeb0bf782b..da05e54a72c7de67ece8607354cb82307016e1a9 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -5,6 +5,7 @@ #include "button.h" #include "utils.h" #include "led.h" +#include "settings.h" InterruptButton button(PIN_BUTTON, HIGH); @@ -12,13 +13,13 @@ void handleShortButton() { if (!sendingEnabled) { - logLine("Starting to send. (Region: "+ String(region)+")"); + logLine("BUTTON: Starting to send. (Region: "+ String(region)+")"); blink(1); digitalWrite(PIN_LED, HIGH); } else { - logLine("Restarting sending."); + logLine("BUTTON: Restarting sending."); blink(1); digitalWrite(PIN_LED, HIGH); cancelSending = true; @@ -36,7 +37,8 @@ void handleDoubleButton() { region = EU; blink(1); } - logLine("Switching Region to: " + String(region)); + logLine("BUTTON: Switching Region to: " + String(region)); + saveSettings(); if (sendingEnabled) { digitalWrite(PIN_LED, HIGH); @@ -48,7 +50,7 @@ void handleLongButton() { if (sendingEnabled) { - logLine("Stopping sending."); + logLine("BUTTON: Stopping sending."); sendingEnabled = false; cancelSending = true; blink(3); diff --git a/src/ir.cpp b/src/ir.cpp index 298397db3a72f40baf98324f98f5fc583ff48a06..d24e1db248054837f36265dda14104cc99d4ce2a 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3,6 +3,7 @@ #include <IRsend.h> #include "config.h" +#include "utils.h" #include "WORLD_IR_CODES.h" #define MAX_WAIT_TIME 65535 // tens of us (ie: 655.350ms) @@ -82,9 +83,12 @@ void sendAllCodes(uint8_t region) num_codes = num_NAcodes; } + logLine("IR: Sending " + String(num_codes) + " codes for region " + String(region) + "."); + // for every POWER code in our collection for (i = 0; i < num_codes; i++) { + logLine("IR: Sending code: " + String(i + 1)); // make sure all loop() handlers are still ran while sending callHandlers(); @@ -132,7 +136,6 @@ void sendAllCodes(uint8_t region) // Send Code with library irsend.sendRaw(rawData, (numpairs * 2), freq); - Serial.print("\n"); yield(); // Flush remaining bits, so that next code starts // with a fresh set of 8 bits. @@ -144,11 +147,14 @@ void sendAllCodes(uint8_t region) if (cancelSending) { cancelSending = false; + logLine("IR: Cancelling sending codes."); break; // exit the POWER code "for" loop } } // end of POWER code for loop + logLine("IR: Finished sending codes."); + } // end of sendAllCodes void setupIR() diff --git a/src/led.cpp b/src/led.cpp index b8f02caaf1be16a6361b8bfe7b75e534a67a8dd7..cad90a16f896855b648217b6f371b9949160c450 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -1,9 +1,11 @@ #include <Arduino.h> #include "led.h" #include "config.h" +#include "utils.h" void blink(int count) { + logLine("LED: Blinking " +String(count)+ " times."); digitalWrite(PIN_LED, LOW); delay(200); for (int i = 0; i < count; i++) diff --git a/src/main.cpp b/src/main.cpp index b7dbcb934cf6c6da844822e6c7aed0e44f2ec28e..53fd393793c34d76d8dfa0f4db02e1c33243c686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "ota.h" #include "network.h" #include "ir.h" +#include "settings.h" bool sendingEnabled = false; bool cancelSending = false; @@ -17,6 +18,7 @@ void setup() { Serial.begin(115200); Serial.println(); + loadSettings(); setupWifi(); setupOTA(); setupTelnet(); diff --git a/src/ota.cpp b/src/ota.cpp index ec34f5410aa3056732437d18a53dc91e7df7f920..555f174547bd33c186047d9845eff0637076e711 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -3,6 +3,7 @@ #include <ESPmDNS.h> #include "config.h" +#include "utils.h" void setupOTA() { @@ -17,24 +18,24 @@ void setupOTA() } // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() - Serial.println("Start updating " + type); }) + logLine("Start updating " + type); }) .onEnd([]() - { Serial.println("\nEnd"); }) + { logLine("End"); }) .onProgress([](unsigned int progress, unsigned int total) - { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }) + { logLine("OTA: " + (String)ceil(progress / (total / 100)) + "%"); }) .onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) { - Serial.println("Auth Failed"); + logLine("Auth Failed"); } else if (error == OTA_BEGIN_ERROR) { - Serial.println("Begin Failed"); + logLine("Begin Failed"); } else if (error == OTA_CONNECT_ERROR) { - Serial.println("Connect Failed"); + logLine("Connect Failed"); } else if (error == OTA_RECEIVE_ERROR) { - Serial.println("Receive Failed"); + logLine("Receive Failed"); } else if (error == OTA_END_ERROR) { - Serial.println("End Failed"); + logLine("End Failed"); } }); ArduinoOTA.setHostname(HOSTNAME); ArduinoOTA.begin(); diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef6a3c7c64013611caf80cf2b516de72adc06a52 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,25 @@ +#include <Arduino.h> +#include <Preferences.h> + +Preferences preferences; + +extern uint8_t region; + +void loadSettings() { + preferences.begin("settings", true); // true = readonly + region = (uint8_t)preferences.getUInt("region", 0); + preferences.end(); +} + +void saveSettings() { + preferences.begin("settings", false); + preferences.putUInt("region", region); + preferences.end(); +} + +void clearSettings() { + preferences.begin("settings", false); + preferences.clear(); + preferences.end(); + ESP.restart(); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000000000000000000000000000000000000..6b00907c620fcac7d5be8ecf40d1f8bdc1b1c7a6 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,8 @@ +#include <Arduino.h> +#include <Preferences.h> + +extern uint8_t region; + +void loadSettings(); +void saveSettings(); +void clearSettings();