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.

77 lines
2.7 KiB

12 months ago
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "stm32basic/stm32basic.hpp"
  5. #include "stm32components/stm32components.hpp"
  6. namespace iflytop {
  7. #define PXX_PRESSURE_SENSOR_NUM 10
  8. class HPP272 {
  9. public:
  10. #pragma pack(1)
  11. typedef struct {
  12. uint16_t hydrogen_peroxide_volume; // ppm 0x0100
  13. uint16_t h2o_h2o2_rs; // %RS * 100
  14. uint16_t temperature1; // °C * 100
  15. uint16_t relative_humidity; // %RH * 100
  16. uint16_t absolute_hydrogen_peroxide; // mg/m3
  17. uint16_t h2o_h2o2dew_point_temperature; // °C * 100
  18. uint16_t reserved1; //
  19. uint16_t water_volume; // ppm
  20. uint16_t water_vapor_pressure; // hpa
  21. uint16_t absolute_humidity; // g/m3
  22. uint16_t water_vapor_saturation_pressure_h2o; // hpa
  23. uint16_t temperature2; // °C * 100
  24. uint16_t h2o2_vapor_pressure; // hpa
  25. uint16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
  26. } hpp272_data_t;
  27. #pragma pack()
  28. private:
  29. /***********************************************************************************************************************
  30. * DATA *
  31. ***********************************************************************************************************************/
  32. ModbusBlockHost* m_modbusBlockHost = NULL;
  33. int32_t m_id = 0;
  34. zmutex m_lock;
  35. hpp272_data_t m_readbuf;
  36. hpp272_data_t m_cachedata;
  37. int32_t m_cache_errorcode = 0;
  38. zmutex m_cache_lock;
  39. public:
  40. /***********************************************************************************************************************
  41. * FUNC *
  42. ***********************************************************************************************************************/
  43. /**
  44. * @brief
  45. *
  46. * @param modbusBlockHost
  47. */
  48. void init(ModbusBlockHost* modbusBlockHost);
  49. bool ping(int id);
  50. bool ping();
  51. void setid(int32_t id);
  52. void read_calibration_date(int32_t* year, int32_t* month, int32_t* day); // TODO
  53. int32_t read_errorcode(); // see datasheet page83
  54. bool read_reg(int32_t add, uint16_t* val, size_t len);
  55. bool read_sensor_data(hpp272_data_t* sensordata);
  56. void updateSensorDataAndErrorcode();
  57. int32_t read_cache_errorcode();
  58. bool read_cache_sensor_data(hpp272_data_t* sensordata);
  59. public:
  60. };
  61. } // namespace iflytop