Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#4162 from leptun/fix_lcd_encoder_diff
Browse files Browse the repository at this point in the history
Fix `lcd_encoder_diff` getting out of sync with the knob hard steps
  • Loading branch information
leptun authored Apr 23, 2023
2 parents ee8b95b + 5778e39 commit ae75d9b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Firmware/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae75d9b

Please sign in to comment.