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.

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