[FL-938] Keyboard widget changes (#398)
* inputs: add repeat event * byte_input: change draw * text_input, byte_input: process repeat event
This commit is contained in:
@@ -11,8 +11,15 @@ void input_press_timer_callback(void* arg) {
|
||||
InputPinState* input_pin = arg;
|
||||
InputEvent event;
|
||||
event.key = input_pin->pin->key;
|
||||
event.type = InputTypeLong;
|
||||
notify_pubsub(&input->event_pubsub, &event);
|
||||
if(!input_pin->repeat_event) {
|
||||
event.type = InputTypeLong;
|
||||
notify_pubsub(&input->event_pubsub, &event);
|
||||
input_pin->repeat_event = true;
|
||||
} else {
|
||||
event.type = InputTypeRepeat;
|
||||
notify_pubsub(&input->event_pubsub, &event);
|
||||
}
|
||||
osTimerStart(input_pin->press_timer, INPUT_REPEATE_PRESS_TICKS);
|
||||
}
|
||||
|
||||
void input_isr(void* _pin, void* _ctx) {
|
||||
@@ -90,6 +97,7 @@ int32_t input_task() {
|
||||
for(size_t i = 0; i < pin_count; i++) {
|
||||
input->pin_states[i].pin = &input_pins[i];
|
||||
input->pin_states[i].state = GPIO_Read(input->pin_states[i]);
|
||||
input->pin_states[i].repeat_event = false;
|
||||
input->pin_states[i].debounce = INPUT_DEBOUNCE_TICKS_HALF;
|
||||
input->pin_states[i].press_timer =
|
||||
osTimerNew(input_press_timer_callback, osTimerOnce, &input->pin_states[i], NULL);
|
||||
@@ -114,6 +122,9 @@ int32_t input_task() {
|
||||
// Short/Long press logic
|
||||
if(state) {
|
||||
osTimerStart(input->pin_states[i].press_timer, INPUT_LONG_PRESS_TICKS);
|
||||
} else if(input->pin_states[i].repeat_event) {
|
||||
osTimerStop(input->pin_states[i].press_timer);
|
||||
input->pin_states[i].repeat_event = false;
|
||||
} else if(osTimerStop(input->pin_states[i].press_timer) == osOK) {
|
||||
event.type = InputTypeShort;
|
||||
notify_pubsub(&input->event_pubsub, &event);
|
||||
|
@@ -10,6 +10,7 @@ typedef enum {
|
||||
InputTypeRelease, /* Release event, emitted after debounce */
|
||||
InputTypeShort, /* Short event, emitted after InputTypeRelease done withing INPUT_LONG_PRESS interval */
|
||||
InputTypeLong, /* Long event, emmited after INPUT_LONG_PRESS interval, asynchronouse to InputTypeRelease */
|
||||
InputTypeRepeat, /* Repeat event, emmited with INPUT_REPEATE_PRESS period after InputTypeLong event */
|
||||
} InputType;
|
||||
|
||||
/* Input Event, dispatches with PubSub */
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
|
||||
#define INPUT_LONG_PRESS_TICKS 2048
|
||||
#define INPUT_REPEATE_PRESS_TICKS 256
|
||||
#define INPUT_THREAD_FLAG_ISR 0x00000001
|
||||
|
||||
/* Input pin state */
|
||||
@@ -17,6 +18,7 @@ typedef struct {
|
||||
const InputPin* pin;
|
||||
// State
|
||||
volatile bool state;
|
||||
volatile bool repeat_event;
|
||||
volatile uint8_t debounce;
|
||||
volatile osTimerId_t press_timer;
|
||||
} InputPinState;
|
||||
|
Reference in New Issue
Block a user