diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6a2efba..ef94533 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -49,6 +49,7 @@ set(headers cloudtexthelpers.h controller.h debugcolorhelpers.h + debuginputhandler.h debugtexthelpers.h displays/bmsdisplay.h displays/calibratedisplay.h @@ -186,7 +187,6 @@ set(headers rotary.h screens.h serial.h - serialhandler.h settings.h settingspersister.h settingsutils.h @@ -264,6 +264,7 @@ set(sources cloudtexthelpers.cpp controller.cpp debugcolorhelpers.cpp + debuginputhandler.cpp debugtexthelpers.cpp displays/bmsdisplay.cpp displays/calibratedisplay.cpp @@ -402,7 +403,6 @@ set(sources rotary.cpp screens.cpp serial.cpp - serialhandler.cpp settings.cpp settingspersister.cpp settingsutils.cpp diff --git a/main/debuginputhandler.cpp b/main/debuginputhandler.cpp new file mode 100644 index 0000000..6a54445 --- /dev/null +++ b/main/debuginputhandler.cpp @@ -0,0 +1,127 @@ +#include "debuginputhandler.h" + +// Arduino includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "globals.h" +#include "utils.h" +#include "screens.h" +#include "buttons.h" + +using namespace espgui; + +//wl_status_t last_status; +//IPAddress last_ip; + +void initDebugInput() +{ + Serial.begin(115200); + //Serial.setDebugOutput(true); +} + +void handleDebugInput() +{ + //const auto status = WiFi.status(); + //if (last_status != status) + //{ + //Serial.print("Status changed to: "); + //Serial.println(to_string(status).c_str()); + //last_status = status; + //} + + //const auto ip = WiFi.localIP(); + //if (last_ip != ip) + //{ + //Serial.print("IP changed to: "); + //Serial.println(to_string(ip).c_str()); + //last_ip = ip; + //} + + while(Serial.available()) + { + const auto c = Serial.read(); + + switch (c) + { + case 'i': + case 'I': + tft.init(); + break; + case 'p': + case 'P': + { + const auto firstPower = controllers.front.command.poweroff; + for (Controller &controller : controllers) + controller.command.poweroff = !firstPower; + break; + } + case 'l': + case 'L': + { + const auto firstLed = controllers.front.command.led; + for (Controller &controller : controllers) + controller.command.led = !firstLed; + break; + } + case 'r': + case 'R': + loadSettings(); + break; + case 's': + case 'S': + saveSettings(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + for (Controller &controller : controllers) + controller.command.buzzer.freq = c-'0'; + break; + case 'A': + InputDispatcher::rotate(-1); + break; + case 'B': + InputDispatcher::rotate(1); + break; + case 'C': + InputDispatcher::confirmButton(true); + InputDispatcher::confirmButton(false); + break; + case 'D': + InputDispatcher::backButton(true); + InputDispatcher::backButton(false); + break; + case 'z': + case 'Z': +#ifndef LEDSTRIP_WRONG_DIRECTION + InputDispatcher::blinkLeftButton(true); + InputDispatcher::blinkLeftButton(false); +#else + InputDispatcher::blinkRightButton(true); + InputDispatcher::blinkRightButton(false); +#endif + break; + case 'u': + case 'U': +#ifndef LEDSTRIP_WRONG_DIRECTION + InputDispatcher::blinkRightButton(true); + InputDispatcher::blinkRightButton(false); +#else + InputDispatcher::blinkLeftButton(true); + InputDispatcher::blinkLeftButton(false); +#endif + break; + } + } +} diff --git a/main/serialhandler.h b/main/debuginputhandler.h similarity index 61% rename from main/serialhandler.h rename to main/debuginputhandler.h index 87e8aff..8d44fcf 100644 --- a/main/serialhandler.h +++ b/main/debuginputhandler.h @@ -3,4 +3,5 @@ //extern wl_status_t last_status; //extern IPAddress last_ip; -void handleSerial(); +void initDebugInput(); +void handleDebugInput(); diff --git a/main/main.cpp b/main/main.cpp index 3bd9b84..3b17cff 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -25,7 +25,6 @@ using namespace std::chrono_literals; #include "macros_bobbycar.h" #include "globals.h" #include "screens.h" -#include "serialhandler.h" #ifdef FEATURE_OTA #include "ota.h" #include "displays/menus/selectbuildservermenu.h" @@ -79,10 +78,6 @@ std::optional lastLedstripUpdate; extern "C" void app_main() { - Serial.begin(115200); - //Serial.setDebugOutput(true); - //Serial.println("setup()"); - #ifdef FEATURE_LEDBACKLIGHT pinMode(PINS_LEDBACKLIGHT, OUTPUT); digitalWrite(PINS_LEDBACKLIGHT, ledBacklightInverted ? LOW : HIGH); @@ -260,8 +255,6 @@ extern "C" void app_main() controller.parser.update(); #endif - handleSerial(); - #ifdef FEATURE_OTA handleOta(); #endif diff --git a/main/taskmanager.cpp b/main/taskmanager.cpp index f99325d..e8ce310 100644 --- a/main/taskmanager.cpp +++ b/main/taskmanager.cpp @@ -44,6 +44,7 @@ #ifdef FEATURE_CAN #include "can.h" #endif +#include "debuginputhandler.h" using namespace std::chrono_literals; @@ -85,6 +86,7 @@ espcpputils::SchedulerTask schedulerTasksArr[] { #ifdef FEATURE_CAN espcpputils::SchedulerTask { "can", can::initCan, can::parseCanInput, 50ms }, #endif + espcpputils::SchedulerTask { "debuginput", initDebugInput, handleDebugInput, 50ms }, }; } // namespace