diff --git a/RotaxMonitor/src/main.cpp b/RotaxMonitor/src/main.cpp index 2b15435..546d435 100644 --- a/RotaxMonitor/src/main.cpp +++ b/RotaxMonitor/src/main.cpp @@ -16,11 +16,11 @@ #include #include -//#define CH_A_ENABLE -//#define CH_B_ENABLE +// #define CH_A_ENABLE +// #define CH_B_ENABLE #define CH_A_RT_ENABLE #define CH_B_RT_ENABLE -//#define I2C_ENABLE +// #define I2C_ENABLE #define WEB_ENABLE // Debug Defines @@ -28,6 +28,7 @@ #define WIFI_PASSWORD "maledettirotax" #define PSRAM_MAX 4096 #define QUEUE_MAX 128 +#define HTOP_DELAY 2000 void setup() { @@ -276,21 +277,52 @@ void loop() AstroWebServer webPage(80, LittleFS); delay(100); +#ifdef CH_A_RT_ENABLE task_A.onMessage([&webPage, &json_data, &data_a](ignitionBoxStatusFiltered sts) { json_data["box_a"] = sts.toJson(); data_a = true; }); +#endif - #ifdef CH_B_RT_ENABLE +#ifdef CH_B_RT_ENABLE task_B.onMessage([&webPage, &json_data, &data_b](ignitionBoxStatusFiltered sts) { json_data["box_b"] = sts.toJson(); data_b = true; }); - #endif #endif - task_A.enableSave(true, "ignitionA_test.csv"); - task_B.enableSave(true, "ignitionB_test.csv"); + webPage.registerWsCommand("saveEnable", [&task_A, &task_B](const ArduinoJson::JsonDocument &doc) { + if(!doc["params"].is()) return; + if(!doc["filename_a"].is() ||!doc["filename_b"].is()){ + LOG_ERROR("saveEnable invalid or missing filenames"); + return; + } + + task_A.enableSave(true, doc["filename_a"].as()); + task_B.enableSave(true, doc["filename_a"].as()); + return; }); + + webPage.registerWsCommand("saveDisable", [&task_A, &task_B](const ArduinoJson::JsonDocument &doc) { + task_A.enableSave(false, ""); + task_B.enableSave(false, ""); }); + + webPage.registerWsCommand("downloadHistory", [](const ArduinoJson::JsonDocument &doc) { + LOG_WARN("Command downloadHistory not Implemented"); + }); + + webPage.registerWsCommand("clearHistory", [](const ArduinoJson::JsonDocument &doc) { + LOG_WARN("Command clearHistory not Implemented"); + }); + + webPage.registerWsCommand("startTest", [](const ArduinoJson::JsonDocument &doc) { + LOG_WARN("Command startTest not Implemented"); + }); + + webPage.registerWsCommand("stopTest", [](const ArduinoJson::JsonDocument &doc) { + LOG_WARN("Command stopTest not Implemented"); + }); + +#endif uint32_t monitor_loop = millis(); uint32_t data_loop = monitor_loop; @@ -298,21 +330,21 @@ void loop() while (running) { uint32_t this_loop = millis(); - if (this_loop - monitor_loop > 5000) + if (this_loop - monitor_loop > HTOP_DELAY) { clearScreen(); printRunningTasksMod(Serial); monitor_loop = millis(); } - vTaskDelay(pdMS_TO_TICKS(10)); -#ifdef WEB_ENABLE - if ((data_a && data_b) || (this_loop - data_loop > 500)) + #ifdef WEB_ENABLE + if ((data_a && data_b) || ((this_loop - data_loop > 500) && (data_b || data_b))) { webPage.sendWsData(json_data.as()); json_data.clear(); data_a = data_b = false; data_loop = millis(); } + vTaskDelay(pdMS_TO_TICKS(10)); #endif } //////////////// INNER LOOP /////////////////////