Merge pull request #4162 from leptun/fix_lcd_encoder_diff

Fix `lcd_encoder_diff` getting out of sync with the knob hard steps
This commit is contained in:
Alex Voinea 2023-04-23 11:31:45 +02:00 committed by GitHub
commit ae75d9bb0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <avr/pgmspace.h>
#include <util/atomic.h>
#include <util/delay.h>
#include "Timer.h"
@ -684,13 +685,20 @@ void lcd_knob_update() {
if (lcd_backlight_wake_trigger) {
lcd_backlight_wake_trigger = false;
backlight_wake();
if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
lcd_encoder_diff = 0;
Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
} else {
Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
bool did_rotate = false;
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
lcd_encoder_diff %= ENCODER_PULSES_PER_STEP;
did_rotate = true;
}
else {
// Get lcd_encoder_diff in sync with the encoder hard steps.
// We assume that a click happens only when the knob is rotated into a stable position
lcd_encoder_diff = 0;
}
}
Sound_MakeSound(did_rotate ? e_SOUND_TYPE_EncoderMove : e_SOUND_TYPE_ButtonEcho);
if (lcd_draw_update == 0) {
// Update LCD rendering at minimum