FabGL
ESP32 Display Controller and Graphics Library
Keyboard Class Reference

The PS2 Keyboard controller class. More...

#include <keyboard.h>

Inheritance diagram for Keyboard:

Public Member Functions

void begin (bool generateVirtualKeys, bool createVKQueue, int PS2Port)
 Initializes Keyboard without initializing the PS/2 controller. More...
 
void begin (gpio_num_t clkGPIO, gpio_num_t dataGPIO, bool generateVirtualKeys=true, bool createVKQueue=true)
 Initializes Keyboard specifying CLOCK and DATA GPIOs. More...
 
void emptyVirtualKeyQueue ()
 Empties the virtual keys queue. More...
 
void enableVirtualKeys (bool generateVirtualKeys, bool createVKQueue)
 Dynamically enables or disables Virtual Keys generation. More...
 
KeyboardLayout const * getLayout ()
 Gets current keyboard layout. More...
 
void getLEDs (bool *numLock, bool *capsLock, bool *scrollLock)
 Gets keyboard LEDs status. More...
 
int getNextScancode (int timeOutMS=-1, bool requestResendOnTimeOut=false)
 Gets a scancode from the queue. More...
 
VirtualKey getNextVirtualKey (bool *keyDown=nullptr, int timeOutMS=-1)
 Gets a virtual key from the queue. More...
 
bool getNextVirtualKey (VirtualKeyItem *item, int timeOutMS=-1)
 Gets a virtual key from the queue, including associated scan code. More...
 
PS2DeviceType identify ()
 Identifies the device attached to the PS2 port. More...
 
void injectVirtualKey (VirtualKey virtualKey, bool keyDown, bool insert=false)
 Adds or inserts a virtual key into the virtual keys queue. More...
 
void injectVirtualKey (VirtualKeyItem const &item, bool insert=false)
 Adds or inserts a virtual key info into the virtual keys queue. More...
 
bool isKeyboardAvailable ()
 Checks if keyboard has been detected and correctly initialized. More...
 
bool isVKDown (VirtualKey virtualKey)
 Gets the virtual keys status. More...
 
bool lock (int timeOutMS)
 Gets exclusive access to the device. More...
 
bool reset ()
 Sends a Reset command to the keyboard. More...
 
void resumePort ()
 Resumes PS/2 port releasing CLK line. More...
 
int scancodeAvailable ()
 Gets the number of scancodes available in the queue. More...
 
int scancodeSet ()
 Gets current scancode set. More...
 
void sendCommand (uint8_t cmd)
 Sends a raw command to the PS/2 device. More...
 
bool sendCommand (uint8_t cmd, uint8_t expectedReply)
 Sends a raw command to the PS/2 device and wait for reply. More...
 
void setCodePage (CodePage const *codepage)
 Sets font codepage for virtual key to ASCII conversion. More...
 
void setLayout (KeyboardLayout const *layout)
 Sets keyboard layout. More...
 
bool setLEDs (bool numLock, bool capsLock, bool scrollLock)
 Sets keyboard LEDs status. More...
 
bool setScancodeSet (int value)
 Sets the scancode set. More...
 
bool setTypematicRateAndDelay (int repeatRateMS, int repeatDelayMS)
 Sets typematic rate and delay. More...
 
void setUIApp (uiApp *app)
 Sets current UI app. More...
 
void suspendPort ()
 Suspends PS/2 port driving the CLK line Low. More...
 
void unlock ()
 Releases device from exclusive access. More...
 
int virtualKeyAvailable ()
 Gets the number of virtual keys available in the queue. More...
 
int virtualKeyToASCII (VirtualKey virtualKey)
 Converts virtual key to ASCII. More...
 

Public Attributes

Delegate< VirtualKey *, bool > onVirtualKey
 Delegate called whenever a new virtual key is decoded from scancodes. More...
 

Static Public Attributes

static int scancodeToVirtualKeyTaskStackSize = FABGLIB_DEFAULT_SCODETOVK_TASK_STACK_SIZE
 Stack size of the task that converts scancodes to Virtual Keys Keyboard. More...
 

Detailed Description

The PS2 Keyboard controller class.

Keyboard connects to one port of the PS2 Controller class (fabgl::PS2Controller) 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 several predefined kayboard layouts: US (USA), UK (United Kingdom), DE (German), IT (Italian), ES (Spanish), FR (French), BE (Belgian) and NO (Norwegian). Other layout can be added inheriting from US or from any other layout.

Applications do not need to create an instance of Keyboard because an instance named Keyboard is created automatically.

Example:

fabgl::Keyboard Keyboard;

// 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
while (true)
  Serial.printf("VirtualKey = %s\n", Keyboard.virtualKeyToString(Keyboard.getNextVirtualKey()));

Definition at line 77 of file keyboard.h.


The documentation for this class was generated from the following files: