Serial Wombat Arduino Library

Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for SerialWombatPS2Keyboard:
[legend]

## Public Member Functions
| SerialWombatPS2Keyboard (SerialWombatChip &serialWombat)
| Constructor for the SerialWombatPS2Keyboard class.
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.
int | available ()
| Queries the SerialWombatPS2Keyboard for number bytes available to read.
int | read ()
| Reads a byte from the SerialWombatPS2Keyboard queue.
void | flush ()
| Discard all bytes from the SerialWombatPS2Keyboard queue.
int | peek ()
| Query the SerialWombatPS2Keyboard queue for the next avaialble byte, but don't remove it from the queue.
size_t | write (uint8_t data)
| Write a byte to the SerialWombatPS2Keyboard queue (Does Nothing)
size_t | write (const uint8_t *buffer, size_t size)
| Write bytes to the SerialWombatPS2Keyboard queue (Does nothing)
int | availableForWrite ()
| Number of bytes avaialble to write to SerialWombatPS2Keyboard queue. Returns 0.
size_t | readBytes (char *buffer, size_t length)
| Reads a specified number of bytes from the SerialWombatPS2Keyboard queue queue.
int16_t | readCurrentScanCodes (uint8_t *buffer, uint8_t startValue)
void | setTimeout (long timeout_mS)
| implemented to fulfill Stream requirement.
uint8_t | scanCodeToAscii (uint8_t scanCode, bool shiftActive=false)
| convernts a set 2 Scan Code to Ascii
bool | isKeyPressed (uint8_t scanCode)
| Check to see if a key is currently pressed (pin mode must be configured for bitfield mode)
bool | isKeyPressed (PS2KeyboardScanCode scanCode)
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
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.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
int16_t | enablePulldown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
int16_t | forceDMA (bool enabled)
| Forces use of DMA instead of hardware timing resources on SW18AB.
void | setPinNumberForTesting (uint8_t pin)
| A function designed for testing only. May have unpredictable results if used in real time. Not intended for general use.

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

Definition at line 181 of file SerialWombatPS2Keyboard.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatPS2Keyboard()

SerialWombatPS2Keyboard::SerialWombatPS2Keyboard | ( | SerialWombatChip & | serialWombat | ) |
| inline

Constructor for the SerialWombatPS2Keyboard class.

Parameters

  serialWombat | The Serial Wombat Chip on which the SerialWombatPS2Keyboard instance will run.

Definition at line 189 of file SerialWombatPS2Keyboard.h.

## Member Function Documentation

## ◆ available()

int SerialWombatPS2Keyboard::available | ( |  | ) |
| inline

Queries the SerialWombatPS2Keyboard for number bytes available to read.

Returns
  Number of bytes available to read.

Definition at line 239 of file SerialWombatPS2Keyboard.h.

## ◆ availableForWrite()

int SerialWombatPS2Keyboard::availableForWrite | ( |  | ) |
| inline

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

Returns
  Zero. Writes are not suppored.

Definition at line 327 of file SerialWombatPS2Keyboard.h.

## ◆ 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 )
| inline

Initalize the SerialWombatPS2Keyboard.

Parameters

  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)

Definition at line 199 of file SerialWombatPS2Keyboard.h.

## ◆ flush()

void SerialWombatPS2Keyboard::flush | ( |  | ) |
| inline

Discard all bytes from the SerialWombatPS2Keyboard queue.

Definition at line 271 of file SerialWombatPS2Keyboard.h.

## ◆ isKeyPressed() [1/2]

bool SerialWombatPS2Keyboard::isKeyPressed | ( | PS2KeyboardScanCode | scanCode | ) |
| inline

Definition at line 601 of file SerialWombatPS2Keyboard.h.

## ◆ isKeyPressed() [2/2]

bool SerialWombatPS2Keyboard::isKeyPressed | ( | uint8_t | scanCode | ) |
| inline

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

Parameters

  scanCode | The 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

Definition at line 582 of file SerialWombatPS2Keyboard.h.

## ◆ peek()

int SerialWombatPS2Keyboard::peek | ( |  | ) |
| inline

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

Definition at line 280 of file SerialWombatPS2Keyboard.h.

## ◆ read()

int SerialWombatPS2Keyboard::read | ( |  | ) |
| inline

Reads a byte from the SerialWombatPS2Keyboard queue.

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

Definition at line 250 of file SerialWombatPS2Keyboard.h.

## ◆ readBytes()

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

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

Parameters

  buffer | An array into which to put received bytes
  length | The 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.

Definition at line 342 of file SerialWombatPS2Keyboard.h.

## ◆ readCurrentScanCodes()

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

Definition at line 388 of file SerialWombatPS2Keyboard.h.

## ◆ scanCodeToAscii()

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

convernts a set 2 Scan Code to Ascii

Definition at line 429 of file SerialWombatPS2Keyboard.h.

## ◆ setTimeout()

void SerialWombatPS2Keyboard::setTimeout | ( | long | timeout_mS | ) |
| inline

implemented to fulfill Stream requirement.

Definition at line 414 of file SerialWombatPS2Keyboard.h.

## ◆ write() [1/2]

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

Write bytes to the SerialWombatPS2Keyboard queue (Does nothing)

Parameters

  buffer | An array of uint8_t bytes to send
  size | the 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.

Definition at line 317 of file SerialWombatPS2Keyboard.h.

## ◆ write() [2/2]

size_t SerialWombatPS2Keyboard::write | ( | uint8_t | data | ) |
| inline

Write a byte to the SerialWombatPS2Keyboard queue (Does Nothing)

Parameters

  data | Byte to write

Returns
  Number of bytes written

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

Definition at line 302 of file SerialWombatPS2Keyboard.h.

## Member Data Documentation

## ◆ _pin

uint8_t SerialWombatPS2Keyboard::_pin = 255

Definition at line 606 of file SerialWombatPS2Keyboard.h.

## ◆ timeout

uint32_t SerialWombatPS2Keyboard::timeout = 1
| protected

Definition at line 608 of file SerialWombatPS2Keyboard.h.