void printHelp()
{
Serial.printf("\n\nPS/2 Mouse Studio\n");
Serial.printf("Chip Revision: %d Chip Frequency: %d MHz\n", ESP.getChipRevision(), ESP.getCpuFreqMHz());
printInfo();
Serial.printf("Commands:\n");
Serial.printf(" r = Reset s = Change Sample Rate e = Change Resolution c = Change Scaling\n");
Serial.printf("Various:\n");
Serial.printf(" h = Print This help\n\n");
}
void printInfo()
{
Serial.write("Device Id = ");
Serial.write("\"Old AT Keyboard\"");
break;
Serial.write("\"Standard Mouse\"");
break;
Serial.write("\"Mouse with scroll wheel\"");
break;
Serial.write("\"5 Buttons Mouse\"");
break;
Serial.write("\"MF2 Keyboard with translation\"");
break;
Serial.write("\"MF2 keyboard\"");
break;
default:
Serial.write("\"Unknown\"");
break;
}
} else
Serial.write("Mouse Error!");
Serial.write("\n");
}
void setup()
{
Serial.begin(115200);
delay(500);
Serial.write("\n\nReset\n");
printHelp();
}
const uint8_t SampleRates[] = { 10, 20, 40, 60, 80, 100, 200 };
int currentSampleRateIndex = 5;
int currentResolution = 2;
int currentScaling = 1;
void loop()
{
if (Serial.available() > 0) {
char c = Serial.read();
switch (c) {
case 'h':
printHelp();
break;
case 'r':
printInfo();
break;
case 's':
++currentSampleRateIndex;
if (currentSampleRateIndex == sizeof(SampleRates))
currentSampleRateIndex = 0;
Serial.printf("Sample rate = %d\n", SampleRates[currentSampleRateIndex]);
break;
case 'e':
++currentResolution;
if (currentResolution == 4)
currentResolution = 0;
Serial.printf("Resolution = %d\n", 1 << currentResolution);
break;
case 'c':
++currentScaling;
if (currentScaling == 3)
currentScaling = 1;
Serial.printf("Scaling = 1:%d\n", currentScaling);
break;
}
}
MouseDelta mouseDelta;
Serial.printf("deltaX = %d deltaY = %d deltaZ = %d leftBtn = %d midBtn = %d rightBtn = %d\n",
mouseDelta.deltaX, mouseDelta.deltaY, mouseDelta.deltaZ,
mouseDelta.buttons.left, mouseDelta.buttons.middle, mouseDelta.buttons.right);
}
}