2022-09-12 16:48:05 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-11 15:59:59 -03:00
|
|
|
#include "AP_TemperatureSensor_config.h"
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
#if AP_TEMPERATURE_SENSOR_ENABLED
|
|
|
|
|
2022-10-11 15:59:59 -03:00
|
|
|
#include "AP_TemperatureSensor_Params.h"
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
// declare backend class
|
|
|
|
class AP_TemperatureSensor_Backend;
|
|
|
|
class AP_TemperatureSensor_TSYS01;
|
2022-09-26 23:29:13 -03:00
|
|
|
class AP_TemperatureSensor_MCP9600;
|
2023-01-19 18:21:01 -04:00
|
|
|
class AP_TemperatureSensor_MAX31865;
|
2023-07-21 22:22:02 -03:00
|
|
|
class AP_TemperatureSensor_TSYS03;
|
2023-09-22 20:54:19 -03:00
|
|
|
class AP_TemperatureSensor_Analog;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
class AP_TemperatureSensor
|
|
|
|
{
|
|
|
|
friend class AP_TemperatureSensor_Backend;
|
|
|
|
friend class AP_TemperatureSensor_TSYS01;
|
2022-09-26 23:29:13 -03:00
|
|
|
friend class AP_TemperatureSensor_MCP9600;
|
2023-01-19 18:21:01 -04:00
|
|
|
friend class AP_TemperatureSensor_MAX31865;
|
2023-07-21 22:22:02 -03:00
|
|
|
friend class AP_TemperatureSensor_TSYS03;
|
2023-09-22 20:54:19 -03:00
|
|
|
friend class AP_TemperatureSensor_Analog;
|
2024-01-15 19:16:53 -04:00
|
|
|
friend class AP_TemperatureSensor_DroneCAN;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
AP_TemperatureSensor();
|
|
|
|
|
|
|
|
CLASS_NO_COPY(AP_TemperatureSensor);
|
|
|
|
|
|
|
|
static AP_TemperatureSensor *get_singleton() { return _singleton; }
|
|
|
|
|
|
|
|
// Return the number of temperature sensors instances
|
|
|
|
uint8_t num_instances(void) const { return _num_instances; }
|
|
|
|
|
|
|
|
// detect and initialise any available temperature sensors
|
|
|
|
void init();
|
|
|
|
|
|
|
|
// Update the temperature for all temperature sensors
|
|
|
|
void update();
|
|
|
|
|
2022-09-26 20:23:48 -03:00
|
|
|
bool get_temperature(float &temp, const uint8_t instance = AP_TEMPERATURE_SENSOR_PRIMARY_INSTANCE) const;
|
|
|
|
|
|
|
|
bool healthy(const uint8_t instance = AP_TEMPERATURE_SENSOR_PRIMARY_INSTANCE) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
2022-09-26 20:23:48 -03:00
|
|
|
// accessors to params
|
2022-10-11 15:59:59 -03:00
|
|
|
AP_TemperatureSensor_Params::Type get_type(const uint8_t instance = AP_TEMPERATURE_SENSOR_PRIMARY_INSTANCE) const;
|
|
|
|
AP_TemperatureSensor_Params::Source get_source(const uint8_t instance = AP_TEMPERATURE_SENSOR_PRIMARY_INSTANCE) const;
|
2022-09-26 20:23:48 -03:00
|
|
|
int32_t get_source_id(const uint8_t instance = AP_TEMPERATURE_SENSOR_PRIMARY_INSTANCE) const;
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2023-09-22 20:52:42 -03:00
|
|
|
static const struct AP_Param::GroupInfo *backend_var_info[AP_TEMPERATURE_SENSOR_MAX_INSTANCES];
|
2022-09-12 16:48:05 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// parameters
|
|
|
|
AP_TemperatureSensor_Params _params[AP_TEMPERATURE_SENSOR_MAX_INSTANCES];
|
|
|
|
|
|
|
|
private:
|
|
|
|
static AP_TemperatureSensor *_singleton;
|
|
|
|
|
2022-10-11 15:59:59 -03:00
|
|
|
// The TemperatureSensor_State structure is filled in by the backend driver
|
|
|
|
struct TemperatureSensor_State {
|
|
|
|
uint32_t last_time_ms; // time when the sensor was last read in milliseconds
|
|
|
|
float temperature; // temperature (deg C)
|
|
|
|
uint8_t instance; // instance number
|
2023-09-22 20:52:42 -03:00
|
|
|
const struct AP_Param::GroupInfo *var_info;
|
2022-10-11 15:59:59 -03:00
|
|
|
};
|
|
|
|
|
2022-09-12 16:48:05 -03:00
|
|
|
TemperatureSensor_State _state[AP_TEMPERATURE_SENSOR_MAX_INSTANCES];
|
|
|
|
AP_TemperatureSensor_Backend *drivers[AP_TEMPERATURE_SENSOR_MAX_INSTANCES];
|
|
|
|
|
|
|
|
uint8_t _num_instances; // number of temperature sensors
|
|
|
|
|
2024-07-27 11:35:20 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
enum class LoggingType : uint8_t {
|
|
|
|
All = 1,
|
|
|
|
SourceNone = 2,
|
|
|
|
};
|
|
|
|
AP_Enum<LoggingType> _logging_type;
|
|
|
|
#endif
|
|
|
|
|
2022-09-12 16:48:05 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_TemperatureSensor &temperature_sensor();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // AP_TEMPERATURE_SENSOR_ENABLED
|