ESPHome  2022.6.2
mpr121.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace mpr121 {
9 
10 enum {
16  MPR121_MHDR = 0x2B,
17  MPR121_NHDR = 0x2C,
18  MPR121_NCLR = 0x2D,
19  MPR121_FDLR = 0x2E,
20  MPR121_MHDF = 0x2F,
21  MPR121_NHDF = 0x30,
22  MPR121_NCLF = 0x31,
23  MPR121_FDLF = 0x32,
24  MPR121_NHDT = 0x33,
25  MPR121_NCLT = 0x34,
26  MPR121_FDLT = 0x35,
34  MPR121_ECR = 0x5E,
41  MPR121_GPIOEN = 0x77,
46 };
47 
49  friend class MPR121Component;
50 
51  public:
52  void set_channel(uint8_t channel) { channel_ = channel; }
53  void process(uint16_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
54  void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
55  void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
56 
57  protected:
58  uint8_t channel_{0};
61 };
62 
63 class MPR121Component : public Component, public i2c::I2CDevice {
64  public:
65  void register_channel(MPR121Channel *channel) { this->channels_.push_back(channel); }
66  void set_touch_debounce(uint8_t debounce);
67  void set_release_debounce(uint8_t debounce);
68  void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
69  void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
70  uint8_t get_touch_threshold() { return this->touch_threshold_; };
71  uint8_t get_release_threshold() { return this->release_threshold_; };
72  void setup() override;
73  void dump_config() override;
74  float get_setup_priority() const override { return setup_priority::DATA; }
75  void loop() override;
76 
77  protected:
78  std::vector<MPR121Channel *> channels_{};
79  uint8_t debounce_{0};
80  uint8_t touch_threshold_{};
81  uint8_t release_threshold_{};
82  enum ErrorCode {
83  NONE = 0,
86  } error_code_{NONE};
87 };
88 
89 } // namespace mpr121
90 } // namespace esphome
void setup()
void loop()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
void set_touch_threshold(uint8_t touch_threshold)
Definition: mpr121.h:54
optional< uint8_t > release_threshold_
Definition: mpr121.h:60
void set_release_threshold(uint8_t release_threshold)
Definition: mpr121.h:69
void set_release_threshold(uint8_t release_threshold)
Definition: mpr121.h:55
void set_touch_threshold(uint8_t touch_threshold)
Definition: mpr121.h:68
optional< uint8_t > touch_threshold_
Definition: mpr121.h:59
void set_channel(uint8_t channel)
Definition: mpr121.h:52
void process(uint16_t data)
Definition: mpr121.h:53
float get_setup_priority() const override
Definition: mpr121.h:74
void publish_state(bool state)
Publish a new state to the front-end.
void register_channel(MPR121Channel *channel)
Definition: mpr121.h:65
Definition: a4988.cpp:4
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:26