Serial Wombat Arduino Library
SerialWombatMatrixKeypad.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4 Copyright 2021 Broadwell Consulting Inc.
5 
6 "Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
7 the United States. See SerialWombat.com for usage guidance.
8 
9 Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26 */
27 
28 #include "Stream.h"
29 #include "SerialWombat.h"
88  public Stream
89 {
90 public:
106  int16_t begin(uint8_t controlPin,
107  uint8_t row0pin, uint8_t row1pin, uint8_t row2pin, uint8_t row3pin,
108  uint8_t column0pin, uint8_t column1pin, uint8_t column2pin, uint8_t column3pin,
109  uint8_t bufferMode = 0, uint8_t queueMode = 1);
110 
111 
123  int16_t writeQueueMask(uint16_t mask);
124 
127  int available();
130  int read();
132  void flush();
135  int peek();
141  size_t write(uint8_t data);
142 
149  size_t write(const uint8_t* buffer, size_t size);
150 
153  int availableForWrite();
154 
163  size_t readBytes(char* buffer, size_t length);
164 
166  void setTimeout(long timeout_mS);
167 
168 
171 
172 
174  uint8_t _pin = 255;
175 protected:
176  uint32_t timeout = 1;
177 };
178 
179 
185 {
186 public:
191  SerialWombatMatrixButton(SerialWombatMatrixKeypad& kp, uint8_t keyIndex);
192 
199  bool digitalRead();
204  uint16_t readDurationInFalseState_mS();
205 
210  uint16_t readDurationInTrueState_mS();
211 
219  bool readTransitionsState();
220 
221 private:
222  SerialWombatMatrixKeypad& _keypad;
223  uint8_t _keyIndex;
224 };
225 
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:267
SerialWombatMatrixKeypad::begin
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)
Initalize the SerialWombatMatrixKeypad.
Definition: SerialWombatMatrixKeypad.cpp:10
SerialWombatMatrixButton::SerialWombatMatrixButton
SerialWombatMatrixButton(SerialWombatMatrixKeypad &kp, uint8_t keyIndex)
Instantiate a SerialWombatMatrixButton.
Definition: SerialWombatMatrixKeypad.cpp:174
SerialWombatMatrixKeypad::flush
void flush()
Discard all bytes from the SerialWombatMatrixKeypad queue.
Definition: SerialWombatMatrixKeypad.cpp:74
SerialWombatMatrixKeypad::writeQueueMask
int16_t writeQueueMask(uint16_t mask)
Set a binary mask for which keys are added to Queue.
Definition: SerialWombatMatrixKeypad.cpp:39
SerialWombatMatrixButton::readTransitionsState
bool readTransitionsState()
Queries the number of transistions that have occured on the button.
Definition: SerialWombatMatrixKeypad.cpp:240
SerialWombatMatrixKeypad::SerialWombatMatrixKeypad
SerialWombatMatrixKeypad(SerialWombatChip &serialWombat)
Constructor for the SerialWombatMatrixKeypad class.
Definition: SerialWombatMatrixKeypad.cpp:5
SerialWombatMatrixButton
Class that runs on top of SerialWombatMatrixKeypad to treat a key as an individual button.
Definition: SerialWombatMatrixKeypad.h:184
SerialWombat.h
SerialWombatMatrixKeypad::peek
int peek()
Query the SerialWombatMatrixKeypad queue for the next avaialble byte, but don't remove it from the qu...
Definition: SerialWombatMatrixKeypad.cpp:79
SerialWombatMatrixKeypad::write
size_t write(uint8_t data)
Write a byte to the SerialWombatMatrixKeypad queue (Does Nothing)
Definition: SerialWombatMatrixKeypad.cpp:94
SerialWombatMatrixKeypad::operator=
SerialWombatMatrixKeypad operator=(SerialWombatMatrixKeypad &kp)
used to allow reference copy. Not for user use.
Definition: SerialWombatMatrixKeypad.cpp:122
SerialWombatMatrixKeypad::readBytes
size_t readBytes(char *buffer, size_t length)
Reads a specified number of bytes from the SerialWombatMatrixKeypad queue queue.
Definition: SerialWombatMatrixKeypad.cpp:127
SerialWombatMatrixKeypad::read
int read()
Reads a byte from the SerialWombatMatrixKeypad queue.
Definition: SerialWombatMatrixKeypad.cpp:55
SerialWombatMatrixKeypad::setTimeout
void setTimeout(long timeout_mS)
implemented to fulfill Stream requirement.
Definition: SerialWombatMatrixKeypad.cpp:110
SerialWombatMatrixKeypad::_pin
uint8_t _pin
Definition: SerialWombatMatrixKeypad.h:174
SerialWombatMatrixButton::readDurationInTrueState_mS
uint16_t readDurationInTrueState_mS()
return the number of mS that the button has been in true state
Definition: SerialWombatMatrixKeypad.cpp:219
SerialWombatMatrixKeypad::timeout
uint32_t timeout
Definition: SerialWombatMatrixKeypad.h:176
SerialWombatMatrixKeypad::_sw
SerialWombatChip & _sw
Definition: SerialWombatMatrixKeypad.h:173
SerialWombatMatrixButton::digitalRead
bool digitalRead()
Returns the state of the input.
Definition: SerialWombatMatrixKeypad.cpp:180
SerialWombatMatrixKeypad::available
int available()
Queries the SerialWombatMatrixKeypad for number bytes available to read.
Definition: SerialWombatMatrixKeypad.cpp:47
SerialWombatMatrixKeypad::availableForWrite
int availableForWrite()
Number of bytes avaialble to write to SerialWombatMatrixKeypad queue. Returns 0.
Definition: SerialWombatMatrixKeypad.cpp:105
SerialWombatMatrixButton::readDurationInFalseState_mS
uint16_t readDurationInFalseState_mS()
return the number of mS that the button has been in false state
Definition: SerialWombatMatrixKeypad.cpp:198
SerialWombatMatrixKeypad
A class for the Serial Wombat SW18AB chips which scans matrix keypads up to 4x4.
Definition: SerialWombatMatrixKeypad.h:87
SerialWombatAbstractButton
SerialWombat18CapTouch, SerialWombatDebouncedInput and SerialWombatMatrixButton inherit from this cla...
Definition: SerialWombatAbstractButton.h:38