1-phase PV router
Loading...
Searching...
No Matches
TemperatureSensing< N > Class Template Reference

Implements temperature sensing functionality for multiple sensors. More...

#include <utils_temp.h>

Collaboration diagram for TemperatureSensing< N >:

Public Member Functions

constexpr TemperatureSensing ()=delete
 
constexpr TemperatureSensing (uint8_t pin, const DeviceAddress(&ref)[N])
 Construct a new Temperature Sensing object.
 
constexpr auto get_pin () const
 Get the pin of the sensor(s).
 
constexpr auto get_size () const
 Get the number of sensors.
 
void initTemperatureSensors () const
 Initialize the Dallas temperature sensors.
 
int16_t readTemperature (const uint8_t idx) const
 Reads the temperature of a specific sensor.
 
void requestTemperatures () const
 Request temperature conversion for all sensors.
 

Private Types

using ScratchPad = uint8_t[9]
 Represents a buffer for storing sensor data.
 

Private Attributes

const DeviceAddress sensorAddrs [N]
 
const uint8_t sensorPin { unused_pin }
 

Static Private Attributes

static conditional< TEMP_SENSOR_PRESENT, OneWire, MockOneWire >::type oneWire
 

Detailed Description

template<uint8_t N>
class TemperatureSensing< N >

Implements temperature sensing functionality for multiple sensors.

The TemperatureSensing class manages temperature sensors connected via the OneWire bus. It supports initialization, temperature reading, and error handling for multiple sensors.

Template Parameters
NThe number of sensors connected to the system.
  • Initialization: Initializes the OneWire bus and requests temperature readings.
  • Temperature Reading: Reads and validates temperature data from individual sensors.
  • Error Handling: Handles disconnected or out-of-range sensors.
  • Compile-Time Configuration: Uses TEMP_ENABLED to include or exclude temperature sensing features.

Definition at line 105 of file utils_temp.h.

Constructor & Destructor Documentation

◆ TemperatureSensing() [1/2]

template<uint8_t N>
TemperatureSensing< N >::TemperatureSensing ( )
constexprdelete

◆ TemperatureSensing() [2/2]

template<uint8_t N>
TemperatureSensing< N >::TemperatureSensing ( uint8_t pin,
const DeviceAddress(&) ref[N] )
inlineconstexpr

Construct a new Temperature Sensing object.

This constructor initializes the TemperatureSensing object with the specified pin and a list of device addresses for the connected temperature sensors.

Template Parameters
NThe number of sensors connected to the system.
Parameters
pinThe pin number where the temperature sensors are connected.
refA reference to an array of DeviceAddress objects representing the addresses of the sensors.

Definition at line 135 of file utils_temp.h.

References sensorAddrs, and sensorPin.

Member Function Documentation

◆ get_pin()

template<uint8_t N>
auto TemperatureSensing< N >::get_pin ( ) const
inlineconstexpr

Get the pin of the sensor(s).

This method returns the pin number where the temperature sensors are connected.

Returns
constexpr auto The pin number.

Definition at line 202 of file utils_temp.h.

References sensorPin.

◆ get_size()

template<uint8_t N>
auto TemperatureSensing< N >::get_size ( ) const
inlineconstexpr

Get the number of sensors.

This method returns the number of temperature sensors connected to the system. It provides a compile-time constant value representing the total number of sensors.

Returns
constexpr auto The number of sensors.

Definition at line 190 of file utils_temp.h.

◆ initTemperatureSensors()

template<uint8_t N>
void TemperatureSensing< N >::initTemperatureSensors ( ) const
inline

Initialize the Dallas temperature sensors.

This method initializes the OneWire bus and sends a request to all connected sensors to start temperature conversion. It ensures that the sensors are ready for temperature readings.

  • Initializes the OneWire bus using the specified sensor pin.
  • Sends a CONVERT_TEMPERATURE command to all sensors on the bus.
  • This method should be called during system initialization to prepare the sensors.

Definition at line 173 of file utils_temp.h.

References oneWire, requestTemperatures(), sensorPin, and TEMP_SENSOR_PRESENT.

Here is the call graph for this function:

◆ readTemperature()

template<uint8_t N>
int16_t TemperatureSensing< N >::readTemperature ( const uint8_t idx) const
inlinenodiscard

Reads the temperature of a specific sensor.

This method reads the temperature data from a specific sensor connected to the OneWire bus. It validates the data using CRC and ensures the temperature is within the acceptable range.

Parameters
idxThe index of the sensor to read.
Returns
int16_t The temperature in hundredths of a degree Celsius (e.g., 2500 = 25.00°C). Returns DEVICE_DISCONNECTED_RAW if the sensor is disconnected or CRC validation fails. Returns OUTOFRANGE_TEMPERATURE if the temperature is out of the defined range.
  • Communicates with the sensor using the OneWire protocol.
  • Reads the scratchpad memory of the sensor to retrieve temperature data.
  • Validates the data using CRC and checks for out-of-range values.

Definition at line 223 of file utils_temp.h.

References DEVICE_DISCONNECTED_RAW, oneWire, OUTOFRANGE_TEMPERATURE, READ_SCRATCHPAD, sensorAddrs, TEMP_RANGE_HIGH, and TEMP_SENSOR_PRESENT.

◆ requestTemperatures()

template<uint8_t N>
void TemperatureSensing< N >::requestTemperatures ( ) const
inline

Request temperature conversion for all sensors.

This method sends a command to all sensors on the OneWire bus to start temperature conversion. It ensures that all connected sensors begin measuring their respective temperatures.

  • The method uses the OneWire protocol to communicate with all sensors on the bus.
  • It sends a CONVERT_TEMPERATURE command to initiate temperature conversion.
  • This method does not block; the actual temperature reading must be performed later.

Definition at line 151 of file utils_temp.h.

References CONVERT_TEMPERATURE, oneWire, and TEMP_SENSOR_PRESENT.

Referenced by initTemperatureSensors().

Here is the caller graph for this function:

Member Data Documentation

◆ oneWire

template<uint8_t N>
conditional<TEMP_SENSOR_PRESENT,OneWire,MockOneWire>::type TemperatureSensing< N >::oneWire
inlinestaticprivate

For temperature sensing

Definition at line 267 of file utils_temp.h.

Referenced by initTemperatureSensors(), readTemperature(), and requestTemperatures().

◆ sensorAddrs

template<uint8_t N>
const DeviceAddress TemperatureSensing< N >::sensorAddrs[N]
private

Array of sensors

Definition at line 265 of file utils_temp.h.

Referenced by TemperatureSensing(), and readTemperature().

◆ sensorPin

template<uint8_t N>
const uint8_t TemperatureSensing< N >::sensorPin { unused_pin }
private

The pin of the sensor(s)

Definition at line 263 of file utils_temp.h.

Referenced by TemperatureSensing(), get_pin(), and initTemperatureSensors().


The documentation for this class was generated from the following file: