Skip to content

Commit

Permalink
Merge pull request #14 from simoninns/issue-12-dev
Browse files Browse the repository at this point in the history
Issue 12 and 10 fixes
  • Loading branch information
Simon Inns authored Jul 30, 2020
2 parents 25246bf + 3f1aff5 commit 5b025b9
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions SmallyMouse2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -429,7 +427,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
Expand Down

0 comments on commit 5b025b9

Please sign in to comment.