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

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "base/config_service.hpp"
  4. #include "base/device_info.hpp"
  5. #include "spi.h"
  6. #include "usart.h"
  7. #include "zsdk/modbus/modbus_block_host.hpp"
  8. #include "zsdk/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp"
  9. #include "zsdk/tmc/ztmc5130.hpp"
  10. #include "zsdk/zadc.hpp"
  11. #include "zsdk/zsdk.hpp"
  12. void hardware_init();
  13. namespace iflytop {
  14. class Hardware {
  15. // 加热片控制
  16. ZGPIO m_Heater_ctrlGpio;
  17. ZGPIO m_Heater_safeCtrlGpio;
  18. ZADC m_Heater_electricCurrentAdc;
  19. ZADC m_Heater_temperatureAdc;
  20. // 鼓风机
  21. ZGPIO m_Blowser_ctrlGpio;
  22. ZGPIO m_Blowser_safeCtrlGpio;
  23. ZADC m_Blowser_electricCurrentAdc;
  24. // 空压机
  25. ZGPIO m_AirCompressor_ctrlGpio;
  26. ZGPIO m_AirCompressor_safeCtrlGpio;
  27. ZADC m_AirCompressor_electricCurrentAdc;
  28. #ifdef H2O2_SENSOR_TYPE_HMP110
  29. ModbusBlockHost m_H2o2Sensor_ModbusBlockHost; //
  30. ZADC m_H2o2Sensor_H2O2Adc; // H2O2传感器控制
  31. HMP110 m_H2o2Sensor_HMP110; // H2O2传感器
  32. int32_t m_h2o2sensor_detectId = -1;
  33. #endif
  34. #ifdef H2O2_SENSOR_TYPE_HPP272
  35. ModbusBlockHost m_H2o2Sensor_ModbusBlockHost; //
  36. HPP272 m_H2o2Sensor_HPP272; // H2O2传感器
  37. int32_t m_h2o2sensor_detectId = -1;
  38. #endif
  39. public:
  40. static Hardware& ins() {
  41. static Hardware ins;
  42. return ins;
  43. }
  44. void init();
  45. void heater_ctrl(int32_t val) { m_Heater_ctrlGpio.write(val); }
  46. void heater_ctrl_safe_valve(int32_t val) { m_Heater_safeCtrlGpio.write(val); }
  47. int32_t heater_read_electric_current() {
  48. int32_t adcv = m_Heater_electricCurrentAdc.getCacheVal();
  49. int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
  50. return ma;
  51. }
  52. int32_t heater_read_temperature_data() {
  53. int32_t adcv = m_Heater_temperatureAdc.getCacheVal();
  54. int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
  55. int32_t temp = (ma - 4) / (20 - 4) * (3000 - 0) + 0;
  56. return temp; // C*10
  57. }
  58. void blower_ctrl(int32_t val) { m_Blowser_ctrlGpio.write(val); }
  59. void blower_ctrl_safe_valve(int32_t val) { m_Blowser_safeCtrlGpio.write(val); }
  60. int32_t blower_read_electric_current() {
  61. int32_t adcv = m_Heater_electricCurrentAdc.getCacheVal();
  62. int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
  63. return ma;
  64. }
  65. void air_compressor_ctrl(int32_t val) { m_AirCompressor_ctrlGpio.write(val); }
  66. void air_compressor_ctrl_safe_valve(int32_t val) { m_AirCompressor_safeCtrlGpio.write(val); }
  67. int32_t air_compressor_read_electric_current() {
  68. int32_t adcv = m_AirCompressor_electricCurrentAdc.getCacheVal();
  69. int32_t ma = (adcv / 4095.0 * 3.3 * 1000) / 150.0;
  70. return ma;
  71. }
  72. bool h2o2_sensor_is_online();
  73. int32_t h2o2_sensor_read_calibration_date(int32_t* year, int32_t* month, int32_t* day);
  74. int32_t h2o2_sensor_read_sub_ic_errorcode();
  75. int32_t h2o2_sensor_read_sub_ic_reg(int32_t add, uint16_t* val, size_t len);
  76. int32_t h2o2_sensor_data(report_h2o2_data_t* sensorData);
  77. public:
  78. void onAdcCaptureThread();
  79. void onH2O2CaptureThread();
  80. };
  81. } // namespace iflytop