10 for (uint8_t i = 0; i < 5; i++) {
11 wire_.beginTransmission(i2c_address_);
12 result =
static_cast<ErrorCode>(wire_.endTransmission());
26 return (last_key_ & key) == 0 && (key_() & key) != 0;
30 return (last_key_ & key) != 0 && (key_() & key) != 0;
34 return (last_key_ & key) != 0 && (key_() & key) == 0;
38 return (last_key_ & key) == 0 && (key_() & key) == 0;
54 static constexpr struct {
57 } key_value_map[] = {{
kKey1,
'1'},
74 for (
const auto& key_map : key_value_map) {
75 if ((last_key_ & key_map.key) == 0 && (key_() & key_map.key) != 0) {
86 if (
sizeof(key) != wire_.requestFrom(i2c_address_,
sizeof(key))) {
90 if (
sizeof(key) != wire_.readBytes(
reinterpret_cast<uint8_t*
>(&key),
sizeof(key))) {
char GetCurrentPressedKey() const
获取当前按下的按键。
bool Idle(const Key key) const
查询按键是否空闲。
MatrixKeyboard(TwoWire &wire, const uint8_t i2c_address)
构造函数
bool Pressing(const Key key) const
查询按键是否被按住。
bool Pressed(const Key key) const
查询按键是否被按下。
ErrorCode Initialize()
初始化。
@ kKeyStateReleased
按键被弹起。
@ kKeyStatePressing
按键被按住。
KeyState GetKeyState(const Key key) const
查询按键状态。
bool Released(const Key key) const
查询按键是否被释放。
void Tick()
扫描按键,在函数loop中调用,每次循环先调用该函数再查询按键状态。