23#include <idfxx/onewire>
29#include <thermo/thermo>
68#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
123#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
156#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
194#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
252#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
298#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
392 static constexpr char hex[] =
"0123456789ABCDEF";
393 auto v =
static_cast<uint8_t>(std::to_underlying(
f));
394 return std::string(
"unknown(0x") +
hex[
v >> 4] +
hex[
v & 0xF] +
')';
417 static constexpr char hex[] =
"0123456789ABCDEF";
418 auto v =
static_cast<uint8_t>(std::to_underlying(
r));
419 return std::string(
"unknown(0x") +
hex[
v >> 4] +
hex[
v & 0xF] +
')';
426#include "sdkconfig.h"
427#ifdef CONFIG_IDFXX_STD_FORMAT
433struct formatter<
idfxx::ds18x20::family> {
434 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
436 template<
typename FormatContext>
439 return std::copy(s.begin(), s.end(), ctx.out());
444struct formatter<
idfxx::ds18x20::resolution> {
445 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
447 template<
typename FormatContext>
450 return std::copy(s.begin(), s.end(), ctx.out());
DS18x20 1-Wire temperature sensor device.
result< void > try_measure(bool wait=true)
Initiates a temperature conversion.
result< void > try_set_resolution(resolution res)
Sets the ADC resolution.
static result< device > make(idfxx::gpio pin, onewire::address addr=onewire::address::any())
Creates a validated device.
resolution get_resolution() const
Gets the current ADC resolution.
void set_resolution(resolution res)
Sets the ADC resolution.
constexpr onewire::address addr() const
Returns the device address.
result< resolution > try_get_resolution() const
Gets the current ADC resolution.
thermo::millicelsius read_temperature() const
Reads the last converted temperature.
void measure(bool wait=true)
Initiates a temperature conversion.
device(device &&)=default
result< thermo::millicelsius > try_read_temperature() const
Reads the last converted temperature.
result< void > try_copy_scratchpad()
Copies the scratchpad to EEPROM.
device(const device &)=default
device(idfxx::gpio pin, onewire::address addr=onewire::address::any())
Constructs a validated device.
device & operator=(device &&)=default
void write_scratchpad(std::span< const uint8_t, 3 > data)
Writes 3 bytes to the scratchpad (TH, TL, configuration register).
thermo::millicelsius measure_and_read()
Measures and reads the temperature in a single operation.
result< thermo::millicelsius > try_measure_and_read()
Measures and reads the temperature in a single operation.
friend result< std::vector< device > > try_scan_devices(idfxx::gpio pin, size_t max_devices)
Scans for DS18x20 devices on a 1-Wire bus.
void copy_scratchpad()
Copies the scratchpad to EEPROM.
result< void > try_write_scratchpad(std::span< const uint8_t, 3 > data)
Writes 3 bytes to the scratchpad (TH, TL, configuration register).
constexpr bool operator==(const device &) const noexcept=default
Compares two devices for equality.
std::array< uint8_t, 9 > read_scratchpad() const
Reads the 9-byte scratchpad memory.
result< std::array< uint8_t, 9 > > try_read_scratchpad() const
Reads the 9-byte scratchpad memory.
constexpr idfxx::gpio pin() const
Returns the GPIO pin.
device & operator=(const device &)=default
static constexpr address any()
Returns the wildcard address for single-device buses.
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
std::vector< device > scan_devices(idfxx::gpio pin, size_t max_devices=8)
Scans for DS18x20 devices on a 1-Wire bus.
result< std::vector< thermo::millicelsius > > try_measure_and_read_multi(std::span< const device > devices)
Measures and reads temperatures from multiple devices.
resolution
DS18B20 ADC resolution configuration.
family
DS18x20 device family identifiers.
std::vector< thermo::millicelsius > measure_and_read_multi(std::span< const device > devices)
Measures and reads temperatures from multiple devices.
result< std::vector< device > > try_scan_devices(idfxx::gpio pin, size_t max_devices=8)
Scans for DS18x20 devices on a 1-Wire bus.
@ bits_11
11-bit resolution (~375ms conversion)
@ bits_12
12-bit resolution (~750ms conversion, default)
@ bits_9
9-bit resolution (~93.75ms conversion)
@ bits_10
10-bit resolution (~187.5ms conversion)
@ ds18s20
DS18S20 (9-bit, +/-0.5C)
@ ds1822
DS1822 (12-bit, +/-2C)
@ max31850
MAX31850 (14-bit, +/-0.25C)
@ ds18b20
DS18B20 (12-bit, +/-0.5C)
DS18x20 1-Wire temperature sensor classes and utilities.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
std::expected< T, std::error_code > result
result type wrapping a value or error code.