Emakefun Matrix Keyboard Arduino 库 1.0.1
载入中...
搜索中...
未找到
emakefun::MatrixKeyboard类 参考

MatrixKeyboard是用于矩阵键盘模块的驱动类。 更多...

#include <matrix_keyboard.h>

Public 类型

enum class  ErrorCode : uint32_t {
  kOK = 0 , kI2cDataTooLongToFitInTransmitBuffer = 1 , kI2cReceivedNackOnTransmitOfAddress = 2 , kI2cReceivedNackOnTransmitOfData = 3 ,
  kI2cOtherError = 4 , kI2cTimeout = 5 , kInvalidParameter = 6 , kUnknownError = 7
}
 错误码。 更多...
 
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
}
 键值。 更多...
 
enum class  KeyState : uint8_t { kKeyStateIdle , kKeyStatePressed , kKeyStatePressing , kKeyStateReleased }
 按键状态。 更多...
 

Public 成员函数

 MatrixKeyboard (TwoWire &wire, const uint8_t i2c_address)
 构造函数
 
ErrorCode Initialize ()
 初始化。
 
void Tick ()
 扫描按键,在函数loop中调用,每次循环先调用该函数再查询按键状态。
 
bool Pressed (const Key key) const
 查询按键是否被按下。
 
bool Pressing (const Key key) const
 查询按键是否被按住。
 
bool Released (const Key key) const
 查询按键是否被释放。
 
bool Idle (const Key key) const
 查询按键是否空闲。
 
KeyState GetKeyState (const Key key) const
 查询按键状态。
 
char GetCurrentPressedKey () const
 获取当前按下的按键。
 

静态 Public 属性

static constexpr uint8_t kDefaultI2cAddress = 0x65
 默认I2C地址。
 

详细描述

MatrixKeyboard是用于矩阵键盘模块的驱动类。

示例
get_current_pressed_key.ino , 以及 print_key_state.ino.

在文件 matrix_keyboard.h27 行定义.

成员枚举类型说明

◆ ErrorCode

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

错误码。

枚举值
kOK 

成功。

kI2cDataTooLongToFitInTransmitBuffer 

I2C数据太长,无法装入传输缓冲区。

kI2cReceivedNackOnTransmitOfAddress 

在I2C发送地址时收到NACK。

kI2cReceivedNackOnTransmitOfData 

在I2C发送数据时收到NACK。

kI2cOtherError 

其他I2C错误。

kI2cTimeout 

I2C通讯超时。

kInvalidParameter 

参数错误。

kUnknownError 

未知错误。

在文件 matrix_keyboard.h49 行定义.

◆ Key

键值。

枚举值
kKeyNone static_cast<Key>(0) 

无按键。

kKey0 static_cast<Key>(1) << 7 

按键0。

kKey1 static_cast<Key>(1) << 0 

按键1。

kKey2 static_cast<Key>(1) << 4 

按键2。

kKey3 static_cast<Key>(1) << 8 

按键3。

kKey4 static_cast<Key>(1) << 1 

按键4。

kKey5 static_cast<Key>(1) << 5 

按键5。

kKey6 static_cast<Key>(1) << 9 

按键6。

kKey7 static_cast<Key>(1) << 2 

按键7。

kKey8 static_cast<Key>(1) << 6 

按键8。

kKey9 static_cast<Key>(1) << 10 

按键9。

kKeyA static_cast<Key>(1) << 12 

按键A。

kKeyB static_cast<Key>(1) << 13 

按键B。

kKeyC static_cast<Key>(1) << 14 

按键C。

kKeyD static_cast<Key>(1) << 15 

按键D。

kKeyAsterisk static_cast<Key>(1) << 3 

按键星号。

kKeyNumberSign static_cast<Key>(1) << 11 

按键井号。

在文件 matrix_keyboard.h134 行定义.

◆ KeyState

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

按键状态。

枚举值
kKeyStateIdle 

按键空闲。

kKeyStatePressed 

按键被按下。

kKeyStatePressing 

按键被按住。

kKeyStateReleased 

按键被弹起。

在文件 matrix_keyboard.h300 行定义.

构造及析构函数说明

◆ MatrixKeyboard()

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

构造函数

参数
[in]wireTwoWire 对象引用。
[in]i2c_addressI2C地址。

在文件 matrix_keyboard.cpp5 行定义.

成员函数说明

◆ GetCurrentPressedKey()

char emakefun::MatrixKeyboard::GetCurrentPressedKey ( ) const

获取当前按下的按键。

返回
char 按键字符:'0'-'9'、'A'-'D'、'*'、'#',返回'\0'表示没有按键按下。
注解
如果多个按键同时按下,则按顺序返回第一个检测到的按键。

在文件 matrix_keyboard.cpp53 行定义.

◆ GetKeyState()

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

查询按键状态。

参数
[in]Key,referto the enumeration Key.
返回
按键状态,参考枚举 KeyState。

在文件 matrix_keyboard.cpp41 行定义.

◆ Idle()

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

查询按键是否空闲。

参数
[in]Key,referto the enumeration Key.
返回
返回true代表按键空闲。

在文件 matrix_keyboard.cpp37 行定义.

◆ Initialize()

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

初始化。

返回
返回值请参考 ErrorCode。

在文件 matrix_keyboard.cpp8 行定义.

◆ Pressed()

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

查询按键是否被按下。

参数
[in]key按键,参考枚举 Key。
返回
返回true代表按键被按下。

在文件 matrix_keyboard.cpp25 行定义.

◆ Pressing()

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

查询按键是否被按住。

参数
[in]Key,referto the enumeration Key.
返回
返回true代表按键被按住。

在文件 matrix_keyboard.cpp29 行定义.

◆ Released()

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

查询按键是否被释放。

参数
[in]Key,referto the enumeration Key.
返回
返回true代表按键被释放。

在文件 matrix_keyboard.cpp33 行定义.

◆ Tick()

void emakefun::MatrixKeyboard::Tick ( )

扫描按键,在函数loop中调用,每次循环先调用该函数再查询按键状态。

在文件 matrix_keyboard.cpp20 行定义.

类成员变量说明

◆ kDefaultI2cAddress

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

默认I2C地址。

在文件 matrix_keyboard.h37 行定义.


该类的文档由以下文件生成: