Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SerialWombatMatrixKeypad Class Reference

A class for the Serial Wombat SW18AB chips which scans matrix keypads up to 4x4. More...

`#include <SerialWombatMatrixKeypad.h>`

Inheritance diagram for SerialWombatMatrixKeypad:
[legend]
Collaboration diagram for SerialWombatMatrixKeypad:
[legend]

## Public Member Functions
| SerialWombatMatrixKeypad (SerialWombatChip &serialWombat)
| Constructor for the SerialWombatMatrixKeypad class.
int16_t | begin (uint8_t controlPin, uint8_t row0pin, uint8_t row1pin, uint8_t row2pin, uint8_t row3pin, uint8_t column0pin, uint8_t column1pin, uint8_t column2pin, uint8_t column3pin, uint8_t bufferMode=0, uint8_t queueMode=1, uint8_t rowTiming=5)
| Initalize the SerialWombatMatrixKeypad.
int16_t | writeQueueMask (uint16_t mask)
| Set a binary mask for which keys are added to Queue.
int16_t | writeAsciiTable (uint8_t tableIndex, uint8_t asciiValue)
| Change the default ASCII output for each key.
int | available ()
| Queries the SerialWombatMatrixKeypad for number bytes available to read.
int | read ()
| Reads a byte from the SerialWombatMatrixKeypad queue.
void | flush ()
| Discard all bytes from the SerialWombatMatrixKeypad queue.
int | peek ()
| Query the SerialWombatMatrixKeypad 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 SerialWombatMatrixKeypad queue (Does Nothing)
size_t | write (const uint8_t *buffer, size_t size)
| Write bytes to the SerialWombatMatrixKeypad queue (Does nothing)
int | availableForWrite ()
| Number of bytes avaialble to write to SerialWombatMatrixKeypad queue. Returns 0.
size_t | readBytes (char *buffer, size_t length)
| Reads a specified number of bytes from the SerialWombatMatrixKeypad queue queue.
void | setTimeout (long timeout_mS)
| implemented to fulfill Stream requirement.
SerialWombatMatrixKeypad & | operator= (SerialWombatMatrixKeypad &kp)
| used to allow reference copy. Not for user use.

## Public Attributes
SerialWombatChip & | _sw
uint8_t | _pin = 255

## Protected Attributes
uint32_t | timeout = 1

## Detailed Description

A class for the Serial Wombat SW18AB chips which scans matrix keypads up to 4x4.

A Tutorial video is avaialble:

https://youtu.be/hxLda6lBWNg

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

This class allows the user to declare up to 4 row and 4 column pins which are strobed continuously to read up to 16 buttons. The Serial Wombat chip's internal pull-up resistors are used so no additional hardware is necesary. Standard matrix keypads can be attached directly to the Serial Wombat chip pins. All Serial Wombat 18AB chip pins can be used in any combination or order.

Results can be returned to the host as a binary 16 bit number indicating the state of 16 buttons, as an index indicating which button is currently pressed (0 for Col 0 Row 0, 3 for Col 3 Row 3 and 12 for Col 0 Row 3, or as ASCII values which assume a standard keypad layout.

Index mode:

    |0  1  2  3 |
    |4  5  6  7 |
    |8  9  10 11|
    |12 13 14 15|
    With 16 being used for no current press, depending on mode setting

Ascii Mode:

    |1 2 3 A|
    |4 5 6 B|
    |7 8 9 C|
    |* 0 # D|

Note that the key indexes remain the same regardless of how many rows and columns are enabled.

The Serial Wombat 18AB firmware also keeps track of button transition counts and time since last transition for all 16 buttons. In this way each key of the keypad can be treated equivalently to a SerialWombatDebouncedInput class when encapsulated in a SerialWombatMatrixInput class. See the documentation on this class and Arduino examples for details.

The 16 Bit public data presented internally to other Serial Wombat pins and through the SerialWombatChip.readPublicData method can be configured to present the binary state of 16 buttons, the last button index pressed, the last button index pressed or 16 if no button is pressed, or ASCII of last button pressed.

Definition at line 87 of file SerialWombatMatrixKeypad.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatMatrixKeypad()

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

Constructor for the SerialWombatMatrixKeypad class.

Parameters

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

Definition at line 95 of file SerialWombatMatrixKeypad.h.

## Member Function Documentation

## ◆ available()

int SerialWombatMatrixKeypad::available | ( |  | ) |
| inline

Queries the SerialWombatMatrixKeypad for number bytes available to read.

Returns
  Number of bytes available to read.

Definition at line 209 of file SerialWombatMatrixKeypad.h.

## ◆ availableForWrite()

int SerialWombatMatrixKeypad::availableForWrite | ( |  | ) |
| inline

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

Returns
  Zero. Writes are not suppored.

Definition at line 295 of file SerialWombatMatrixKeypad.h.

## ◆ begin()

int16_t SerialWombatMatrixKeypad::begin | ( | uint8_t | controlPin,
|  | uint8_t | row0pin,
|  | uint8_t | row1pin,
|  | uint8_t | row2pin,
|  | uint8_t | row3pin,
|  | uint8_t | column0pin,
|  | uint8_t | column1pin,
|  | uint8_t | column2pin,
|  | uint8_t | column3pin,
|  | uint8_t | bufferMode = 0,
|  | uint8_t | queueMode = 1,
|  | uint8_t | rowTiming = 5 )
| inline

Initalize the SerialWombatMatrixKeypad.

Parameters

  controlPin | Keypad scanning transitions will occur while this pin is being serviced by the Serial Wombat executive. Typically this will be the same as the row0 pin
  row0pin | pin attached to the topmost keypad row. On many marked keypads this row has 1,2,3 and A in it. Enter 255 if this column is unused
  row1pin | pin attached to the topcenter keypad row. On many marked keypads this row has 4,5,6 and B in it. Enter 255 if this row is unused
  row2pin | pin attached to the topmost keypad row. On many marked keypads this row has 7,8,9 and C in it. Enter 255 if this row is unused
  row3pin | pin attached to the topmost keypad row. On many marked keypads this row has *,0,# and D in it. Enter 255 if this row is unused
  column0pin | pin attached to the leftmost keypad column. On many marked keypads this column has 1,4,7 and * in it. Enter 255 if this column is unused
  column1pin | pin attached to the leftcenter keypad column. On many marked keypads this column has 1,5,8 and 0 in it. Enter 255 if this column is unused
  column2pin | pin attached to the rightcenter keypad column. On many marked keypads this column has 3,5,9 and # in it. Enter 255 if this column is unused
  column3pin | pin attached to the rightmost keypad column. On many marked keypads this column has A,B,C and D in it. Enter 255 if this column is unused
  bufferMode | 0: Public data is Binary of 16 keys (Default) 1: Public data is last key index pressed 2: Public data is last key pressed or 16 for no key index 3: Public data is Ascii of last key pressed
  queueMode | 0: Button presses are queued as indexes 1: Button Presses are queued as ASCII
  rowTiming | mS to delay after setting a pin row low before reading columns

Definition at line 114 of file SerialWombatMatrixKeypad.h.

## ◆ flush()

void SerialWombatMatrixKeypad::flush | ( |  | ) |
| inline

Discard all bytes from the SerialWombatMatrixKeypad queue.

Definition at line 240 of file SerialWombatMatrixKeypad.h.

## ◆ operator=()

SerialWombatMatrixKeypad & SerialWombatMatrixKeypad::operator= | ( | SerialWombatMatrixKeypad & | kp | ) |
| inline

used to allow reference copy. Not for user use.

Definition at line 375 of file SerialWombatMatrixKeypad.h.

## ◆ peek()

int SerialWombatMatrixKeypad::peek | ( |  | ) |
| inline

Query the SerialWombatMatrixKeypad 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 248 of file SerialWombatMatrixKeypad.h.

## ◆ read()

int SerialWombatMatrixKeypad::read | ( |  | ) |
| inline

Reads a byte from the SerialWombatMatrixKeypad queue.

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

Definition at line 221 of file SerialWombatMatrixKeypad.h.

## ◆ readBytes()

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

Reads a specified number of bytes from the SerialWombatMatrixKeypad 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 SerialWombatMatrixKeypad queue into buffer. If 'length' characters are not available to read then the value returned will be less than length.

Definition at line 310 of file SerialWombatMatrixKeypad.h.

## ◆ setTimeout()

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

implemented to fulfill Stream requirement.

Definition at line 359 of file SerialWombatMatrixKeypad.h.

## ◆ write() [1/2]

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

Write bytes to the SerialWombatMatrixKeypad 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 285 of file SerialWombatMatrixKeypad.h.

## ◆ write() [2/2]

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

Write a byte to the SerialWombatMatrixKeypad 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 270 of file SerialWombatMatrixKeypad.h.

## ◆ writeAsciiTable()

int16_t SerialWombatMatrixKeypad::writeAsciiTable | ( | uint8_t | tableIndex,
|  | uint8_t | asciiValue )
| inline

Change the default ASCII output for each key.

By default the keypad outputs 123A / 456B / 789C / *0 # D This can be changed by calling this function. Each call sets one byte in a 16 byte array changing the output. For example, the pin which normally outputs B could be made to output 'G' by calling this function with an index 7 and a value (byte)'G'.

This function would be called 16 times to configure the whole table

Parameters

  tableIndex | A value from 0 to 15 indicating the key index .
  asciiValue | The Ascii Vaule to store in the table

Returns
  Returns 0 or higher if successfully set or a negative error code otherwise.

Definition at line 198 of file SerialWombatMatrixKeypad.h.

## ◆ writeQueueMask()

int16_t SerialWombatMatrixKeypad::writeQueueMask | ( | uint16_t | mask | ) |
| inline

Set a binary mask for which keys are added to Queue.

This commands allows exclusion of keys from being queued. This can be useful if, for instance, only the numeric keys of a keypad are to be added to the queue (excluding #,*, ABCD, etc)

Parameters

  mask | A 16 bit bitmap where a 1 allows queuing of that key index and a 0 does not. Index 0 is LSB. For instance, for a typical Phone/ABCD keypad, a mask of 0x2777 would allow the numeric keys to be added to the queue but would exclude ABCD#* .

Returns
  Returns 0 or higher if successfully set or a negative error code otherwise.

Definition at line 174 of file SerialWombatMatrixKeypad.h.

## Member Data Documentation

## ◆ _pin

uint8_t SerialWombatMatrixKeypad::_pin = 255

Definition at line 382 of file SerialWombatMatrixKeypad.h.

## ◆ _sw

SerialWombatChip& SerialWombatMatrixKeypad::_sw

Definition at line 381 of file SerialWombatMatrixKeypad.h.

## ◆ timeout

uint32_t SerialWombatMatrixKeypad::timeout = 1
| protected

Definition at line 384 of file SerialWombatMatrixKeypad.h.