TSYS01.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * I2C driver for Measurement Specialties MEAS TSYS01 digital temperature sensor
  3. */
  4. #pragma once
  5. #include <AP_HAL/AP_HAL.h>
  6. #include <AP_HAL/Semaphores.h>
  7. #include <AP_HAL/Device.h>
  8. #define TSYS01_ADDR 0x77
  9. class TSYS01 {
  10. public:
  11. bool init(uint8_t bus);
  12. float temperature(void) { return _temperature; } // temperature in degrees C
  13. bool healthy(void) { // do we have a valid temperature reading?
  14. #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
  15. return true;
  16. #endif
  17. return _healthy;
  18. }
  19. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  20. private:
  21. #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
  22. float _temperature = 42.42; // degrees C
  23. #else
  24. float _temperature; // degrees C
  25. #endif
  26. bool _healthy; // we have a valid temperature reading to report
  27. uint16_t _k[5]; // internal calibration for temperature calculation
  28. bool _reset(void); // reset device
  29. bool _read_prom(void); // read (relevant) internal calibration registers into _k
  30. bool _convert(void); // begin an ADC conversion (min:7.40ms typ:8.22ms max:9.04ms)
  31. uint32_t _read_adc(void);
  32. uint16_t _read_prom_word(uint8_t word);
  33. void _timer(void); // update the temperature, called at 20Hz
  34. void _calculate(uint32_t adc); // calculate temperature using adc reading and internal calibration
  35. };