3-phase PV router
Loading...
Searching...
No Matches
TempSensors< N > Class Template Reference

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

#include <utils_temp.h>

Inheritance diagram for TempSensors< N >:
Collaboration diagram for TempSensors< N >:

Public Member Functions

constexpr TempSensors (const TemperatureSensing< N > &sensors)
 The sensors of config.h.
 
int16_t endRead () const
 CLOSE, the last transaction: a reset (the sensor still there?), the reading decoded.
 
void initTemperatureSensors () const
 Initialize the Dallas temperature sensors.
 
void printSensorsOnBus () const
 Lists the sensors on the bus, with their ROM codes as config.h takes them.
 
void readScratchpad (const uint8_t idx) const
 READ, the second transaction: the second half of the ROM code, Read Scratchpad, the 9 bytes of the scratchpad.
 
template<uint8_t IDX>
int16_t readTemperature () const
 Read temperature from a specific sensor (compile-time bounds checking).
 
int16_t readTemperature (const uint8_t idx) const
 Reads the temperature of a specific sensor (runtime bounds checking).
 
void requestTemperatures () const
 Request temperature conversion for all sensors.
 
bool startRead (const uint8_t idx) const
 ADDRESS, the first transaction of a sensor's read: reset, Match ROM, the first half of its ROM code.
 
- Public Member Functions inherited from TemperatureSensing< N >
constexpr TemperatureSensing ()=delete
 
constexpr TemperatureSensing (const uint8_t pin, const DeviceAddress(&ref)[N])
 The sensors on pin, from their addresses.
 
constexpr uint8_t get_pin () const
 The pin of the bus.
 
constexpr uint8_t size () const
 Number of sensors.
 

Private Member Functions

bool isConfigured (const DeviceAddress &device) const
 Whether config.h lists this sensor.
 

Static Private Attributes

static constexpr uint8_t MATCH_ROM { 0x55 }
 
static OneWireType oneWire
 
static constexpr uint8_t ROM_HALF { 4 }
 
static DS18B20::ScratchPad scratchPad
 

Additional Inherited Members

- Protected Attributes inherited from TemperatureSensing< N >
const DeviceAddress sensorAddrs [N]
 
const uint8_t sensorPin { unused_pin }
 

Detailed Description

template<uint8_t N>
class TempSensors< N >

Implements temperature sensing functionality for multiple sensors.

The TempSensors class reads the sensors of config.h (its base, TemperatureSensing). It 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.
  • Temperature Reading: The transactions of temp_schedule.h: requestTemperatures(), then for each sensor startRead(), readScratchpad() and endRead(), on three mains cycles.
  • Error Handling: Handles disconnected or out-of-range sensors.
  • Compile-Time Configuration: TEMP_SENSOR_PRESENT selects the real OneWire bus or a mock.

Definition at line 96 of file utils_temp.h.

Constructor & Destructor Documentation

◆ TempSensors()

template<uint8_t N>
TempSensors< N >::TempSensors ( const TemperatureSensing< N > & sensors)
inlineexplicitconstexpr

The sensors of config.h.

Parameters
sensorsThe pin of the bus and the address of each sensor, as in config.h.

Definition at line 107 of file utils_temp.h.

Here is the call graph for this function:

Member Function Documentation

◆ endRead()

template<uint8_t N>
int16_t TempSensors< N >::endRead ( ) const
inlinenodiscard

CLOSE, the last transaction: a reset (the sensor still there?), the reading decoded.

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.

Definition at line 276 of file utils_temp.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initTemperatureSensors()

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

Initialize the Dallas temperature sensors.

Initializes the OneWire bus on the sensor pin. The first conversion is requested by the main loop, at the first mains cycle (temp_schedule.h), like every other one. Call it during system initialization.

Definition at line 205 of file utils_temp.h.

◆ isConfigured()

template<uint8_t N>
bool TempSensors< N >::isConfigured ( const DeviceAddress & device) const
inlineprivate

Whether config.h lists this sensor.

Definition at line 341 of file utils_temp.h.

Here is the caller graph for this function:

◆ printSensorsOnBus()

template<uint8_t N>
void TempSensors< N >::printSensorsOnBus ( ) const
inline

Lists the sensors on the bus, with their ROM codes as config.h takes them.

Calibration mode only (CALIBRATION_MODE), with temperature sensing: to find the codes to put in config.h, or to check them. Each code says whether config.h has it. The OneWire library is built without its search (-DONEWIRE_SEARCH=0, platformio.ini): RomSearch (onewire_search.h) does it here, with its state on the stack.

Definition at line 141 of file utils_temp.h.

Here is the call graph for this function:

◆ readScratchpad()

template<uint8_t N>
void TempSensors< N >::readScratchpad ( const uint8_t idx) const
inline

READ, the second transaction: the second half of the ROM code, Read Scratchpad, the 9 bytes of the scratchpad.

Parameters
idxThe index of the sensor, as for startRead()

Definition at line 248 of file utils_temp.h.

Here is the caller graph for this function:

◆ readTemperature() [1/2]

template<uint8_t N>
template<uint8_t IDX>
int16_t TempSensors< N >::readTemperature ( ) const
inlinenodiscard

Read temperature from a specific sensor (compile-time bounds checking).

This template version provides compile-time bounds checking for constant sensor indices. Use this version when the sensor index is known at compile time for better safety.

Template Parameters
IDXThe sensor index (must be < N)
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.

Definition at line 304 of file utils_temp.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readTemperature() [2/2]

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

Reads the temperature of a specific sensor (runtime bounds checking).

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. Includes runtime bounds checking for safety when the index is not known at compile time.

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.

Definition at line 329 of file utils_temp.h.

Here is the call graph for this function:

◆ requestTemperatures()

template<uint8_t N>
void TempSensors< 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 123 of file utils_temp.h.

◆ startRead()

template<uint8_t N>
bool TempSensors< N >::startRead ( const uint8_t idx) const
inlinenodiscard

ADDRESS, the first transaction of a sensor's read: reset, Match ROM, the first half of its ROM code.

Parameters
idxThe index of the sensor
Returns
false if no sensor answered the reset (its read ends here: DEVICE_DISCONNECTED_RAW)

Definition at line 220 of file utils_temp.h.

Here is the caller graph for this function:

Member Data Documentation

◆ MATCH_ROM

template<uint8_t N>
uint8_t TempSensors< N >::MATCH_ROM { 0x55 }
staticconstexprprivate

the ROM command that addresses one sensor

Definition at line 353 of file utils_temp.h.

◆ oneWire

template<uint8_t N>
OneWireType TempSensors< N >::oneWire
inlinestaticprivate

For temperature sensing

Definition at line 356 of file utils_temp.h.

◆ ROM_HALF

template<uint8_t N>
uint8_t TempSensors< N >::ROM_HALF { 4 }
staticconstexprprivate

the bytes of the ROM code written by startRead()

Definition at line 354 of file utils_temp.h.

◆ scratchPad

template<uint8_t N>
DS18B20::ScratchPad TempSensors< N >::scratchPad
inlinestaticprivate

the scratchpad of the sensor being read

Definition at line 357 of file utils_temp.h.


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