From 1c32a9887f4855e2f79908d867bf4c5b0b66c7f5 Mon Sep 17 00:00:00 2001 From: Simon Inns Date: Thu, 30 Jul 2020 12:04:19 +0200 Subject: [PATCH 1/2] Bug fix for issue #12 Solves issue with pointer motion when right button is held down --- SmallyMouse2/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmallyMouse2/main.c b/SmallyMouse2/main.c index aa20334..dd0513f 100644 --- a/SmallyMouse2/main.c +++ b/SmallyMouse2/main.c @@ -429,7 +429,7 @@ void processMouse(void) } else { // Set to 0V RB_DDR |= RB; // 1 = output - RB_PORT &= RB; // Button low + RB_PORT &= ~RB; // Button low } // Clear USB report processing activity on expansion port pin D0 From 3f1aff5881a1edcfad8c7e434e2ef2b6eec9d810 Mon Sep 17 00:00:00 2001 From: Simon Inns Date: Thu, 30 Jul 2020 15:26:42 +0200 Subject: [PATCH 2/2] Fix for issue #10 Changed the order in which new mouse motion is output; code now change phase first then outputs the phase to the IO --- SmallyMouse2/main.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/SmallyMouse2/main.c b/SmallyMouse2/main.c index dd0513f..adde0de 100644 --- a/SmallyMouse2/main.c +++ b/SmallyMouse2/main.c @@ -114,24 +114,23 @@ ISR(TIMER0_COMPA_vect) { // Process X output if (mouseDistanceX > 0) { + // Change phase and range check + if (mouseDirectionX == 0) { + mouseEncoderPhaseX--; + if (mouseEncoderPhaseX < 0) mouseEncoderPhaseX = 3; + } else { + mouseEncoderPhaseX++; + if (mouseEncoderPhaseX > 3) mouseEncoderPhaseX = 0; + } + // Set the output pins according to the current phase if (mouseEncoderPhaseX == 0) X1_PORT |= X1; // Set X1 to 1 if (mouseEncoderPhaseX == 1) X2_PORT |= X2; // Set X2 to 1 if (mouseEncoderPhaseX == 2) X1_PORT &= ~X1; // Set X1 to 0 if (mouseEncoderPhaseX == 3) X2_PORT &= ~X2; // Set X2 to 0 - - // Change phase - if (mouseDirectionX == 0) mouseEncoderPhaseX--; else mouseEncoderPhaseX++; // Decrement the distance left to move mouseDistanceX--; - - // Range check the phase - if ((mouseDirectionX == 1) && (mouseEncoderPhaseX > 3)) mouseEncoderPhaseX = 0; - if ((mouseDirectionX == 0) && (mouseEncoderPhaseX < 0)) mouseEncoderPhaseX = 3; - } else { - // Reset the phase if the mouse isn't moving - mouseEncoderPhaseX = 0; } // Set the timer top value for the next interrupt @@ -143,24 +142,23 @@ ISR(TIMER2_COMPA_vect) { // Process Y output if (mouseDistanceY > 0) { + // Change phase and range check + if (mouseDirectionY == 0) { + mouseEncoderPhaseY--; + if (mouseEncoderPhaseY < 0) mouseEncoderPhaseY = 3; + } else { + mouseEncoderPhaseY++; + if (mouseEncoderPhaseY > 3) mouseEncoderPhaseY = 0; + } + // Set the output pins according to the current phase if (mouseEncoderPhaseY == 3) Y1_PORT &= ~Y1; // Set Y1 to 0 if (mouseEncoderPhaseY == 2) Y2_PORT &= ~Y2; // Set Y2 to 0 if (mouseEncoderPhaseY == 1) Y1_PORT |= Y1; // Set Y1 to 1 if (mouseEncoderPhaseY == 0) Y2_PORT |= Y2; // Set Y2 to 1 - // Change phase - if (mouseDirectionY == 0) mouseEncoderPhaseY--; else mouseEncoderPhaseY++; - // Decrement the distance left to move mouseDistanceY--; - - // Range check the phase - if ((mouseDirectionY == 1) && (mouseEncoderPhaseY > 3)) mouseEncoderPhaseY = 0; - if ((mouseDirectionY == 0) && (mouseEncoderPhaseY < 0)) mouseEncoderPhaseY = 3; - } else { - // Reset the phase if the mouse isn't moving - mouseEncoderPhaseY = 0; } // Set the timer top value for the next interrupt