Hello All!
I have a trackpad used as a mouse in relative mode. I don't have absolute positioning, so I'm using x, y relative data to make a detectable pattern to start scrolling.
I am able to get direction using x,y and form a recognizable pattern over elapsed time, the data repeats in this pattern but not necessary starts at 1 or ends at 4.
CW gesture on trackpad: Data: 1234... and repeats
CCW gesture on trackpad: Data: 4321...and repeats
I've seemed to have solved the issue using arrays and 4 inputs but cant seem to be able to compare arrays to known CW and CCW list in arrays. Thanks for all your advice.
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis <= period) //test whether the period has elapsed
{
if (data.y < 0) {
if (data.x < 0) {
//Serial.println(" NE ");
direction = 1;
} else if (data.x > 0) {
//Serial.println(" NW ");
direction = 4;
}
} else if (data.y > 0) {
if (data.x < 0) {
//Serial.println(" SE ");
direction = 2;
} else if (data.x > 0) {
//Serial.println(" SW ")
direction = 3;
}
}
if (direction != oldDirection){
//Serial.print(direction);
input[i] = direction;
//Serial.print(input[i]);
i++;
if (i > 3)
i = 0;
}
oldDirection = direction;
} ///END OF PERIOD
else {
Serial.println(" END ");
startMillis = currentMillis; //IMPORTANT to save the restart start time.
///LOGIC FOR SCROLLING GREYCODE?
//CW INC Scroll
int* final[4] = {&input[1], &input[2], &input[3], &input[4]};
int CW[4] = {1234,4123,2341,3412};
int CCW[4] = {4321,1432,3214,2143};
for (int outer = 0; outer < 3; outer++){
for (int inner = 0; inner < 3; inner++){
if (!memcmp(final[outer], CW[inner], 4))
Mouse.move(0,0,1);
else if (!memcmp(final[outer], CCW[inner], 4))
Mouse.move(0,0,-1);
}
}
///CLEAR THE ARRAY
for (int x = 0; x < 4; x++)
input[x];
}
I can solve it using this bit of code but not seems clunky. Is there a way to pool the data to greycode?
///CW INC SCROLL
if (input[0] == 1 && input[1] == 2 && input[2] == 3 && input[3] == 4)
Mouse.move(0,0,1);
else if (input[0] == 4 && input[1] == 1 && input[2] == 2 && input[3] == 3)
Mouse.move(0,0,1);
else if (input[0] == 2 && input[1] == 3 && input[2] == 4 && input[3] == 1)
Mouse.move(0,0,1);
else if (input[0] == 3 && input[1] == 4 && input[2] == 1 && input[3] == 2)
Mouse.move(0,0,1);
//CCW DEC Scroll
else if (input[0] == 4 && input[1] == 3 && input[2] == 2 && input[3] == 1)
Mouse.move(0,0,-1);
else if (input[0] == 1 && input[1] == 4 && input[2] == 3 && input[3] == 2)
Mouse.move(0,0,-1);
else if (input[0] == 3 && input[1] == 2 && input[2] == 1 && input[3] == 4)
Mouse.move(0,0,-1);
else if (input[0] == 2 && input[1] == 1 && input[2] == 4 && input[3] == 3)
Mouse.move(0,0,-1);