ESP32VGA
ESP32 VGA Controller and Graphics Library
Public Member Functions | List of all members
FabGL::KeyboardClass Class Reference

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...
 

Detailed Description

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)));

Member Function Documentation

◆ begin()

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.

Parameters
clkGPIOThe GPIO number of Clock line
dataGPIOThe GPIO number of Data line
generateVirtualKeysIf true creates a task which consumes scancodes and produces virtual keys, so you can call KeyboardClass.isVKDown().
createVKQueueIf 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

◆ getLayout()

KeyboardLayout const* FabGL::KeyboardClass::getLayout ( )
inline

Get current keyboard layout.

Returns
The default or last set keyboard layout.

◆ getNextVirtualKey()

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.

Parameters
keyDownA pointer to boolean variable which will contain if the virtual key is depressed (true) or released (false).
timeOutMSTimeout in milliseconds. -1 means no timeout (infinite time).
Returns
The first virtual key of the queue (VK_NONE if no data is available in the timeout period).

◆ isKeyboardAvailable()

bool FabGL::KeyboardClass::isKeyboardAvailable ( )
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.

Returns
True if the keyboard is correctly initialized.

◆ isVKDown()

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).

Parameters
virtualKeyThe Virtual Key to test.
Returns
True if the specified virtual key is down.

◆ reset()

bool FabGL::KeyboardClass::reset ( )

Send a Reset command to the keyboard.

Returns
True if the keyboard is correctly initialized.

◆ setLayout()

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.

Parameters
layoutA pointer to the layout structure.

Example:

// Set German layout
setLayout(&FabGL::GermanLayout);

◆ virtualKeyAvailable()

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.

Returns
The number of virtual keys available to read.

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