From fa1b288f4d0476f85baba8af92f924d39d6d3fe6 Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Wed, 30 Jul 2025 16:26:18 +0200 Subject: [PATCH] added setBuzz demo test command --- src/commands.cpp | 15 +++++++++++---- src/commands.h | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 3f6bf6a..9f382cd 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -9,6 +9,13 @@ namespace commands esp_restart(); } + const ArduinoJson::JsonDocument Commands::setBuzz(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms) + { + ArduinoJson::JsonDocument response; + dev.buzzer.beep(500, NOTE_Bb); + return response; + } + // CONFIG // // CONFIG // const ArduinoJson::JsonDocument Commands::setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms) @@ -115,7 +122,7 @@ namespace commands for (const auto &[name, event] : eventMap) { const auto cmd = std::get<0>(event); - response["values"]["name"] = cmd; + response["values"][name] = cmd; eventNum++; } LOG_INFO("getCronJob got [", eventNum, "] events"); @@ -385,7 +392,7 @@ namespace commands } response["values"]["status"] = "valid"; - response["status"]["time"] = rtc.getTimeStr(); + response["values"]["time"] = rtc.getTimeStr(); LOG_INFO("setTimeNTP -> RTC is [", response["status"]["time"].as().c_str(), "]"); @@ -485,10 +492,10 @@ namespace commands auto timeDiff = std::chrono::duration_cast(ntpTimePoint - rtcTimePoint); auto direction = timeDiff.count() >= 0 ? "BEYOND" : "AHEAD"; - response["values"]["drift"] = (uint32_t)timeDiff.count(); + response["values"]["drift"] = (int32_t)timeDiff.count(); response["values"]["direction"] = "RTC is [" + std::string(direction) + "] NTP time"; - LOG_INFO("getTimeDrift -> RTC is [", (uint32_t)timeDiff.count(), "] sec, [", std::string(direction).c_str(), "] NTP time"); + LOG_INFO("getTimeDrift -> RTC is [", (int32_t)timeDiff.count(), "] sec, [", std::string(direction).c_str(), "] NTP time"); return response; } diff --git a/src/commands.h b/src/commands.h index fcca973..6c0fdc0 100644 --- a/src/commands.h +++ b/src/commands.h @@ -64,6 +64,9 @@ namespace commands Commands() = delete; public: + // TEST // + static const ArduinoJson::JsonDocument setBuzz(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms); + // CONFIG // static const ArduinoJson::JsonDocument setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms); static const ArduinoJson::JsonDocument getConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms); @@ -94,6 +97,9 @@ namespace commands }; static const std::map s_commandMap = { + + {"setBuzz", Commands::setBuzz}, + {"setConfig", Commands::setConfig}, {"getConfig", Commands::getConfig},