You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
3.0 KiB

#include <stddef.h>
#include <stdio.h>
#include "base/config_service.hpp"
#include "base/device_info.hpp"
#include "spi.h"
#include "usart.h"
#include "zsdk/modbus/modbus_block_host.hpp"
#include "zsdk/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp"
#include "zsdk/tmc/ztmc5130.hpp"
#include "zsdk/zadc.hpp"
#include "zsdk/zsdk.hpp"
void hardware_init();
namespace iflytop {
class Hardware {
// 加热片控制
ZGPIO m_Heater_ctrlGpio;
ZGPIO m_Heater_safeCtrlGpio;
ZADC m_Heater_electricCurrentAdc;
ZADC m_Heater_temperatureAdc;
// 鼓风机
ZGPIO m_Blowser_ctrlGpio;
ZGPIO m_Blowser_safeCtrlGpio;
ZADC m_Blowser_electricCurrentAdc;
// 空压机
ZGPIO m_AirCompressor_ctrlGpio;
ZGPIO m_AirCompressor_safeCtrlGpio;
ZADC m_AirCompressor_electricCurrentAdc;
#ifdef H2O2_SENSOR_TYPE_HMP110
ModbusBlockHost m_H2o2Sensor_ModbusBlockHost; //
ZADC m_H2o2Sensor_H2O2Adc; // H2O2传感器控制
HMP110 m_H2o2Sensor_HMP110; // H2O2传感器
int32_t m_h2o2sensor_detectId = -1;
#endif
#ifdef H2O2_SENSOR_TYPE_HPP272
ModbusBlockHost m_H2o2Sensor_ModbusBlockHost; //
HPP272 m_H2o2Sensor_HPP272; // H2O2传感器
int32_t m_h2o2sensor_detectId = -1;
#endif
public:
static Hardware& ins() {
static Hardware ins;
return ins;
}
void init();
void heater_ctrl(int32_t val) { m_Heater_ctrlGpio.write(val); }
void heater_ctrl_safe_valve(int32_t val) { m_Heater_safeCtrlGpio.write(val); }
int32_t heater_read_electric_current() {
int32_t adcv = m_Heater_electricCurrentAdc.getCacheVal();
int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
return ma;
}
int32_t heater_read_temperature_data() {
int32_t adcv = m_Heater_temperatureAdc.getCacheVal();
int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
int32_t temp = (ma - 4) / (20 - 4) * (3000 - 0) + 0;
return temp; // C*10
}
void blower_ctrl(int32_t val) { m_Blowser_ctrlGpio.write(val); }
void blower_ctrl_safe_valve(int32_t val) { m_Blowser_safeCtrlGpio.write(val); }
int32_t blower_read_electric_current() {
int32_t adcv = m_Heater_electricCurrentAdc.getCacheVal();
int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
return ma;
}
void air_compressor_ctrl(int32_t val) { m_AirCompressor_ctrlGpio.write(val); }
void air_compressor_ctrl_safe_valve(int32_t val) { m_AirCompressor_safeCtrlGpio.write(val); }
int32_t air_compressor_read_electric_current() {
int32_t adcv = m_AirCompressor_electricCurrentAdc.getCacheVal();
int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
return ma;
}
bool h2o2_sensor_is_online();
int32_t h2o2_sensor_read_calibration_date(int32_t* year, int32_t* month, int32_t* day);
int32_t h2o2_sensor_read_sub_ic_errorcode();
int32_t h2o2_sensor_read_sub_ic_reg(int32_t add, uint16_t* val, size_t len);
int32_t h2o2_sensor_data(report_h2o2_data_t* sensorData);
public:
void onAdcCaptureThread();
void onH2O2CaptureThread();
};
} // namespace iflytop