|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
DS18x20 1-Wire temperature sensor device. More...
Public Member Functions | |
| device (idfxx::gpio pin, onewire::address addr=onewire::address::any()) | |
| Constructs a validated device. | |
| device (const device &)=default | |
| device (device &&)=default | |
| device & | operator= (const device &)=default |
| device & | operator= (device &&)=default |
| constexpr bool | operator== (const device &) const noexcept=default |
| Compares two devices for equality. | |
| constexpr idfxx::gpio | pin () const |
| Returns the GPIO pin. | |
| constexpr onewire::address | addr () const |
| Returns the device address. | |
| void | measure (bool wait=true) |
| Initiates a temperature conversion. | |
| thermo::millicelsius | read_temperature () const |
| Reads the last converted temperature. | |
| thermo::millicelsius | measure_and_read () |
| Measures and reads the temperature in a single operation. | |
| result< void > | try_measure (bool wait=true) |
| Initiates a temperature conversion. | |
| result< thermo::millicelsius > | try_read_temperature () const |
| Reads the last converted temperature. | |
| result< thermo::millicelsius > | try_measure_and_read () |
| Measures and reads the temperature in a single operation. | |
| void | set_resolution (resolution res) |
| Sets the ADC resolution. | |
| resolution | get_resolution () const |
| Gets the current ADC resolution. | |
| result< void > | try_set_resolution (resolution res) |
| Sets the ADC resolution. | |
| result< resolution > | try_get_resolution () const |
| Gets the current ADC resolution. | |
| std::array< uint8_t, 9 > | read_scratchpad () const |
| Reads the 9-byte scratchpad memory. | |
| void | write_scratchpad (std::span< const uint8_t, 3 > data) |
| Writes 3 bytes to the scratchpad (TH, TL, configuration register). | |
| void | copy_scratchpad () |
| Copies the scratchpad to EEPROM. | |
| result< std::array< uint8_t, 9 > > | try_read_scratchpad () const |
| Reads the 9-byte scratchpad memory. | |
| result< void > | try_write_scratchpad (std::span< const uint8_t, 3 > data) |
| Writes 3 bytes to the scratchpad (TH, TL, configuration register). | |
| result< void > | try_copy_scratchpad () |
| Copies the scratchpad to EEPROM. | |
Static Public Member Functions | |
| static result< device > | make (idfxx::gpio pin, onewire::address addr=onewire::address::any()) |
| Creates a validated device. | |
Friends | |
| result< std::vector< device > > | try_scan_devices (idfxx::gpio pin, size_t max_devices) |
| Scans for DS18x20 devices on a 1-Wire bus. | |
DS18x20 1-Wire temperature sensor device.
Lightweight, copyable value type representing a specific sensor on a 1-Wire bus. Each device is identified by its GPIO pin and 64-bit ROM address.
For single-sensor buses, use onewire::address::any() (the default) to skip ROM matching:
For multi-sensor buses, first scan for devices:
Definition at line 154 of file ds18x20.hpp.
|
explicit |
Constructs a validated device.
| pin | GPIO pin connected to the 1-Wire bus. |
| addr | Device address (default: onewire::address::any() for single-device buses). |
| std::system_error | if the pin is not connected. |
|
default |
|
inlineconstexpr |
Returns the device address.
Definition at line 191 of file ds18x20.hpp.
|
inline |
Copies the scratchpad to EEPROM.
Persists the TH, TL, and configuration register values so they survive power cycles.
| std::system_error | on failure. |
Definition at line 326 of file ds18x20.hpp.
References try_copy_scratchpad(), and idfxx::unwrap().
|
inline |
Gets the current ADC resolution.
Reads the scratchpad and extracts the configuration register.
| std::system_error | on failure. |
Definition at line 274 of file ds18x20.hpp.
References try_get_resolution(), and idfxx::unwrap().
|
static |
Creates a validated device.
| pin | GPIO pin connected to the 1-Wire bus. |
| addr | Device address (default: onewire::address::any() for single-device buses). |
| invalid_state | If the pin is not connected. |
Initiates a temperature conversion.
| wait | If true, blocks until conversion completes (up to 750ms). If false, returns immediately and the caller must wait. |
| std::system_error | on failure. |
Definition at line 203 of file ds18x20.hpp.
References try_measure(), and idfxx::unwrap().
|
inline |
Measures and reads the temperature in a single operation.
Sends a convert command, waits for completion, then reads the result.
| std::system_error | on failure. |
Definition at line 223 of file ds18x20.hpp.
References try_measure_and_read(), and idfxx::unwrap().
Compares two devices for equality.
|
inlineconstexpr |
Returns the GPIO pin.
Definition at line 188 of file ds18x20.hpp.
|
inline |
Reads the 9-byte scratchpad memory.
| std::system_error | on failure. |
Definition at line 306 of file ds18x20.hpp.
References try_read_scratchpad(), and idfxx::unwrap().
|
inline |
Reads the last converted temperature.
| std::system_error | on failure. |
Definition at line 212 of file ds18x20.hpp.
References try_read_temperature(), and idfxx::unwrap().
|
inline |
Sets the ADC resolution.
Reads the current scratchpad, modifies the configuration register, and writes it back. Only applicable to DS18B20 sensors.
| res | The desired resolution. |
| std::system_error | on failure. |
Definition at line 263 of file ds18x20.hpp.
References try_set_resolution(), and idfxx::unwrap().
Copies the scratchpad to EEPROM.
Persists the TH, TL, and configuration register values so they survive power cycles.
Referenced by copy_scratchpad().
| result< resolution > idfxx::ds18x20::device::try_get_resolution | ( | ) | const |
Gets the current ADC resolution.
Reads the scratchpad and extracts the configuration register.
Referenced by get_resolution().
Initiates a temperature conversion.
| wait | If true, blocks until conversion completes (up to 750ms). If false, returns immediately and the caller must wait. |
Referenced by measure().
| result< thermo::millicelsius > idfxx::ds18x20::device::try_measure_and_read | ( | ) |
Measures and reads the temperature in a single operation.
Sends a convert command, waits for completion, then reads the result.
Referenced by measure_and_read().
Reads the 9-byte scratchpad memory.
Referenced by read_scratchpad().
| result< thermo::millicelsius > idfxx::ds18x20::device::try_read_temperature | ( | ) | const |
Reads the last converted temperature.
Referenced by read_temperature().
| result< void > idfxx::ds18x20::device::try_set_resolution | ( | resolution | res | ) |
Sets the ADC resolution.
Reads the current scratchpad, modifies the configuration register, and writes it back. Only applicable to DS18B20 sensors.
| res | The desired resolution. |
Referenced by set_resolution().
Writes 3 bytes to the scratchpad (TH, TL, configuration register).
| data | The 3 bytes to write [th, tl, config]. |
Referenced by write_scratchpad().
Writes 3 bytes to the scratchpad (TH, TL, configuration register).
| data | The 3 bytes to write [th, tl, config]. |
| std::system_error | on failure. |
Definition at line 315 of file ds18x20.hpp.
References try_write_scratchpad(), and idfxx::unwrap().
|
friend |
Scans for DS18x20 devices on a 1-Wire bus.
Discovers all DS18x20-family devices connected to the specified GPIO pin.
| pin | GPIO pin connected to the 1-Wire bus. |
| max_devices | Maximum number of devices to discover. |
| invalid_state | If the pin is not connected. |