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
Get the currently pressed key.
@ kUnknownError
Unknown error.
bool Idle(const Key key) const
Check whether the key is idle.
MatrixKeyboard(TwoWire &wire, const uint8_t i2c_address)
构造函数
@ kKeyAsterisk
Key asterisk.
@ kKeyNumberSign
Key number sign.
bool Pressing(const Key key) const
Check whether the key is held down.
bool Pressed(const Key key) const
Check whether the button is pressed.
ErrorCode Initialize()
Initialize.
@ kKeyStatePressed
Key is pressed.
@ kKeyStateReleased
Key is released.
@ kKeyStateIdle
Key is idle.
@ kKeyStatePressing
Key is pressing.
KeyState GetKeyState(const Key key) const
Query key state.
bool Released(const Key key) const
Check whether the key has been released.
void Tick()
Scan keys, call this function in the loop function, and then query the key state each time the loop i...