ESP32VGA
ESP32 VGA Controller and Graphics Library
|
The PS2 Keyboard controller class. More...
#include <keyboard.h>
Public Member Functions | |
void | begin (gpio_num_t clkGPIO, gpio_num_t dataGPIO, bool generateVirtualKeys=true, bool createVKQueue=true) |
Initialize KeyboardClass specifying CLOCK and DATA GPIOs. More... | |
bool | reset () |
Send a Reset command to the keyboard. More... | |
bool | isKeyboardAvailable () |
Return true if a keyboard has been detected and correctly initialized. More... | |
void | setLayout (KeyboardLayout const *layout) |
Set keyboard layout. More... | |
KeyboardLayout const * | getLayout () |
Get current keyboard layout. More... | |
bool | isVKDown (VirtualKey virtualKey) |
Get the virtual keys status. More... | |
uint8_t | virtualKeyAvailable () |
Get the number of virtual keys available in the keyboard queue. More... | |
VirtualKey | getNextVirtualKey (bool *keyDown=NULL, int32_t timeOutMS=-1) |
Get a virtual key from the keyboard queue. More... | |
The PS2 Keyboard controller class.
KeyboardClass interfaces directly to PS2 Controller class (FabGL::PS2ControllerClass) and provides the logic that converts scancodes to virtual keys or ASCII (and ANSI) codes. It optionally creates a task that waits for scan codes from the PS2 device and puts virtual keys in a queue. The PS2 controller uses ULP coprocessor and RTC slow memory to communicate with the PS2 device.
It is possible to specify an international keyboard layout. The default is US-layout. There are three predefined kayboard layouts: US (USA), UK (United Kingdom), DE (German) and IT (Italian). Other layout can be added inheriting from US or from any other layout.
Applications do not need to create an instance of KeyboardClass because an instance named Keyboard is created automatically.
Example:
// Setup pins GPIO33 for CLK and GPIO32 for DATA Keyboard.begin(GPIO_NUM_33, GPIO_NUM_32); // clk, dat // Prints name of received virtual keys bool down; while (true) Serial.printf("VirtualKey = %s\n", Keyboard.virtualKeyToString(Keyboard.getNextVirtualKey(&down)));
void FabGL::KeyboardClass::begin | ( | gpio_num_t | clkGPIO, |
gpio_num_t | dataGPIO, | ||
bool | generateVirtualKeys = true , |
||
bool | createVKQueue = true |
||
) |
Initialize KeyboardClass specifying CLOCK and DATA GPIOs.
A reset command (KeyboardClass.reset() method) is automatically sent to the keyboard.
clkGPIO | The GPIO number of Clock line |
dataGPIO | The GPIO number of Data line |
generateVirtualKeys | If true creates a task which consumes scancodes and produces virtual keys, so you can call KeyboardClass.isVKDown(). |
createVKQueue | If true creates a task which consunes scancodes and produces virtual keys and put them in a queue, so you can call KeyboardClass.isVKDown(), KeyboardClass.scancodeAvailable() and KeyboardClass.getNextScancode. |
Example:
// Setup pins GPIO33 for CLK and GPIO32 for DATA Keyboard.begin(GPIO_NUM_33, GPIO_NUM_32); // clk, dat
|
inline |
Get current keyboard layout.
VirtualKey FabGL::KeyboardClass::getNextVirtualKey | ( | bool * | keyDown = NULL , |
int32_t | timeOutMS = -1 |
||
) |
Get a virtual key from the keyboard queue.
Virtual keys are generated from scancodes only if generateVirtualKeys parameter is true (default) and createVKQueue parameter is true (default) of KeyboardClass.begin() method.
keyDown | A pointer to boolean variable which will contain if the virtual key is depressed (true) or released (false). |
timeOutMS | Timeout in milliseconds. -1 means no timeout (infinite time). |
|
inline |
Return true if a keyboard has been detected and correctly initialized.
isKeyboardAvailable() returns a valid value only after KeyboardClass.begin() or KeyboardClass.reset() has been called.
bool FabGL::KeyboardClass::isVKDown | ( | VirtualKey | virtualKey | ) |
Get the virtual keys status.
This method allows to know the status of each virtual key (Down or Up). Virtual keys are generated from scancodes only if generateVirtualKeys parameter of KeyboardClass.begin() method is true (default).
virtualKey | The Virtual Key to test. |
bool FabGL::KeyboardClass::reset | ( | ) |
Send a Reset command to the keyboard.
void FabGL::KeyboardClass::setLayout | ( | KeyboardLayout const * | layout | ) |
Set keyboard layout.
It is possible to specify an international keyboard layout. The default is US-layout. There are three predefined kayboard layouts: US (USA), UK (United Kingdom), DE (German) and IT (Italian). Other layout can be added inheriting from US or from any other layout.
layout | A pointer to the layout structure. |
Example:
// Set German layout setLayout(&FabGL::GermanLayout);
uint8_t FabGL::KeyboardClass::virtualKeyAvailable | ( | ) |
Get the number of virtual keys available in the keyboard queue.
Virtual keys are generated from scancodes only if generateVirtualKeys parameter is true (default) and createVKQueue parameter is true (default) of KeyboardClass.begin() method.