forked from EmbeddedTeam/app_photomagnetic
Restructure Led as a template on the DT spec, add a generic signal/slot mechanism for host status, and cache Infrared sensor samples via trigger callbacks. Add new init modules for LED, temp, and watchdog, and build them into the main app.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#ifndef __THER_COM_HPP__
|
|
#define __THER_COM_HPP__
|
|
|
|
#include "led.hpp"
|
|
#include <etl/delegate.h>
|
|
#include <etl/signal.h>
|
|
#include <led_strip_indicator/led_strip_indicator.hpp>
|
|
#include <uart_com/simple_protocal.hpp>
|
|
#include <zephyr/drivers/hwinfo.h>
|
|
#include <zephyr/drivers/sensor.h>
|
|
#include <zpp/driver.hpp>
|
|
#include <zpp/error.hpp>
|
|
namespace ther {
|
|
|
|
class Com {
|
|
public:
|
|
enum HostStatus : uint8_t { STANDBY, RUNNING, PAUSE, ERROR };
|
|
using RunningStateSignal = etl::signal<void(HostStatus), 10>;
|
|
static auto Init() -> zpp::error {
|
|
s_proto->SetRxCallbackTable(kRxCallbackTable);
|
|
auto size = hwinfo_get_device_id(buff, sizeof(buff));
|
|
s_id_buff = etl::span<uint8_t>(buff, size);
|
|
return zpp::ok();
|
|
}
|
|
static auto SendTemp(sensor_value val) -> void {
|
|
const uint8_t temp_data[] = {(uint8_t)val.val1, (uint8_t)val.val2};
|
|
s_proto->Send(R_TEMP, temp_data);
|
|
}
|
|
static auto AddRunningState(RunningStateSignal::slot_type slot) -> bool {
|
|
return s_running_state_sig.connect(slot);
|
|
}
|
|
|
|
private:
|
|
enum Addr : uint8_t {
|
|
R_TEMP = 0,
|
|
R_GET_ID,
|
|
W_RUNNING_STATE,
|
|
};
|
|
inline static RunningStateSignal s_running_state_sig{};
|
|
static auto RunningState(uart_com::DataType data) -> void {
|
|
if (data.size() != 1) {
|
|
return;
|
|
}
|
|
s_running_state_sig(HostStatus(data[0]));
|
|
}
|
|
static auto GetId(uart_com::DataType data) -> void {
|
|
printk("handle get id");
|
|
s_proto->Send(R_GET_ID, uart_com::DataType(s_id_buff));
|
|
};
|
|
|
|
constexpr static std::pair<const uint8_t,
|
|
uart_com::SimpleProtocal::CallbackType>
|
|
kRxCallbackTable[] = {
|
|
{R_GET_ID, GetId},
|
|
{W_RUNNING_STATE, RunningState},
|
|
};
|
|
inline static auto s_proto = (uart_com::SimpleProtocal *)DEVICE_DT_GET(
|
|
DT_COMPAT_GET_ANY_STATUS_OKAY(uart_com_simple_protocal));
|
|
|
|
inline static uint8_t buff[20];
|
|
inline static auto s_heating_state = false;
|
|
inline static etl::span<uint8_t> s_id_buff;
|
|
};
|
|
} // namespace ther
|
|
|
|
#endif
|