Firmware SDK
twr_soil_sensor.h
1 #ifndef _TWR_SOIL_SENSOR_H
2 #define _TWR_SOIL_SENSOR_H
3 
4 #include <twr_ds28e17.h>
5 #include <twr_scheduler.h>
6 #include <twr_onewire.h>
7 
11 
13 
14 typedef enum
15 {
18 
21 
23 
25 
26 typedef enum
27 {
30 
33 
36 
39 
42 
45 
48 
51 
54 
57 
60 
63 
66 
69 
72 
75 
77 
79 
81 
82 typedef struct twr_soil_sensor_sensor_t twr_soil_sensor_sensor_t;
83 
84 #pragma pack(push, 1)
85 
86 typedef struct
87 {
89  uint32_t signature;
91  uint8_t version;
93  uint8_t length;
95  uint16_t crc;
96 
98 
99 typedef struct
100 {
102  uint8_t product;
103 
105  uint16_t revision;
106 
108  char label[16 + 1];
109 
111  uint16_t calibration[11];
112 
114 
115 #pragma pack(pop)
116 
118 
119 typedef enum
120 {
121  TWR_SOIL_SENSOR_STATE_ERROR = -1,
122  TWR_SOIL_SENSOR_STATE_PREINITIALIZE = 0,
123  TWR_SOIL_SENSOR_STATE_INITIALIZE = 1,
124  TWR_SOIL_SENSOR_STATE_READY = 2,
125  TWR_SOIL_SENSOR_STATE_MEASURE = 3,
126  TWR_SOIL_SENSOR_STATE_READ = 4,
127  TWR_SOIL_SENSOR_STATE_UPDATE = 5
128 
129 } twr_soil_sensor_state_t;
130 
131 struct twr_soil_sensor_t
132 {
133  twr_scheduler_task_id_t _task_id_interval;
134  twr_scheduler_task_id_t _task_id_measure;
135  twr_soil_sensor_state_t _state;
136  bool _measurement_active;
137  twr_tick_t _update_interval;
138  void (*_event_handler)(twr_soil_sensor_t *, uint64_t, twr_soil_sensor_event_t, void *);
139  void *_event_param;
140 
141  twr_onewire_t *_onewire;
142  twr_soil_sensor_sensor_t *_sensor;
143  int _sensor_count;
144  int _sensor_found;
146 };
147 
148 struct twr_soil_sensor_sensor_t
149 {
150  twr_ds28e17_t _ds28e17;
151  bool _temperature_valid;
152  int16_t _temperature_raw;
153  bool _cap_valid;
154  uint16_t _cap_raw;
155  twr_soil_sensor_eeprom_t _eeprom;
156 };
157 
159 
162 
164 
169 
170 void twr_soil_sensor_init_multiple(twr_soil_sensor_t *self, twr_soil_sensor_sensor_t *sensors, int sensor_count);
171 
176 
177 void twr_soil_sensor_set_event_handler(twr_soil_sensor_t *self, void (*event_handler)(twr_soil_sensor_t *, uint64_t, twr_soil_sensor_event_t, void *), void *event_param);
178 
182 
184 
188 
190 
195 
197 
204 
205 bool twr_soil_sensor_get_temperature_raw(twr_soil_sensor_t *self, uint64_t device_address, int16_t *raw);
206 
213 
214 bool twr_soil_sensor_get_temperature_celsius(twr_soil_sensor_t *self, uint64_t device_address, float *celsius);
215 
222 
223 bool twr_soil_sensor_get_temperature_fahrenheit(twr_soil_sensor_t *self, uint64_t device_address, float *fahrenheit);
224 
231 
232 bool twr_soil_sensor_get_temperature_kelvin(twr_soil_sensor_t *self, uint64_t device_address, float *kelvin);
233 
240 
241 bool twr_soil_sensor_get_cap_raw(twr_soil_sensor_t *self, uint64_t device_address, uint16_t *raw);
242 
249 
250 bool twr_soil_sensor_get_moisture(twr_soil_sensor_t *self, uint64_t device_address, int *moisture);
251 
257 
258 int twr_soil_sensor_get_index_by_device_address(twr_soil_sensor_t *self, uint64_t device_address);
259 
265 
267 
272 
273 char *twr_soil_sensor_get_label(twr_soil_sensor_t *self, uint64_t device_address);
274 
281 
282 bool twr_soil_sensor_set_label(twr_soil_sensor_t *self, uint64_t device_address, const char *label);
283 
291 
292 bool twr_soil_sensor_calibration_set_point(twr_soil_sensor_t *self, uint64_t device_address, uint8_t point, uint16_t value);
293 
297 
298 bool twr_soil_sensor_eeprom_save(twr_soil_sensor_t *self, uint64_t device_address);
299 
302 
304 
306 
307 #endif // _TWR_SOIL_SENSOR_H
struct twr_onewire_t twr_onewire_t
1-Wire instance
Definition: twr_onewire.h:14
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
bool twr_soil_sensor_get_moisture(twr_soil_sensor_t *self, uint64_t device_address, int *moisture)
Get measured moisture in percent.
twr_soil_sensor_error_t twr_soil_sensor_get_error(twr_soil_sensor_t *self)
Get error number.
bool twr_soil_sensor_get_temperature_raw(twr_soil_sensor_t *self, uint64_t device_address, int16_t *raw)
Get measured temperature as raw value.
char * twr_soil_sensor_get_label(twr_soil_sensor_t *self, uint64_t device_address)
Get device label by its device address.
int twr_soil_sensor_get_index_by_device_address(twr_soil_sensor_t *self, uint64_t device_address)
Get device index by its device address.
int twr_soil_sensor_get_sensor_found(twr_soil_sensor_t *self)
Get sensors found.
struct twr_soil_sensor_t twr_soil_sensor_t
Soil sensor instance.
bool twr_soil_sensor_measure(twr_soil_sensor_t *self)
Start measurement manually.
uint64_t twr_soil_sensor_get_device_address_by_index(twr_soil_sensor_t *self, int index)
Get device device address by its index.
bool twr_soil_sensor_get_temperature_celsius(twr_soil_sensor_t *self, uint64_t device_address, float *celsius)
Get measured temperature in degrees of Celsius.
bool twr_soil_sensor_get_temperature_fahrenheit(twr_soil_sensor_t *self, uint64_t device_address, float *fahrenheit)
Get measured temperature in degrees of Fahrenheit.
twr_soil_sensor_event_t
Callback events.
twr_soil_sensor_error_t
Error numbers.
bool twr_soil_sensor_get_cap_raw(twr_soil_sensor_t *self, uint64_t device_address, uint16_t *raw)
Get capacite as raw value.
void twr_soil_sensor_init(twr_soil_sensor_t *self)
Initialize Soil sensor.
void twr_soil_sensor_init_multiple(twr_soil_sensor_t *self, twr_soil_sensor_sensor_t *sensors, int sensor_count)
Initialize multiple Soil sensor.
void twr_soil_sensor_set_update_interval(twr_soil_sensor_t *self, twr_tick_t interval)
Set measurement interval.
bool twr_soil_sensor_get_temperature_kelvin(twr_soil_sensor_t *self, uint64_t device_address, float *kelvin)
Get measured temperature in kelvin.
bool twr_soil_sensor_calibration_set_point(twr_soil_sensor_t *self, uint64_t device_address, uint8_t point, uint16_t value)
Set value for calibration point by device address.
bool twr_soil_sensor_set_label(twr_soil_sensor_t *self, uint64_t device_address, const char *label)
Get device label by its device address.
void twr_soil_sensor_set_event_handler(twr_soil_sensor_t *self, void(*event_handler)(twr_soil_sensor_t *, uint64_t, twr_soil_sensor_event_t, void *), void *event_param)
Set callback function.
bool twr_soil_sensor_eeprom_save(twr_soil_sensor_t *self, uint64_t device_address)
Save calibration points and label to eeprom by device address.
@ TWR_SOIL_SENSOR_EVENT_UPDATE
Update event.
@ TWR_SOIL_SENSOR_EVENT_ERROR
Error event.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_PAYLOAD_CRC
EEPROM payload crc error.
@ TWR_SOIL_SENSOR_ERROR_TMP112_MEASUREMENT_REQUEST
Tmp112 measurement request.
@ TWR_SOIL_SENSOR_ERROR_NONE
No error.
@ TWR_SOIL_SENSOR_ERROR_ZSSC3123_MEASUREMENT_REQUEST
Zssc3123 measurement request.
@ TWR_SOIL_SENSOR_ERROR_TMP112_DATA_FETCH
Tmp112 data fetch.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_HEADER_READ
EEPROM header read error.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_PAYLOAD_LENGTH
EEPROM payload length error.
@ TWR_SOIL_SENSOR_ERROR_ZSSC3123_DATA_FETCH
Zssc3123 data fetch.
@ TWR_SOIL_SENSOR_ERROR_SENSOR_MODULE_INITIALIZE
Sensor Module initialize error.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_PAYLOAD_READ
EEPROM payload readerror.
@ TWR_SOIL_SENSOR_ERROR_SENSOR_MODULE_POWER_UP
Sensor Module onewire power up error.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_SIGNATURE
EEPROM signature error.
@ TWR_SOIL_SENSOR_ERROR_ZSSC3123_INITIALIZE
Zssc3123 inicialize error.
@ TWR_SOIL_SENSOR_ERROR_EEPROM_VERSION
EEPROM version error.
@ TWR_SOIL_SENSOR_ERROR_NO_SENSOR_FOUND
No sensor found.
@ TWR_SOIL_SENSOR_ERROR_TMP112_INITIALIZE
Tmp112 inicialize error.
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
DS28E17 instance.
Definition: twr_ds28e17.h:14
uint32_t signature
Signature 0xdeadbeef.
uint8_t version
Data Version.
uint16_t revision
Hardware Revision.
uint8_t product
Product number.