Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : 16 : /* 17 : * I2C driver for Measurement Specialties MEAS TSYS03 digital temperature sensor 18 : */ 19 : 20 : #pragma once 21 : #include "AP_TemperatureSensor_Backend.h" 22 : 23 : #ifndef AP_TEMPERATURE_SENSOR_TSYS03_ENABLED 24 : #define AP_TEMPERATURE_SENSOR_TSYS03_ENABLED AP_TEMPERATURE_SENSOR_ENABLED 25 : #endif 26 : 27 : #if AP_TEMPERATURE_SENSOR_TSYS03_ENABLED 28 : 29 : #define TSYS03_ADDR_CSB0 0x40 30 : 31 : class AP_TemperatureSensor_TSYS03 : public AP_TemperatureSensor_Backend { 32 : using AP_TemperatureSensor_Backend::AP_TemperatureSensor_Backend; 33 : 34 : public: 35 : __INITFUNC__ void init(void) override; 36 : 37 0 : void update() override {}; 38 : 39 : 40 : private: 41 : // reset device 42 : bool reset(void) const; 43 : 44 : // begin an ADC conversion (min:7.40ms typ:8.22ms max:9.04ms) 45 : void start_next_sample(); 46 : uint16_t read_adc(void) const; 47 : 48 : // update the temperature, called at 20Hz 49 : void _timer(void); 50 : 51 : // calculate temperature using adc reading and internal calibration 52 : float calculate(const uint16_t adc) const; 53 : }; 54 : #endif // AP_TEMPERATURE_SENSOR_TSYS03_ENABLED