6 #include <twr_scheduler.h>
12 #define TWR_SWITCH_OPEN false
13 #define TWR_SWITCH_CLOSE true
68 TWR_SWITCH_TASK_STATE_MEASURE = 0,
69 TWR_SWITCH_TASK_STATE_SET_PULL = 1,
71 } twr_switch_task_state_t;
81 twr_switch_task_state_t _task_state;
87 uint16_t _pull_advance_time;
twr_gpio_channel_t
GPIO channels.
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
bool twr_switch_get_state(twr_switch_t *self)
Get state.
void twr_switch_init(twr_switch_t *self, twr_gpio_channel_t channel, twr_switch_type_t type, twr_switch_pull_t pull)
Initialize button.
void twr_switch_set_pull_advance_time(twr_switch_t *self, uint16_t pull_advance_time_us)
Set pull advance time (work only with dynamic pull up/down), default 50us, for time bigger than 1000u...
void twr_switch_set_debounce_time(twr_switch_t *self, twr_tick_t debounce_time)
Set debounce time (minimum sampling interval during which input cannot change to toggle its state),...
twr_switch_event_t
Callback events.
struct twr_switch_t twr_switch_t
State.
void twr_switch_set_scan_interval(twr_switch_t *self, twr_tick_t scan_interval)
Set scan interval (period of button input sampling), default 50ms.
void twr_switch_set_event_handler(twr_switch_t *self, void(*event_handler)(twr_switch_t *, twr_switch_event_t, void *), void *event_param)
Set callback function.
@ TWR_SWITCH_EVENT_OPENED
Event Opened.
@ TWR_SWITCH_EVENT_CLOSED
Event Closed.
@ TWR_SWITCH_PULL_NONE
Pull None.
@ TWR_SWITCH_PULL_DOWN
Pull Down.
@ TWR_SWITCH_PULL_UP
Pull Up.
@ TWR_SWITCH_PULL_DOWN_DYNAMIC
Pull Down dynamic (Turns pull only for measurement)
@ TWR_SWITCH_PULL_UP_DYNAMIC
Pull Up dynamic (Turns pull only for measurement)
@ TWR_SWITCH_TYPE_NC
Type Normally Closed.
@ TWR_SWITCH_TYPE_NO
Type Normally Open.
uint64_t twr_tick_t
Timestamp data type.