diff --git a/applications/gui/modules/byte_input.c b/applications/gui/modules/byte_input.c index 567727940..a94e3908f 100644 --- a/applications/gui/modules/byte_input.c +++ b/applications/gui/modules/byte_input.c @@ -36,8 +36,8 @@ typedef struct { #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #endif -static const uint8_t keyboard_origin_x = 8; -static const uint8_t keyboard_origin_y = 32; +static const uint8_t keyboard_origin_x = 7; +static const uint8_t keyboard_origin_y = 31; static const uint8_t keyboard_row_count = 2; static const uint8_t enter_symbol = '\r'; static const uint8_t backspace_symbol = '\b'; @@ -52,7 +52,7 @@ static const ByteInputKey keyboard_keys_row_1[] = { {'5', 55, 12}, {'6', 66, 12}, {'7', 77, 12}, - {backspace_symbol, 101, 4}, + {backspace_symbol, 103, 4}, }; static const ByteInputKey keyboard_keys_row_2[] = { @@ -64,7 +64,7 @@ static const ByteInputKey keyboard_keys_row_2[] = { {'D', 55, 26}, {'E', 66, 26}, {'F', 77, 26}, - {enter_symbol, 93, 17}, + {enter_symbol, 95, 17}, }; /** @@ -158,10 +158,10 @@ static char byte_input_get_nibble_text(uint8_t byte, bool high_nibble) { * @param model */ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) { - const uint8_t text_x = 7; - const uint8_t text_y = 27; + const uint8_t text_x = 3; + const uint8_t text_y = 25; - elements_slightly_rounded_frame(canvas, 5, 16, 117, 15); + elements_slightly_rounded_frame(canvas, 1, 14, 126, 15); for(uint8_t i = model->first_visible_byte; i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes); @@ -242,12 +242,12 @@ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) { * @param model */ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model) { - const uint8_t text_x = 7; - const uint8_t text_y = 27; + const uint8_t text_x = 3; + const uint8_t text_y = 25; - canvas_draw_box(canvas, 0, 14, 128, 19); + canvas_draw_box(canvas, 0, 12, 128, 19); canvas_invert_color(canvas); - elements_slightly_rounded_frame(canvas, 5, 16, 117, 15); + elements_slightly_rounded_frame(canvas, 1, 14, 126, 15); for(uint8_t i = model->first_visible_byte; i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes); @@ -518,7 +518,7 @@ static void byte_input_view_draw_callback(Canvas* canvas, void* _model) { canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); - canvas_draw_str(canvas, 5, 10, model->header); + canvas_draw_str(canvas, 2, 9, model->header); canvas_set_font(canvas, FontKeyboard); @@ -608,7 +608,7 @@ static bool byte_input_view_input_callback(InputEvent* event, void* context) { furi_assert(byte_input); bool consumed = false; - if(event->type == InputTypeShort) { + if(event->type == InputTypeShort || event->type == InputTypeRepeat) { switch(event->key) { case InputKeyLeft: with_view_model( diff --git a/applications/gui/modules/text_input.c b/applications/gui/modules/text_input.c index eefb2eb90..44f5ab9c1 100644 --- a/applications/gui/modules/text_input.c +++ b/applications/gui/modules/text_input.c @@ -292,7 +292,7 @@ static bool text_input_view_input_callback(InputEvent* event, void* context) { furi_assert(text_input); bool consumed = false; - if(event->type == InputTypeShort) { + if(event->type == InputTypeShort || event->type == InputTypeRepeat) { switch(event->key) { case InputKeyUp: text_input_handle_up(text_input); diff --git a/applications/input/input.c b/applications/input/input.c index ab684986e..0a1b53cb0 100644 --- a/applications/input/input.c +++ b/applications/input/input.c @@ -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); diff --git a/applications/input/input.h b/applications/input/input.h index a3500acbd..3e855eec2 100644 --- a/applications/input/input.h +++ b/applications/input/input.h @@ -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 */ diff --git a/applications/input/input_i.h b/applications/input/input_i.h index 97b82da49..78cb50ba8 100644 --- a/applications/input/input_i.h +++ b/applications/input/input_i.h @@ -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;