forked from EmbeddedTeam/app_photomagnetic
- Add CONFIG_SAMPLE_NTC to CMakeLists.txt and Kconfig - Implement PI temperature controller with PWM output in heating.hpp - Convert NtcGroup from template to non-template class - Add LED helper class with flash support - Implement COM protocol handlers for device ID and running state - Add SPI, sensor, and PWM configuration to prj.conf - Remove indicator overlay and update main.cpp with temperature monitoring - Add test script for serial protocol communication
61 lines
1.8 KiB
C++
61 lines
1.8 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 };
|
|
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) {
|
|
InfLed::On();
|
|
} else {
|
|
InfLed::Off();
|
|
}
|
|
s_led_strip_indicator->Status(data[0]);
|
|
}
|
|
};
|
|
constexpr static std::pair<const uint8_t,
|
|
uart_com::SimpleProtocal::CallbackType>
|
|
kRxCallbackTable[] = {{GET_ID, Cb::GetId},
|
|
{RUNNING_STATE, Cb::RunningState}};
|
|
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)));
|
|
using InfLed = ther::Led<LED_DT_SPEC_GET(DT_NODELABEL(inf_led))>;
|
|
};
|
|
} // namespace ther
|
|
|
|
#endif
|