Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_soil_sensor.h
1 #ifndef _BC_SOIL_SENSOR_H
2 #define _BC_SOIL_SENSOR_H
3 
4 #include <bc_ds28e17.h>
5 #include <bc_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef enum
26 {
29 
32 
35 
38 
41 
44 
47 
50 
53 
56 
59 
62 
65 
68 
71 
74 
76 
78 
80 
81 typedef struct bc_soil_sensor_sensor_t bc_soil_sensor_sensor_t;
82 
83 #pragma pack(push, 1)
84 
85 typedef struct
86 {
88  uint32_t signature;
90  uint8_t version;
92  uint8_t length;
94  uint16_t crc;
95 
97 
98 typedef struct
99 {
101  uint8_t product;
102 
104  uint16_t revision;
105 
107  char label[16 + 1];
108 
110  uint16_t calibration[11];
111 
113 
114 #pragma pack(pop)
115 
117 
118 typedef enum
119 {
120  BC_SOIL_SENSOR_STATE_ERROR = -1,
121  BC_SOIL_SENSOR_STATE_PREINITIALIZE = 0,
122  BC_SOIL_SENSOR_STATE_INITIALIZE = 1,
123  BC_SOIL_SENSOR_STATE_READY = 2,
124  BC_SOIL_SENSOR_STATE_MEASURE = 3,
125  BC_SOIL_SENSOR_STATE_READ = 4,
126  BC_SOIL_SENSOR_STATE_UPDATE = 5
127 
128 } bc_soil_sensor_state_t;
129 
130 struct bc_soil_sensor_t
131 {
132  bc_scheduler_task_id_t _task_id_interval;
133  bc_scheduler_task_id_t _task_id_measure;
134  bc_soil_sensor_state_t _state;
135  bool _measurement_active;
136  bc_tick_t _update_interval;
137  void (*_event_handler)(bc_soil_sensor_t *, uint64_t, bc_soil_sensor_event_t, void *);
138  void *_event_param;
139 
140  bc_gpio_channel_t _channel;
141  bc_soil_sensor_sensor_t *_sensor;
142  int _sensor_count;
143  int _sensor_found;
144  bc_soil_sensor_error_t _error;
145 };
146 
147 struct bc_soil_sensor_sensor_t
148 {
149  bc_ds28e17_t _ds28e17;
150  bool _temperature_valid;
151  int16_t _temperature_raw;
152  bool _cap_valid;
153  uint16_t _cap_raw;
154  bc_soil_sensor_eeprom_t _eeprom;
155 };
156 
158 
161 
163 
168 
169 void bc_soil_sensor_init_multiple(bc_soil_sensor_t *self, bc_soil_sensor_sensor_t *sensors, int sensor_count);
170 
175 
176 void bc_soil_sensor_set_event_handler(bc_soil_sensor_t *self, void (*event_handler)(bc_soil_sensor_t *, uint64_t, bc_soil_sensor_event_t, void *), void *event_param);
177 
181 
183 
187 
189 
194 
196 
203 
204 bool bc_soil_sensor_get_temperature_raw(bc_soil_sensor_t *self, uint64_t device_address, int16_t *raw);
205 
212 
213 bool bc_soil_sensor_get_temperature_celsius(bc_soil_sensor_t *self, uint64_t device_address, float *celsius);
214 
221 
222 bool bc_soil_sensor_get_temperature_fahrenheit(bc_soil_sensor_t *self, uint64_t device_address, float *fahrenheit);
223 
230 
231 bool bc_soil_sensor_get_temperature_kelvin(bc_soil_sensor_t *self, uint64_t device_address, float *kelvin);
232 
239 
240 bool bc_soil_sensor_get_cap_raw(bc_soil_sensor_t *self, uint64_t device_address, uint16_t *raw);
241 
248 
249 bool bc_soil_sensor_get_moisture(bc_soil_sensor_t *self, uint64_t device_address, int *moisture);
250 
256 
257 int bc_soil_sensor_get_index_by_device_address(bc_soil_sensor_t *self, uint64_t device_address);
258 
264 
266 
271 
272 char *bc_soil_sensor_get_label(bc_soil_sensor_t *self, uint64_t device_address);
273 
280 
281 bool bc_soil_sensor_set_label(bc_soil_sensor_t *self, uint64_t device_address, const char *label);
282 
290 
291 bool bc_soil_sensor_calibration_set_point(bc_soil_sensor_t *self, uint64_t device_address, uint8_t point, uint16_t value);
292 
296 
297 bool bc_soil_sensor_eeprom_save(bc_soil_sensor_t *self, uint64_t device_address);
298 
301 
303 
305 
306 #endif // _BC_SOIL_SENSOR_H
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
bool bc_soil_sensor_get_temperature_celsius(bc_soil_sensor_t *self, uint64_t device_address, float *celsius)
Get measured temperature in degrees of Celsius.
bool bc_soil_sensor_measure(bc_soil_sensor_t *self)
Start measurement manually.
uint8_t length
Data Length.
Sensor Module initialize error.
struct bc_soil_sensor_t bc_soil_sensor_t
Soil sensor instance.
uint8_t version
Data Version.
void bc_soil_sensor_set_event_handler(bc_soil_sensor_t *self, void(*event_handler)(bc_soil_sensor_t *, uint64_t, bc_soil_sensor_event_t, void *), void *event_param)
Set callback function.
bool bc_soil_sensor_get_cap_raw(bc_soil_sensor_t *self, uint64_t device_address, uint16_t *raw)
Get capacite as raw value.
bool bc_soil_sensor_set_label(bc_soil_sensor_t *self, uint64_t device_address, const char *label)
Get device label by its device address.
uint64_t bc_soil_sensor_get_device_address_by_index(bc_soil_sensor_t *self, int index)
Get device device address by its index.
bc_soil_sensor_event_t
Callback events.
uint16_t revision
Hardware Revision.
bc_soil_sensor_error_t bc_soil_sensor_get_error(bc_soil_sensor_t *self)
Get error number.
bool bc_soil_sensor_eeprom_save(bc_soil_sensor_t *self, uint64_t device_address)
Save calibration points and label to eeprom by device address.
bool bc_soil_sensor_get_temperature_raw(bc_soil_sensor_t *self, uint64_t device_address, int16_t *raw)
Get measured temperature as raw value.
bool bc_soil_sensor_get_temperature_kelvin(bc_soil_sensor_t *self, uint64_t device_address, float *kelvin)
Get measured temperature in kelvin.
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
uint8_t product
Product number.
bool bc_soil_sensor_get_moisture(bc_soil_sensor_t *self, uint64_t device_address, int *moisture)
Get measured moisture in percent.
DS28E17 instance.
Definition: bc_ds28e17.h:14
void bc_soil_sensor_init(bc_soil_sensor_t *self)
Initialize Soil sensor.
EEPROM payload length error.
char * bc_soil_sensor_get_label(bc_soil_sensor_t *self, uint64_t device_address)
Get device label by its device address.
void bc_soil_sensor_set_update_interval(bc_soil_sensor_t *self, bc_tick_t interval)
Set measurement interval.
int bc_soil_sensor_get_sensor_found(bc_soil_sensor_t *self)
Get sensors found.
bc_soil_sensor_error_t
Error numbers.
uint32_t signature
Signature 0xdeadbeef.
bool bc_soil_sensor_calibration_set_point(bc_soil_sensor_t *self, uint64_t device_address, uint8_t point, uint16_t value)
Set value for calibration point by device address.
bc_gpio_channel_t
GPIO channels.
Definition: bc_gpio.h:12
int bc_soil_sensor_get_index_by_device_address(bc_soil_sensor_t *self, uint64_t device_address)
Get device index by its device address.
Sensor Module onewire power up error.
bool bc_soil_sensor_get_temperature_fahrenheit(bc_soil_sensor_t *self, uint64_t device_address, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
void bc_soil_sensor_init_multiple(bc_soil_sensor_t *self, bc_soil_sensor_sensor_t *sensors, int sensor_count)
Initialize multiple Soil sensor.