From dddb921beb92e2b8353e3b1b2c61b69566fa00eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 17 Jun 2021 15:17:56 +0200 Subject: [PATCH] fix: incorrect command handling for rotation encoders --- image-viewer/src/input.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/image-viewer/src/input.c b/image-viewer/src/input.c index cad8e96b2d2b8647bff97b463936e2cc5a676774..6e122ceccfa1115a41e2a7b7a2da763dbe2f3cf0 100644 --- a/image-viewer/src/input.c +++ b/image-viewer/src/input.c @@ -141,12 +141,19 @@ int16_t commands_check_input(commands_t * commands) { return -1; } + commands_update_rotation_encoders(&commands->encoders); rotation_encoders_t encoders = commands->encoders; - commands_update_rotation_encoders(&encoders); for (int i = 0; i < commands->size; i++) { command_t command = commands->commands[i]; input_t input = command.input; + if (input.type != IN_ENCODER_ROTATE && input.type != IN_ENCODER_CLICK) { + continue; + } + rotation_encoder_state_t state = encoders.encoders_state[(uint8_t)command.input.filter]; + if (command.input.filter > ROTATION_ENCODERS_COUNT) { + return -1; + } bool button_changed = state.button_prev != state.button; bool rotation_changed = state.delta != 0;