ESPHome  2024.12.2
matrix_keypad_binary_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace matrix_keypad {
8 
10  public:
11  MatrixKeypadBinarySensor(uint8_t key) : has_key_(true), key_(key){};
12  MatrixKeypadBinarySensor(const char *key) : has_key_(true), key_((uint8_t) key[0]){};
13  MatrixKeypadBinarySensor(int row, int col) : has_key_(false), row_(row), col_(col){};
14 
15  void key_pressed(uint8_t key) override {
16  if (!this->has_key_)
17  return;
18  if (key == this->key_)
19  this->publish_state(true);
20  }
21 
22  void key_released(uint8_t key) override {
23  if (!this->has_key_)
24  return;
25  if (key == this->key_)
26  this->publish_state(false);
27  }
28 
29  void button_pressed(int row, int col) override {
30  if (this->has_key_)
31  return;
32  if ((row == this->row_) && (col == this->col_))
33  this->publish_state(true);
34  }
35 
36  void button_released(int row, int col) override {
37  if (this->has_key_)
38  return;
39  if ((row == this->row_) && (col == this->col_))
40  this->publish_state(false);
41  }
42 
43  protected:
44  bool has_key_;
45  uint8_t key_;
46  int row_;
47  int col_;
48 };
49 
50 } // namespace matrix_keypad
51 } // namespace esphome
void publish_state(bool state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7