ESPHome  2024.12.2
matrix_keypad.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/hal.h"
7 #include "esphome/core/helpers.h"
8 #include <cstdlib>
9 #include <utility>
10 
11 namespace esphome {
12 namespace matrix_keypad {
13 
15  public:
16  virtual void button_pressed(int row, int col){};
17  virtual void button_released(int row, int col){};
18  virtual void key_pressed(uint8_t key){};
19  virtual void key_released(uint8_t key){};
20 };
21 
22 class MatrixKeyTrigger : public Trigger<uint8_t> {};
23 
25  public:
26  void setup() override;
27  void loop() override;
28  void dump_config() override;
29  void set_columns(std::vector<GPIOPin *> pins) { columns_ = std::move(pins); };
30  void set_rows(std::vector<GPIOPin *> pins) { rows_ = std::move(pins); };
31  void set_keys(std::string keys) { keys_ = std::move(keys); };
32  void set_debounce_time(int debounce_time) { debounce_time_ = debounce_time; };
33  void set_has_diodes(int has_diodes) { has_diodes_ = has_diodes; };
34  void set_has_pulldowns(int has_pulldowns) { has_pulldowns_ = has_pulldowns; };
35 
36  void register_listener(MatrixKeypadListener *listener);
37  void register_key_trigger(MatrixKeyTrigger *trig);
38 
39  protected:
40  std::vector<GPIOPin *> rows_;
41  std::vector<GPIOPin *> columns_;
42  std::string keys_;
43  int debounce_time_ = 0;
44  bool has_diodes_{false};
45  bool has_pulldowns_{false};
46  int pressed_key_ = -1;
47 
48  std::vector<MatrixKeypadListener *> listeners_{};
49  std::vector<MatrixKeyTrigger *> key_triggers_;
50 };
51 
52 } // namespace matrix_keypad
53 } // namespace esphome
void setup()
void set_rows(std::vector< GPIOPin *> pins)
Definition: matrix_keypad.h:30
void loop()
interface for components that provide keypresses
Definition: key_provider.h:10
void set_has_pulldowns(int has_pulldowns)
Definition: matrix_keypad.h:34
void set_columns(std::vector< GPIOPin *> pins)
Definition: matrix_keypad.h:29
std::vector< MatrixKeyTrigger * > key_triggers_
Definition: matrix_keypad.h:49
void set_debounce_time(int debounce_time)
Definition: matrix_keypad.h:32
virtual void button_pressed(int row, int col)
Definition: matrix_keypad.h:16
std::vector< GPIOPin * > columns_
Definition: matrix_keypad.h:41
virtual void button_released(int row, int col)
Definition: matrix_keypad.h:17
void set_has_diodes(int has_diodes)
Definition: matrix_keypad.h:33
void set_keys(std::string keys)
Definition: matrix_keypad.h:31
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::vector< GPIOPin * > rows_
Definition: matrix_keypad.h:40