Firmware SDK
bc_ds18b20.h
1 #ifndef _BC_DS18B20_H
2 #define _BC_DS18B20_H
3 
4 #include <bc_tick.h>
5 #include <bc_module_sensor.h>
6 #include <bc_scheduler.h>
7 #include <bc_onewire.h>
8 
12 
14 
15 typedef enum
16 {
19 
22 
24 
26 
27 typedef struct bc_ds18b20_t bc_ds18b20_t;
28 typedef struct bc_ds18b20_sensor_t bc_ds18b20_sensor_t;
29 
31 
32 typedef enum
33 {
34  BC_DS18B20_STATE_ERROR = -1,
35  BC_DS18B20_STATE_PREINITIALIZE = 0,
36  BC_DS18B20_STATE_INITIALIZE = 1,
37  BC_DS18B20_STATE_READY = 2,
38  BC_DS18B20_STATE_MEASURE = 3,
39  BC_DS18B20_STATE_READ = 4,
40  BC_DS18B20_STATE_UPDATE = 5
41 
42 } bc_ds18b20_state_t;
43 
44 typedef enum
45 {
46  BC_DS18B20_RESOLUTION_BITS_9 = 0,
47  BC_DS18B20_RESOLUTION_BITS_10 = 1,
48  BC_DS18B20_RESOLUTION_BITS_11 = 2,
49  BC_DS18B20_RESOLUTION_BITS_12 = 3
50 
51 } bc_ds18b20_resolution_bits_t;
52 
53 struct bc_ds18b20_sensor_t
54 {
55  int16_t _temperature_raw;
56  uint64_t _device_address;
57  bool _temperature_valid;
58 };
59 
60 struct bc_ds18b20_t
61 {
62  bc_scheduler_task_id_t _task_id_interval;
63  bc_scheduler_task_id_t _task_id_measure;
64  void (*_event_handler)(bc_ds18b20_t *, uint64_t _device_address, bc_ds18b20_event_t, void *);
65  void *_event_param;
66  bool _measurement_active;
67  bc_tick_t _update_interval;
68  bc_ds18b20_state_t _state;
69 
70  bc_ds18b20_sensor_t *_sensor;
71  int _sensor_count;
72  int _sensor_found;
73 
74  bc_ds18b20_resolution_bits_t _resolution;
75 
76  bool _power;
77  bool _power_dynamic;
78  bc_onewire_t *_onewire;
79 };
80 
82 
83 
87 
88 void bc_ds18b20_init_single(bc_ds18b20_t *self, bc_ds18b20_resolution_bits_t resolution);
89 
95 
96 void bc_ds18b20_init_multiple(bc_ds18b20_t *self, bc_ds18b20_sensor_t *sensors, int sensor_count, bc_ds18b20_resolution_bits_t resolution);
97 
104 
105 void bc_ds18b20_init(bc_ds18b20_t *self, bc_onewire_t *onewire, bc_ds18b20_sensor_t *sensors, int sensor_count, bc_ds18b20_resolution_bits_t resolution);
106 
111 
112 void bc_ds18b20_set_event_handler(bc_ds18b20_t *self, void (*event_handler)(bc_ds18b20_t *, uint64_t _device_address, bc_ds18b20_event_t, void *), void *event_param);
113 
117 
119 
124 
125 bool bc_ds18b20_measure(bc_ds18b20_t *self);
126 
133 
134 bool bc_ds18b20_get_temperature_raw(bc_ds18b20_t *self, uint64_t device_address, int16_t *raw);
135 
142 
143 bool bc_ds18b20_get_temperature_celsius(bc_ds18b20_t *self, uint64_t _device_address, float *celsius);
144 
148 
149 int bc_ds18b20_get_index_by_device_address(bc_ds18b20_t *self, uint64_t device_address);
150 
155 
156 uint64_t bc_ds182b0_get_short_address(bc_ds18b20_t *self, uint8_t index);
157 
160 
162 
166 
167 void bc_ds18b20_set_power_dynamic(bc_ds18b20_t *self, bool on);
168 
170 
171 #endif // _BC_DS18B20_H
void bc_ds18b20_init_multiple(bc_ds18b20_t *self, bc_ds18b20_sensor_t *sensors, int sensor_count, bc_ds18b20_resolution_bits_t resolution)
Initialize multiple ds18b20 over channel B on Sensor Module.
Definition: bc_ds18b20.c:31
int bc_ds18b20_get_index_by_device_address(bc_ds18b20_t *self, uint64_t device_address)
Get device index by its device address.
Definition: bc_ds18b20.c:89
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
struct bc_ds18b20_t bc_ds18b20_t
BigClown ds18b20 instance.
Definition: bc_ds18b20.h:27
Update event.
Definition: bc_ds18b20.h:21
bc_ds18b20_event_t
Callback events.
Definition: bc_ds18b20.h:15
void bc_ds18b20_init(bc_ds18b20_t *self, bc_onewire_t *onewire, bc_ds18b20_sensor_t *sensors, int sensor_count, bc_ds18b20_resolution_bits_t resolution)
Initialize ds18b20.
Definition: bc_ds18b20.c:38
bool bc_ds18b20_measure(bc_ds18b20_t *self)
Start measurement manually.
Definition: bc_ds18b20.c:75
void bc_ds18b20_set_power_dynamic(bc_ds18b20_t *self, bool on)
Set power dynamic, Turns VDD on and pull 4k7 only for measurement.
Definition: bc_ds18b20.c:121
void bc_ds18b20_init_single(bc_ds18b20_t *self, bc_ds18b20_resolution_bits_t resolution)
Initialize single ds18b20 over channel B on Sensor Module.
Definition: bc_ds18b20.c:23
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:22
int bc_ds18b20_get_sensor_found(bc_ds18b20_t *self)
Get number of found sensor.
Definition: bc_ds18b20.c:116
struct bc_onewire_t bc_onewire_t
1-Wire instance
Definition: bc_onewire.h:14
bool bc_ds18b20_get_temperature_celsius(bc_ds18b20_t *self, uint64_t _device_address, float *celsius)
Get measured temperature in degrees of Celsius.
Definition: bc_ds18b20.c:145
Error event.
Definition: bc_ds18b20.h:18
bool bc_ds18b20_get_temperature_raw(bc_ds18b20_t *self, uint64_t device_address, int16_t *raw)
Get measured temperature in degrees of Celsius.
Definition: bc_ds18b20.c:126
void bc_ds18b20_set_update_interval(bc_ds18b20_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_ds18b20.c:59
uint64_t bc_ds182b0_get_short_address(bc_ds18b20_t *self, uint8_t index)
Get device index by its device address.
Definition: bc_ds18b20.c:102
void bc_ds18b20_set_event_handler(bc_ds18b20_t *self, void(*event_handler)(bc_ds18b20_t *, uint64_t _device_address, bc_ds18b20_event_t, void *), void *event_param)
Set callback function.
Definition: bc_ds18b20.c:52