diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 725ae33420..c4fc6dc139 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -43,6 +43,9 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) { return PORTS[brainPin / PORT_SIZE]; } +/** + * this method returns the numeric part of pin name. For instance, for PC13 this would return '13' + */ ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) { if (brainPin == GPIO_UNASSIGNED) return EFI_ERROR_CODE; diff --git a/firmware/hw_layer/joystick.cpp b/firmware/hw_layer/joystick.cpp index 0cc20ae4a5..59bba827e7 100644 --- a/firmware/hw_layer/joystick.cpp +++ b/firmware/hw_layer/joystick.cpp @@ -36,12 +36,18 @@ static int joyD = 0; static Logging *sharedLogger; static efitick_t lastEventTime = 0; -static void extCallback(EXTDriver *extp, expchannel_t channel) { - UNUSED(extp); +static bool isJitter() { efitick_t now = getTimeNowNt(); if (now - lastEventTime < NT_EVENT_GAP) - return; // two consecutive events are probably just jitter + return true; // two consecutive events are probably just jitter lastEventTime = now; + return false; +} + +static void extCallback(EXTDriver *extp, expchannel_t channel) { + UNUSED(extp); + if (isJitter()) + return; joyTotal++; joystick_button_e button; // todo: I guess it's time to reduce code duplication and start working with an array @@ -51,12 +57,14 @@ static void extCallback(EXTDriver *extp, expchannel_t channel) { } else if (channel == getHwPin("joy", boardConfiguration->joystickAPin)) { joyA++; button = JB_BUTTON_A; +/* not used so far } else if (channel == getHwPin("joy", boardConfiguration->joystickBPin)) { joyB++; - button = JB_BUTTON_C; + button = JB_BUTTON_B; } else if (channel == getHwPin("joy", boardConfiguration->joystickCPin)) { joyC++; - button = JB_BUTTON_B; + button = JB_BUTTON_C; +*/ } else if (channel == getHwPin("joy", boardConfiguration->joystickDPin)) { joyD++; button = JB_BUTTON_D; diff --git a/firmware/hw_layer/joystick.h b/firmware/hw_layer/joystick.h index dc5b2489dc..04bca2f595 100644 --- a/firmware/hw_layer/joystick.h +++ b/firmware/hw_layer/joystick.h @@ -12,8 +12,8 @@ typedef enum { JB_CENTER = 0, JB_BUTTON_A = 1, - JB_BUTTON_B = 2, - JB_BUTTON_C = 3, +// not used so far JB_BUTTON_B = 2, +// not used so far JB_BUTTON_C = 3, JB_BUTTON_D = 4, } joystick_button_e;