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()
{
auto mouse = PS2Controller.
mouse();
if (mouse->isMouseAvailable()) {
Serial.write("Device Id = ");
switch (mouse->identify()) {
case PS2DeviceType::OldATKeyboard:
Serial.write("\"Old AT Keyboard\"");
break;
case PS2DeviceType::MouseStandard:
Serial.write("\"Standard Mouse\"");
break;
case PS2DeviceType::MouseWithScrollWheel:
Serial.write("\"Mouse with scroll wheel\"");
break;
case PS2DeviceType::Mouse5Buttons:
Serial.write("\"5 Buttons Mouse\"");
break;
case PS2DeviceType::MF2KeyboardWithTranslation:
Serial.write("\"MF2 Keyboard with translation\"");
break;
case PS2DeviceType::M2Keyboard:
Serial.write("\"MF2 keyboard\"");
break;
default:
Serial.write("\"Unknown\"");
break;
}
} else
Serial.write("Mouse Error!");
Serial.write("\n");
}
void setup()
{
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()
{
auto mouse = PS2Controller.
mouse();
if (Serial.available() > 0) {
char c = Serial.read();
switch (c) {
case 'h':
printHelp();
break;
case 'r':
mouse->reset();
printInfo();
break;
case 's':
++currentSampleRateIndex;
if (currentSampleRateIndex == sizeof(SampleRates))
currentSampleRateIndex = 0;
if (mouse->setSampleRate(SampleRates[currentSampleRateIndex]))
Serial.printf("Sample rate = %d\n", SampleRates[currentSampleRateIndex]);
break;
case 'e':
++currentResolution;
if (currentResolution == 4)
currentResolution = 0;
if (mouse->setResolution(currentResolution))
Serial.printf("Resolution = %d\n", 1 << currentResolution);
break;
case 'c':
++currentScaling;
if (currentScaling == 3)
currentScaling = 1;
if (mouse->setScaling(currentScaling))
Serial.printf("Scaling = 1:%d\n", currentScaling);
break;
}
}
if (mouse->deltaAvailable()) {
MouseDelta mouseDelta;
mouse->getNextDelta(&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);
}
}
void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO)
Initializes Mouse specifying CLOCK and DATA GPIOs.
static Mouse * mouse()
Returns the instance of Mouse object automatically created by PS2Controller.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes PS2 device controller.
The PS2 device controller class.
This file is the all in one include file. Application can just include this file to use FabGL library...