5 #include <twr_module_sensor.h>
6 #include <twr_scheduler.h>
7 #include <twr_onewire.h>
28 typedef struct twr_ds18b20_sensor_t twr_ds18b20_sensor_t;
34 TWR_DS18B20_STATE_ERROR = -1,
35 TWR_DS18B20_STATE_PREINITIALIZE = 0,
36 TWR_DS18B20_STATE_INITIALIZE = 1,
37 TWR_DS18B20_STATE_READY = 2,
38 TWR_DS18B20_STATE_MEASURE = 3,
39 TWR_DS18B20_STATE_READ = 4,
40 TWR_DS18B20_STATE_RESULTS = 5
42 } twr_ds18b20_state_t;
46 TWR_DS18B20_RESOLUTION_BITS_9 = 0,
47 TWR_DS18B20_RESOLUTION_BITS_10 = 1,
48 TWR_DS18B20_RESOLUTION_BITS_11 = 2,
49 TWR_DS18B20_RESOLUTION_BITS_12 = 3
51 } twr_ds18b20_resolution_bits_t;
53 struct twr_ds18b20_sensor_t
55 int16_t _temperature_raw;
56 uint64_t _device_address;
57 bool _temperature_valid;
66 bool _measurement_active;
68 twr_ds18b20_state_t _state;
70 twr_ds18b20_sensor_t *_sensor;
74 twr_ds18b20_resolution_bits_t _resolution;
int twr_ds18b20_get_sensor_found(twr_ds18b20_t *self)
Get number of found sensor.
void twr_ds18b20_set_event_handler(twr_ds18b20_t *self, void(*event_handler)(twr_ds18b20_t *, uint64_t _device_address, twr_ds18b20_event_t, void *), void *event_param)
Set callback function.
void twr_ds18b20_init_single(twr_ds18b20_t *self, twr_ds18b20_resolution_bits_t resolution)
Initialize single ds18b20 over channel B on Sensor Module.
void twr_ds18b20_set_update_interval(twr_ds18b20_t *self, twr_tick_t interval)
Set measurement interval.
void twr_ds18b20_set_power_dynamic(twr_ds18b20_t *self, bool on)
Set power dynamic, Turns VDD on and pull 4k7 only for measurement.
void twr_ds18b20_rescan(twr_ds18b20_t *self)
Request to rescan the bus.
bool twr_ds18b20_get_temperature_celsius(twr_ds18b20_t *self, uint64_t _device_address, float *celsius)
Get measured temperature in degrees of Celsius.
void twr_ds18b20_init(twr_ds18b20_t *self, twr_onewire_t *onewire, twr_ds18b20_sensor_t *sensors, int sensor_count, twr_ds18b20_resolution_bits_t resolution)
Initialize ds18b20.
twr_ds18b20_event_t
Callback events.
int twr_ds18b20_get_index_by_device_address(twr_ds18b20_t *self, uint64_t device_address)
Get device index by its device address.
struct twr_ds18b20_t twr_ds18b20_t
BigClown ds18b20 instance.
bool twr_ds18b20_get_temperature_raw(twr_ds18b20_t *self, uint64_t device_address, int16_t *raw)
Get measured temperature in degrees of Celsius.
bool twr_ds18b20_measure(twr_ds18b20_t *self)
Start measurement manually.
uint64_t twr_ds182b0_get_short_address(twr_ds18b20_t *self, uint8_t index)
Get device index by its device address.
void twr_ds18b20_init_multiple(twr_ds18b20_t *self, twr_ds18b20_sensor_t *sensors, int sensor_count, twr_ds18b20_resolution_bits_t resolution)
Initialize multiple ds18b20 over channel B on Sensor Module.
@ TWR_DS18B20_EVENT_UPDATE
Update event.
@ TWR_DS18B20_EVENT_ERROR
Error event.
struct twr_onewire_t twr_onewire_t
1-Wire instance
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
uint64_t twr_tick_t
Timestamp data type.