From 4936fa628dfc768dc4fe98127dcd09ecc6618d68 Mon Sep 17 00:00:00 2001 From: DIY89 Date: Tue, 24 May 2022 21:10:49 +0200 Subject: [PATCH] stabilized rotary encoder handling Change-Id: If5678c7a1f8be7fe9c9e64773583246cbc92fb0e --- src/js/remotebuzzer_server.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/js/remotebuzzer_server.js b/src/js/remotebuzzer_server.js index 16777a764..e1d40bcc4 100644 --- a/src/js/remotebuzzer_server.js +++ b/src/js/remotebuzzer_server.js @@ -5,6 +5,7 @@ const API_DIR_NAME = 'api'; const API_FILE_NAME = 'config.php'; const PID = process.pid; let rotaryClkPin, rotaryDtPin; +let cnt = 0; /* LOGGING FUNCTION */ const log = function (...optionalParams) { @@ -525,9 +526,14 @@ const watchRotaryClk = function watchRotaryClk(err, gpioValue) { } if (gpioValue) { - if (rotaryDtPin) { + if (rotaryClkPin) { /* rotation */ - photoboothAction('rotary-cw'); + if (cnt < -3) { + photoboothAction('rotary-cw'); + cnt = 0; + } else { + cnt--; + } } else { rotaryClkPin = true; } @@ -548,9 +554,14 @@ const watchRotaryDt = function watchRotaryDt(err, gpioValue) { } if (gpioValue) { - if (rotaryClkPin) { + if (rotaryDtPin) { /* rotation */ - photoboothAction('rotary-ccw'); + if (cnt > 3) { + photoboothAction('rotary-ccw'); + cnt = 0; + } else { + cnt++; + } } else { rotaryDtPin = true; }