|
|
#pragma once
#include "base/appdep.hpp"
namespace iflytop { using namespace transmit_disfection_protocol;
class HeaterController { ZGPIO m_ctrlGpio; ZADC m_iAdc; ZADC m_tempAdc; bool m_isInitialized = false;
public: void initialize(Pin_t ctrlGpio, ADC_HandleTypeDef* iadc, uint32_t ich, ADC_HandleTypeDef* tadc, uint32_t tch) { m_ctrlGpio.initAsOutput(ctrlGpio, kxs_gpio_nopull, true, false); m_iAdc.initialize("heater-idac", iadc, ich); m_tempAdc.initialize("heater-tadc", iadc, tch); m_isInitialized = true; AppPeriodTaskMgr::ins()->regTask("Heater-ADC", [this]() { periodTask(); }, 1000);
BIND_FN(HeaterController, this, fn_heater_ctrl); BIND_FN(HeaterController, this, fn_heater_ctrl_safe_valve); BIND_FN(HeaterController, this, fn_heater_read_ei); BIND_FN(HeaterController, this, fn_heater_read_temperature_data); BIND_FN(HeaterController, this, fn_heater_read_ei_adc_raw); BIND_FN(HeaterController, this, fn_heater_read_temperature_data_adc_raw); BIND_FN(HeaterController, this, fn_heater_is_open); }
bool isInitialized() { return m_isInitialized; }
void heater_ctrl(int32_t val) { m_ctrlGpio.write(val); } void heater_ctrl_safe_valve(int32_t val) {} int32_t heater_read_temperature_data() { return heaterAdc2Temp(m_tempAdc.getCacheVal()); } int32_t heater_read_ei() { return hearterAdcToCurrent(m_iAdc.getCacheVal()); } int32_t heater_read_iadc() { return m_iAdc.getCacheVal(); } int32_t heater_read_tadc() { return m_tempAdc.getCacheVal(); }
// PP
void fn_heater_ctrl(ProcessContext* cxt) { //
heater_ctrl(GET_PARAM(0)); zcanbus_send_ack(cxt->packet, NULL, 0); } void fn_heater_ctrl_safe_valve(ProcessContext* cxt) { //
heater_ctrl_safe_valve(GET_PARAM(0)); zcanbus_send_ack(cxt->packet, NULL, 0); } void fn_heater_read_ei(ProcessContext* cxt) { //
auto val = heater_read_ei(); zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); } void fn_heater_read_temperature_data(ProcessContext* cxt) { //
auto val = heater_read_temperature_data(); zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); }
void fn_heater_read_ei_adc_raw(ProcessContext* cxt) { //
auto val = m_iAdc.getCacheVal(); zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); }
void fn_heater_read_temperature_data_adc_raw(ProcessContext* cxt) { //
auto val = m_tempAdc.getCacheVal(); zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); } void fn_heater_is_open(ProcessContext* cxt) { //
zcanbus_send_ack(cxt->packet, m_ctrlGpio.read()); }
private: void periodTask() { m_iAdc.updateAdcValToCache(); m_tempAdc.updateAdcValToCache(); } }; } // namespace iflytop
|