forked from EmbeddedTeam/app_photomagnetic
- Remove heating and NTC functionality from communication module - Convert Infrared from template to runtime array-based implementation - Refactor Led to support multiple LEDs with compile-time name validation - Simplify main to remove direct hardware initialization - Update west manifest for dr2501a board and add ch9438 module
109 lines
3.3 KiB
C++
109 lines
3.3 KiB
C++
#ifndef __THER_COM_HPP__
|
|
#define __THER_COM_HPP__
|
|
|
|
#include "led.hpp"
|
|
#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:
|
|
static auto Init() -> zpp::error {
|
|
s_proto->SetRxCallbackTable(kRxCallbackTable);
|
|
return zpp::ok();
|
|
}
|
|
static auto Send(sensor_value val) -> void {
|
|
const uint8_t temp_data[] = {(uint8_t)val.val1, (uint8_t)val.val2};
|
|
s_proto->Send(TEMP, temp_data);
|
|
}
|
|
|
|
private:
|
|
enum HostStatus : uint8_t { STANDBY, RUNNING, PAUSE, ERROR };
|
|
enum Addr : uint8_t {
|
|
TEMP = 0,
|
|
GET_ID,
|
|
RUNNING_STATE,
|
|
W_HEATING_STATE,
|
|
R_HEATING_STATE
|
|
};
|
|
enum DevAddr : uint8_t {
|
|
R_TEMP_POLE_NTC = 100,
|
|
R_TEMP_HETING_PAD_NTC = 101,
|
|
};
|
|
using CbTableValueType =
|
|
std::pair<const uint8_t, void (*)(uart_com::DataType)>;
|
|
struct Cb {
|
|
static auto GetId(uart_com::DataType data) -> void {
|
|
printk("handle get id");
|
|
uint8_t buff[20];
|
|
auto size = hwinfo_get_device_id(buff, sizeof(buff));
|
|
s_proto->Send(GET_ID, uart_com::DataType(buff, size));
|
|
}
|
|
static auto RunningState(uart_com::DataType data) -> void {
|
|
if (data.size() != 1) {
|
|
return;
|
|
}
|
|
if (data[0] == RUNNING) {
|
|
} else {
|
|
}
|
|
printk("set ledsrtip to %d", data[0]);
|
|
const uint8_t id = data[0];
|
|
s_led_strip_indicator->Status(id).on_error([](zpp::error_code err) {
|
|
printk("err code: %s", zpp::error_str(err));
|
|
});
|
|
}
|
|
static auto WHeatingState(uart_com::DataType data) -> void {
|
|
// if (data.size() != 1) {
|
|
// return;
|
|
// }
|
|
// const bool state = (data[0] > 0);
|
|
// if (state) {
|
|
// HeatingPad::Start(sensor_value{data[0], 0});
|
|
// } else {
|
|
// HeatingPad::Stop();
|
|
// }
|
|
}
|
|
static auto RHeatingState(uart_com::DataType data) -> void {
|
|
// if (data.size() != 0) {
|
|
// return;
|
|
// }
|
|
// const sensor_value temp = HeatingPad::CurrentTemp();
|
|
// const uint8_t state[] = {s_heating_state, (uint8_t)temp.val1,
|
|
// (uint8_t)temp.val2};
|
|
// s_proto->Send(R_HEATING_STATE, state);
|
|
}
|
|
/// Read one pole NTC by index (0~7).
|
|
static auto ReadPoleNtcTemperature(uart_com::DataType data) -> void {
|
|
if (data.size() != 1) {
|
|
return;
|
|
}
|
|
}
|
|
/// Read heating pad NTC (onboard ADC).
|
|
static auto ReadHeatingPadNtcTemperature(uart_com::DataType data) -> void {}
|
|
};
|
|
constexpr static std::pair<const uint8_t,
|
|
uart_com::SimpleProtocal::CallbackType>
|
|
kRxCallbackTable[] = {
|
|
{GET_ID, Cb::GetId},
|
|
{RUNNING_STATE, Cb::RunningState},
|
|
{W_HEATING_STATE, Cb::WHeatingState},
|
|
{R_HEATING_STATE, Cb::RHeatingState},
|
|
// Pole NTC (MCP3208)
|
|
{R_TEMP_POLE_NTC, Cb::ReadPoleNtcTemperature},
|
|
// Heating pad NTC (ADC1)
|
|
{R_TEMP_HETING_PAD_NTC, Cb::ReadHeatingPadNtcTemperature},
|
|
};
|
|
inline static auto s_led_strip_indicator =
|
|
ZPP_DRV_GET_P(ledstrip::Indicator, DT_NODELABEL(indicator));
|
|
inline static auto s_proto =
|
|
(uart_com::SimpleProtocal *)(DEVICE_DT_GET(DT_NODELABEL(pm_protocal)));
|
|
inline static auto s_heating_state = false;
|
|
};
|
|
} // namespace ther
|
|
|
|
#endif
|