![]() |
Serial Wombat Arduino Library
|
A class for the Serial Wombat SW18AB chips which recieves input from IBM PS2 Keyboards. More...
#include <SerialWombatPS2Keyboard.h>
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) |
![]() | |
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, bool pullDown=false, bool openDrain=false) |
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 |
![]() | |
uint8_t | _pin = 255 |
SerialWombatChip & | _sw |
uint8_t | _pinMode = 0 |
A class for the Serial Wombat SW18AB chips which recieves input from IBM PS2 Keyboards.
A Tutorial video is avaialble:
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.
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.
A video Tutorial on this pin mode is available:
SerialWombatPS2Keyboard::SerialWombatPS2Keyboard | ( | SerialWombatChip & | serialWombat | ) |
Constructor for the SerialWombatPS2Keyboard class.
serialWombat | The Serial Wombat Chip on which the SerialWombatPS2Keyboard instance will run. |
int SerialWombatPS2Keyboard::available | ( | ) |
Queries the SerialWombatPS2Keyboard for number bytes available to read.
int SerialWombatPS2Keyboard::availableForWrite | ( | ) |
Number of bytes avaialble to write to SerialWombatPS2Keyboard queue. Returns 0.
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.
clockPin | Pin 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. |
dataPin | Pin 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. |
bufferMode | 0: Public data is lower case ASCII of key pressed (Default) 1: Public data is PS2 Keyboard 'make' code of last key pressed or released. |
queueMode | 0: 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 |
queueAddress | An 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. |
pullUpDown | 0: No pull ups or pull downs 1: Internal 3.3v pullup (not recommended) 2: Internal Pulldown (not recommended) |
void SerialWombatPS2Keyboard::flush | ( | ) |
Discard all bytes from the SerialWombatPS2Keyboard queue.
bool SerialWombatPS2Keyboard::isKeyPressed | ( | PS2KeyboardScanCode | scanCode | ) |
bool SerialWombatPS2Keyboard::isKeyPressed | ( | uint8_t | scanCode | ) |
Check to see if a key is currently pressed (pin mode must be configured for bitfield mode)
scanCode | The scan code of the key being checked. Set the 0x80 bit if it's an extended code |
int SerialWombatPS2Keyboard::peek | ( | ) |
Query the SerialWombatPS2Keyboard queue for the next avaialble byte, but don't remove it from the queue.
int SerialWombatPS2Keyboard::read | ( | ) |
Reads a byte from the SerialWombatPS2Keyboard queue.
size_t SerialWombatPS2Keyboard::readBytes | ( | char * | buffer, |
size_t | length | ||
) |
Reads a specified number of bytes from the SerialWombatPS2Keyboard queue queue.
buffer | An array into which to put received bytes |
length | The maximum number of bytes to be received |
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.
int16_t SerialWombatPS2Keyboard::readCurrentScanCodes | ( | uint8_t * | buffer, |
uint8_t | startValue | ||
) |
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
void SerialWombatPS2Keyboard::setTimeout | ( | long | timeout_mS | ) |
implemented to fulfill Stream requirement.
size_t SerialWombatPS2Keyboard::write | ( | const uint8_t * | buffer, |
size_t | size | ||
) |
Write bytes to the SerialWombatPS2Keyboard queue (Does nothing)
buffer | An array of uint8_t bytes to send |
size | the number of bytes to send |
This function exists to fully implement the Stream class. It throws away the bytes.
size_t SerialWombatPS2Keyboard::write | ( | uint8_t | data | ) |
Write a byte to the SerialWombatPS2Keyboard queue (Does Nothing)
data | Byte to write |
This function exists to fully implement the Stream class. It throws away the byte.
uint8_t SerialWombatPS2Keyboard::_pin = 255 |
|
protected |