Serial Wombat Arduino Library
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SerialWombatPS2Keyboard Class Reference

A class for the Serial Wombat SW18AB chips which recieves input from IBM PS2 Keyboards. More...

#include <SerialWombatPS2Keyboard.h>

Inheritance diagram for SerialWombatPS2Keyboard:
SerialWombatPin

Public Member Functions

 SerialWombatPS2Keyboard (SerialWombatChip &serialWombat)
 Constructor for the SerialWombatPS2Keyboard class.
More...
 
int16_t begin (uint8_t clockPin, uint8_t dataPin, uint8_t bufferMode=0, uint8_t queueMode=0, uint16_t queueAddress=0xFFFF, uint8_t pullUpDown=0)
 Initalize the SerialWombatPS2Keyboard.
More...
 
int available ()
 Queries the SerialWombatPS2Keyboard for number bytes available to read. More...
 
int read ()
 Reads a byte from the SerialWombatPS2Keyboard queue. More...
 
void flush ()
 Discard all bytes from the SerialWombatPS2Keyboard queue. More...
 
int peek ()
 Query the SerialWombatPS2Keyboard queue for the next avaialble byte, but don't remove it from the queue. More...
 
size_t write (uint8_t data)
 Write a byte to the SerialWombatPS2Keyboard queue (Does Nothing) More...
 
size_t write (const uint8_t *buffer, size_t size)
 Write bytes to the SerialWombatPS2Keyboard queue (Does nothing) More...
 
int availableForWrite ()
 Number of bytes avaialble to write to SerialWombatPS2Keyboard queue. Returns 0. More...
 
size_t readBytes (char *buffer, size_t length)
 Reads a specified number of bytes from the SerialWombatPS2Keyboard queue queue. More...
 
int16_t readCurrentScanCodes (uint8_t *buffer, uint8_t startValue)
 
void setTimeout (long timeout_mS)
 implemented to fulfill Stream requirement. More...
 
uint8_t scanCodeToAscii (uint8_t scanCode, bool shiftActive=false)
 convernts a set 2 Scan Code to Ascii More...
 
bool isKeyPressed (uint8_t scanCode)
 Check to see if a key is currently pressed (pin mode must be configured for bitfield mode) More...
 
bool isKeyPressed (PS2KeyboardScanCode scanCode)
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin. More...
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin. More...
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin. More...
 
void pinMode (uint8_t mode)
 Set pin to INPUT or OUTPUT. More...
 
void pinMode (uint8_t mode, bool pullDown, bool openDrain)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More...
 
void digitalWrite (uint8_t val)
 Set output pin High or Low. More...
 
int digitalRead ()
 Reads the state of the Pin. More...
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin. More...
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes. More...
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data. More...
 

Public Attributes

uint8_t _pin = 255
 

Protected Attributes

uint32_t timeout = 1
 
- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

Detailed Description

A class for the Serial Wombat SW18AB chips which recieves input from IBM PS2 Keyboards.

A Tutorial video is avaialble:

https://youtu.be/TODO

The class inherits from the Arduino Stream class, so queued ps2 keyboard presses can be read like a Serial port.

This class allows the user to declare a PS2 Keyboard. The PS2 Keyboard class is currently only supported on the Serial Wombat 18AB chip.

Warning
The PS2 Keyboard pin mode requires 20 to 25% of the Serial Wombat 18AB chip's processor capacity.
Assigning pin modes which together exceed avaialble processing capacity causes malfunctions within the Serial Wombat chip.

The PS2 Keyboard pin mode requires a clock pin (to which this pin mode is assigned) and an additional data pin. Both should be tied high to 5v with a pull up resistor. I use a 5.1k.

Warning
The PS2 Keyboard inputs are 5V inputs. It is suggested that pins 9,10,11,12,14, or 15 on the Serial Wombat 18AB chip be used for PS2 Keyboard because they are 5V tollerant. Using other pins may damage the Serial Wombat chip.

A video Tutorial on this pin mode is available:

https://youtu.be/YV00GfyxFJU

Constructor & Destructor Documentation

◆ SerialWombatPS2Keyboard()

SerialWombatPS2Keyboard::SerialWombatPS2Keyboard ( SerialWombatChip serialWombat)

Constructor for the SerialWombatPS2Keyboard class.

Parameters
serialWombatThe Serial Wombat Chip on which the SerialWombatPS2Keyboard instance will run.

Member Function Documentation

◆ available()

int SerialWombatPS2Keyboard::available ( )

Queries the SerialWombatPS2Keyboard for number bytes available to read.

Returns
Number of bytes available to read.

◆ availableForWrite()

int SerialWombatPS2Keyboard::availableForWrite ( )

Number of bytes avaialble to write to SerialWombatPS2Keyboard queue. Returns 0.

Returns
Zero. Writes are not suppored.

◆ begin()

int16_t SerialWombatPS2Keyboard::begin ( uint8_t  clockPin,
uint8_t  dataPin,
uint8_t  bufferMode = 0,
uint8_t  queueMode = 0,
uint16_t  queueAddress = 0xFFFF,
uint8_t  pullUpDown = 0 
)

Initalize the SerialWombatPS2Keyboard.

Parameters
clockPinPin attached to the PS2 Keyboard Clock line. This line shoudl be pulled up to 5V with a resistor (5.1k suggested). This pin should be a 5V tolerant pin.
dataPinPin attached to the PS2 Keyboard data line. This line shoudl be pulled up to 5V with a resistor (5.1k suggested). This pin should be a 5V tolerant pin.
bufferMode0: Public data is lower case ASCII of key pressed (Default) 1: Public data is PS2 Keyboard 'make' code of last key pressed or released.
queueMode0: Queued data is ASCII values, taking into account shift keys 1: Queued data is make codes of keys when pressed 2: All PS2 codes are queued 3: A bitfield of held keys is maintained instead of a queue
queueAddressAn optional parameter that allows a previously initialized queue in User RAM on the SW18AB chip to be used instead of the pin mode's internal 16 byte buffer. 0xFFFF uses pin mode buffer.
pullUpDown0: No pull ups or pull downs 1: Internal 3.3v pullup (not recommended) 2: Internal Pulldown (not recommended)

◆ flush()

void SerialWombatPS2Keyboard::flush ( )

Discard all bytes from the SerialWombatPS2Keyboard queue.

◆ isKeyPressed() [1/2]

bool SerialWombatPS2Keyboard::isKeyPressed ( PS2KeyboardScanCode  scanCode)

◆ isKeyPressed() [2/2]

bool SerialWombatPS2Keyboard::isKeyPressed ( uint8_t  scanCode)

Check to see if a key is currently pressed (pin mode must be configured for bitfield mode)

Parameters
scanCodeThe scan code of the key being checked. Set the 0x80 bit if it's an extended code
Returns
returns true if the key is currently pressed

◆ peek()

int SerialWombatPS2Keyboard::peek ( )

Query the SerialWombatPS2Keyboard queue for the next avaialble byte, but don't remove it from the queue.

Returns
A byte from 0-255, or -1 if no bytes were avaialble

◆ read()

int SerialWombatPS2Keyboard::read ( )

Reads a byte from the SerialWombatPS2Keyboard queue.

Returns
A byte from 0-255, or -1 if no bytes were avaialble

◆ readBytes()

size_t SerialWombatPS2Keyboard::readBytes ( char *  buffer,
size_t  length 
)

Reads a specified number of bytes from the SerialWombatPS2Keyboard queue queue.

Parameters
bufferAn array into which to put received bytes
lengthThe maximum number of bytes to be received
Returns
the number of bytes written to buffer

This function will read bytes from the SerialWombatPS2Keyboard queue into buffer. If 'length' characters are not available to read then the value returned will be less than length.

◆ readCurrentScanCodes()

int16_t SerialWombatPS2Keyboard::readCurrentScanCodes ( uint8_t *  buffer,
uint8_t  startValue 
)

◆ scanCodeToAscii()

uint8_t SerialWombatPS2Keyboard::scanCodeToAscii ( uint8_t  scanCode,
bool  shiftActive = false 
)

convernts a set 2 Scan Code to Ascii

This array is used to convert PS2 Code set 2 codes to Ascii. The first column is unshfited data, the second if shift is active

◆ setTimeout()

void SerialWombatPS2Keyboard::setTimeout ( long  timeout_mS)

implemented to fulfill Stream requirement.

◆ write() [1/2]

size_t SerialWombatPS2Keyboard::write ( const uint8_t *  buffer,
size_t  size 
)

Write bytes to the SerialWombatPS2Keyboard queue (Does nothing)

Parameters
bufferAn array of uint8_t bytes to send
sizethe number of bytes to send
Returns
the number of bytes sent

This function exists to fully implement the Stream class. It throws away the bytes.

◆ write() [2/2]

size_t SerialWombatPS2Keyboard::write ( uint8_t  data)

Write a byte to the SerialWombatPS2Keyboard queue (Does Nothing)

Parameters
dataByte to write
Returns
Number of bytes written

This function exists to fully implement the Stream class. It throws away the byte.

Member Data Documentation

◆ _pin

uint8_t SerialWombatPS2Keyboard::_pin = 255

◆ timeout

uint32_t SerialWombatPS2Keyboard::timeout = 1
protected