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