From e10a022ea1bf954958f7d4a4e968b95dbcd51272 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 1 Jan 2000 01:22:29 +0900 Subject: Test encoder against min change and min speed, for free-rolling defective encoders --- menus.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/menus.c b/menus.c index a92d471..e591f39 100644 --- a/menus.c +++ b/menus.c @@ -23,6 +23,8 @@ #define Plus_Minus_Button 16 /* mask for +/- button */ #define Extra_Fine_Button 32 /* mask for extra-fine button */ +#define MIN_ENCODER_CHANGE 3 +#define MAX_MS_PER_STEP 2000 /* ----- HOW THE MENU SYSTEM WORKS -------------------------------------------------------------------------*/ @@ -2315,17 +2317,19 @@ static void Submenu_Service_Encoder(int encoder_change) int new_int_value; int channel; - // need an encoder change of at least 2 to do anything - if (abs(encoder_change) <= 1) { + + // ignore small changes + if (abs(encoder_change) <= MIN_ENCODER_CHANGE) { Menu_Clear_Buttons(FALSE); + //g_print_debug("ignoring small change, for now\n"); return; } else if (encoder_change > 0) { - --encoder_change; + encoder_change -= MIN_ENCODER_CHANGE; } else { - ++encoder_change; + encoder_change += MIN_ENCODER_CHANGE; } - + g_print_debug("encoder change: %d\n",encoder_change); /* quit if RWLS mode */ update_remote_mode (); @@ -2353,6 +2357,17 @@ static void Submenu_Service_Encoder(int encoder_change) if (encoder_timer_change[0]<0) { encoder_timer_change[0]=1000; } + if (encoder_timer_change[0]>10000) { + encoder_timer_change[0]=10000; + } + + unsigned long ms_per_step = encoder_timer_change[0] / abs(encoder_change); + g_print_debug("encoder ms per step: %lu\n",ms_per_step); + if (ms_per_step > MAX_MS_PER_STEP) { + g_print_debug("ignoring slow change\n"); + Menu_Clear_Buttons(TRUE); + return; + } if ( (encoder_timer_change[0] < 50) @@ -2360,6 +2375,7 @@ static void Submenu_Service_Encoder(int encoder_change) && (encoder_timer_change[2] < 50) && (Submenu_extra_fine==NO) ) { ++encoder_mult; + g_print_debug("fast spin x%d\n", encoder_mult); if (encoder_mult>8) { encoder_mult=8; } @@ -3473,4 +3489,3 @@ static void Nonstd_menu_network(void) globals.MenuStatus.Nonstd_Display=YES; } - -- cgit