Emakefun Matrix Keyboard Arduino Lib 1.0.1
Loading...
Searching...
No Matches
emakefun::MatrixKeyboard Class Reference

MatrixKeyboard is a driver class for the Matrix Keyboard module. More...

#include <matrix_keyboard.h>

Public Types

enum class  ErrorCode : uint32_t {
  kOK = 0 , kI2cDataTooLongToFitInTransmitBuffer = 1 , kI2cReceivedNackOnTransmitOfAddress = 2 , kI2cReceivedNackOnTransmitOfData = 3 ,
  kI2cOtherError = 4 , kI2cTimeout = 5 , kInvalidParameter = 6 , kUnknownError = 7
}
 Error codes. More...
 
enum  Key : uint16_t {
  kKeyNone = static_cast<Key>(0) , kKey0 = static_cast<Key>(1) << 7 , kKey1 = static_cast<Key>(1) << 0 , kKey2 = static_cast<Key>(1) << 4 ,
  kKey3 = static_cast<Key>(1) << 8 , kKey4 = static_cast<Key>(1) << 1 , kKey5 = static_cast<Key>(1) << 5 , kKey6 = static_cast<Key>(1) << 9 ,
  kKey7 = static_cast<Key>(1) << 2 , kKey8 = static_cast<Key>(1) << 6 , kKey9 = static_cast<Key>(1) << 10 , kKeyA = static_cast<Key>(1) << 12 ,
  kKeyB = static_cast<Key>(1) << 13 , kKeyC = static_cast<Key>(1) << 14 , kKeyD = static_cast<Key>(1) << 15 , kKeyAsterisk = static_cast<Key>(1) << 3 ,
  kKeyNumberSign = static_cast<Key>(1) << 11
}
 Key values. More...
 
enum class  KeyState : uint8_t { kKeyStateIdle , kKeyStatePressed , kKeyStatePressing , kKeyStateReleased }
 Key state. More...
 

Public Member Functions

 MatrixKeyboard (TwoWire &wire, const uint8_t i2c_address)
 构造函数
 
ErrorCode Initialize ()
 Initialize.
 
void Tick ()
 Scan keys, call this function in the loop function, and then query the key state each time the loop is executed.
 
bool Pressed (const Key key) const
 Check whether the button is pressed.
 
bool Pressing (const Key key) const
 Check whether the key is held down.
 
bool Released (const Key key) const
 Check whether the key has been released.
 
bool Idle (const Key key) const
 Check whether the key is idle.
 
KeyState GetKeyState (const Key key) const
 Query key state.
 
char GetCurrentPressedKey () const
 Get the currently pressed key.
 

Static Public Attributes

static constexpr uint8_t kDefaultI2cAddress = 0x65
 Default I2C address.
 

Detailed Description

MatrixKeyboard is a driver class for the Matrix Keyboard module.

Examples
get_current_pressed_key.ino, and print_key_state.ino.

Definition at line 27 of file matrix_keyboard.h.

Member Enumeration Documentation

◆ ErrorCode

enum class emakefun::MatrixKeyboard::ErrorCode : uint32_t
strong

Error codes.

Enumerator
kOK 

Success.

kI2cDataTooLongToFitInTransmitBuffer 

I2C data too long to fit in transmit buffer.

kI2cReceivedNackOnTransmitOfAddress 

NACK received on I2C transmit of address.

kI2cReceivedNackOnTransmitOfData 

NACK received on I2C transmit of data.

kI2cOtherError 

Other I2C errors.

kI2cTimeout 

I2C communication timed out.

kInvalidParameter 

Invalid parameter.

kUnknownError 

Unknown error.

Definition at line 49 of file matrix_keyboard.h.

◆ Key

Key values.

Enumerator
kKeyNone static_cast<Key>(0) 

No Key.

kKey0 static_cast<Key>(1) << 7 

Key 0.

kKey1 static_cast<Key>(1) << 0 

Key 1.

kKey2 static_cast<Key>(1) << 4 

Key 2.

kKey3 static_cast<Key>(1) << 8 

Key 3.

kKey4 static_cast<Key>(1) << 1 

Key 4.

kKey5 static_cast<Key>(1) << 5 

Key 5.

kKey6 static_cast<Key>(1) << 9 

Key 6.

kKey7 static_cast<Key>(1) << 2 

Key 7.

kKey8 static_cast<Key>(1) << 6 

Key 8.

kKey9 static_cast<Key>(1) << 10 

Key 9.

kKeyA static_cast<Key>(1) << 12 

Key A.

kKeyB static_cast<Key>(1) << 13 

Key B.

kKeyC static_cast<Key>(1) << 14 

Key C.

kKeyD static_cast<Key>(1) << 15 

Key D.

kKeyAsterisk static_cast<Key>(1) << 3 

Key asterisk.

kKeyNumberSign static_cast<Key>(1) << 11 

Key number sign.

Definition at line 134 of file matrix_keyboard.h.

◆ KeyState

enum class emakefun::MatrixKeyboard::KeyState : uint8_t
strong

Key state.

Enumerator
kKeyStateIdle 

Key is idle.

kKeyStatePressed 

Key is pressed.

kKeyStatePressing 

Key is pressing.

kKeyStateReleased 

Key is released.

Definition at line 300 of file matrix_keyboard.h.

Constructor & Destructor Documentation

◆ MatrixKeyboard()

emakefun::MatrixKeyboard::MatrixKeyboard ( TwoWire & wire,
const uint8_t i2c_address )
explicit

构造函数

Parameters
[in]wireTwoWire object reference.
[in]i2c_addressI2C address.

Definition at line 5 of file matrix_keyboard.cpp.

Member Function Documentation

◆ GetCurrentPressedKey()

char emakefun::MatrixKeyboard::GetCurrentPressedKey ( ) const

Get the currently pressed key.

Returns
char key character: '0'-'9', 'A'-'D', '*', '#', returns '\0' to indicate no key pressed.
Note
If multiple buttons are pressed simultaneously, return to the first detected button in order.

Definition at line 53 of file matrix_keyboard.cpp.

◆ GetKeyState()

MatrixKeyboard::KeyState emakefun::MatrixKeyboard::GetKeyState ( const Key key) const

Query key state.

Parameters
[in]Key,referto the enumeration Key.
Returns
Key state, refer to enumeration KeyState.

Definition at line 41 of file matrix_keyboard.cpp.

◆ Idle()

bool emakefun::MatrixKeyboard::Idle ( const Key key) const

Check whether the key is idle.

Parameters
[in]Key,referto the enumeration Key.
Returns
Return true to indicate that the key is idle.

Definition at line 37 of file matrix_keyboard.cpp.

◆ Initialize()

MatrixKeyboard::ErrorCode emakefun::MatrixKeyboard::Initialize ( )

Initialize.

Returns
Return value refer to ErrorCode.

Definition at line 8 of file matrix_keyboard.cpp.

◆ Pressed()

bool emakefun::MatrixKeyboard::Pressed ( const Key key) const

Check whether the button is pressed.

Parameters
[in]Key,referto the enumeration Key.
Returns
Returning true indicates that the button has been pressed.

Definition at line 25 of file matrix_keyboard.cpp.

◆ Pressing()

bool emakefun::MatrixKeyboard::Pressing ( const Key key) const

Check whether the key is held down.

Parameters
[in]Key,referto the enumeration Key.
Returns
Return true to indicate that the key is held down.

Definition at line 29 of file matrix_keyboard.cpp.

◆ Released()

bool emakefun::MatrixKeyboard::Released ( const Key key) const

Check whether the key has been released.

Parameters
[in]Key,referto the enumeration Key.
Returns
Returning true indicates that the key has been released.

Definition at line 33 of file matrix_keyboard.cpp.

◆ Tick()

void emakefun::MatrixKeyboard::Tick ( )

Scan keys, call this function in the loop function, and then query the key state each time the loop is executed.

Definition at line 20 of file matrix_keyboard.cpp.

Member Data Documentation

◆ kDefaultI2cAddress

uint8_t emakefun::MatrixKeyboard::kDefaultI2cAddress = 0x65
staticconstexpr

Default I2C address.

Definition at line 37 of file matrix_keyboard.h.


The documentation for this class was generated from the following files: