1 #include <twr_flood_detector.h>
3 #define _TWR_FLOOD_DETECTOR_DELAY_RUN 50
5 static void _twr_flood_task_interval(
void *param);
7 static void _twr_flood_task_measure(
void *param);
11 memset(
self, 0,
sizeof(&
self));
14 self->_task_id_measure =
twr_scheduler_register(_twr_flood_task_measure,
self, _TWR_FLOOD_DETECTOR_DELAY_RUN);
19 self->_event_handler = event_handler;
20 self->_event_param = event_param;
25 self->_update_interval = interval;
39 if (self->_measurement_active)
44 self->_measurement_active =
true;
56 static void _twr_flood_task_interval(
void *param)
65 static void _twr_flood_task_measure(
void *param)
73 case TWR_FLOOD_DETECTOR_STATE_ERROR:
75 self->_measurement_active =
false;
77 if (self->_event_handler != NULL)
79 self->_event_handler(
self, TWR_FLOOD_DETECTOR_EVENT_ERROR, self->_event_param);
82 self->_state = TWR_FLOOD_DETECTOR_STATE_INITIALIZE;
86 case TWR_FLOOD_DETECTOR_STATE_INITIALIZE:
88 self->_state = TWR_FLOOD_DETECTOR_STATE_ERROR;
92 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_A:
102 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_B:
112 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_C:
129 self->_state = TWR_FLOOD_DETECTOR_STATE_READY;
131 if (self->_measurement_active)
137 case TWR_FLOOD_DETECTOR_STATE_READY:
139 self->_state = TWR_FLOOD_DETECTOR_STATE_ERROR;
143 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_A:
152 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_B:
161 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_C:
172 self->_state = TWR_FLOOD_DETECTOR_STATE_MEASURE;
175 case TWR_FLOOD_DETECTOR_STATE_MEASURE:
177 self->_state = TWR_FLOOD_DETECTOR_STATE_ERROR;
181 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_A:
191 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_B:
201 case TWR_FLOOD_DETECTOR_TYPE_LD_81_SENSOR_MODULE_CHANNEL_C:
211 self->_measurement_active =
false;
213 if (self->_event_handler != NULL)
215 self->_event_handler(
self, TWR_FLOOD_DETECTOR_EVENT_UPDATE, self->_event_param);
218 self->_state = TWR_FLOOD_DETECTOR_STATE_READY;
struct twr_flood_detector_t twr_flood_detector_t
Instance.
void twr_flood_detector_init(twr_flood_detector_t *self, twr_flood_detector_type_t type)
Initialize flood detector.
bool twr_flood_detector_is_alarm(twr_flood_detector_t *self)
Is alarm.
bool twr_flood_detector_measure(twr_flood_detector_t *self)
Start measurement manually.
twr_flood_detector_type_t
Type sensor.
twr_flood_detector_event_t
Callback events.
void twr_flood_detector_set_update_interval(twr_flood_detector_t *self, twr_tick_t interval)
Set measurement interval.
void twr_flood_detector_set_event_handler(twr_flood_detector_t *self, void(*event_handler)(twr_flood_detector_t *, twr_flood_detector_event_t, void *), void *event_param)
Set callback function.
void twr_gpio_init(twr_gpio_channel_t channel)
Initialize GPIO channel.
int twr_gpio_get_input(twr_gpio_channel_t channel)
Get input state for GPIO channel.
void twr_gpio_set_mode(twr_gpio_channel_t channel, twr_gpio_mode_t mode)
Set mode of operation for GPIO channel.
@ TWR_GPIO_MODE_INPUT
GPIO channel operates as input.
@ TWR_GPIO_P5
GPIO channel P5, A5, DAC1.
@ TWR_GPIO_P4
GPIO channel P4, A4, DAC0.
@ TWR_GPIO_P7
GPIO channel P7, A6.
bool twr_module_sensor_set_vdd(bool on)
Set VDD On / Off.
bool twr_module_sensor_init(void)
Initialize Sensor Module.
bool twr_module_sensor_set_pull(twr_module_sensor_channel_t channel, twr_module_sensor_pull_t pull)
Set pull of Sensor Module channel.
@ TWR_MODULE_SENSOR_PULL_UP_4K7
Channel has pull-up 4k7.
@ TWR_MODULE_SENSOR_PULL_NONE
Channel has no pull.
@ TWR_MODULE_SENSOR_CHANNEL_B
Channel B.
@ TWR_MODULE_SENSOR_CHANNEL_A
Channel A.
void twr_scheduler_plan_current_from_now(twr_tick_t tick)
Schedule current task to tick relative from now.
void twr_scheduler_plan_current_relative(twr_tick_t tick)
Schedule current task to tick relative from current spin.
void twr_scheduler_plan_absolute(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to absolute tick.
void twr_scheduler_plan_now(twr_scheduler_task_id_t task_id)
Schedule specified task for immediate execution.
void twr_scheduler_plan_current_now(void)
Schedule current task for immediate execution.
void twr_scheduler_plan_relative(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to tick relative from current spin.
twr_scheduler_task_id_t twr_scheduler_register(void(*task)(void *), void *param, twr_tick_t tick)
Register task in scheduler.
#define TWR_TICK_INFINITY
Maximum timestamp value.
uint64_t twr_tick_t
Timestamp data type.