#include #include #include #include #include #include #include "watchdog.hpp" #include "zpp/fmt.hpp" namespace { auto sensor = DEVICE_DT_GET(DT_NODELABEL(godtek)); auto &pmc = ZPP_DRV_GET(uart_com::Protocal, DT_NODELABEL(pm_protocal)); auto &led_strip = ZPP_DRV_GET(ledstrip::Indicator, DT_NODELABEL(indicator)); enum Command { kTemp = 0x00, kGetId, kRunningState }; enum RunningState {}; constexpr auto kDeviceIdSize = 20; enum StatusId : uint8_t { kStandby, kRunning, kPause, kError }; volatile bool flag{false}; } // namespace auto main(void) -> int { pmc.SetRxCallback(kGetId, [](uart_com::DataType data) -> void { uint8_t buffer[kDeviceIdSize]; auto size = hwinfo_get_device_id(buffer, sizeof(buffer)); pmc.Send(kGetId, uart_com::DataType(buffer, size)); }); pmc.SetRxCallback(kRunningState, [](uart_com::DataType data) -> void { auto state = static_cast(data[0]); pmc.Send( kRunningState, uart_com::DataType(reinterpret_cast(&state), sizeof(state))); led_strip.Status(state).on_error([](zpp::error_code code) {}); }); auto wdt = app::WatchDogConfig{}; sensor_trigger tri{.type = SENSOR_TRIG_DATA_READY, .chan = SENSOR_CHAN_AMBIENT_TEMP}; if (auto r = sensor_trigger_set( sensor, &tri, [](const device *dev, const sensor_trigger *trig) { flag = true; }); r != 0) { return -ENODEV; }; while (1) { if (flag) { sensor_value val{0, 0}; if (sensor_sample_fetch_chan(sensor, SENSOR_CHAN_AMBIENT_TEMP) == 0) { sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &val); const uint8_t data[2] = {static_cast(val.val1), static_cast(val.val2)}; pmc.Send("temp", data); } flag = false; } wdt.Feed(); } return 0; }