ESPHome  2024.4.1
cap1188.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
8 
9 #include <vector>
10 
11 namespace esphome {
12 namespace cap1188 {
13 
14 enum {
23  CAP1188_MAIN = 0x00,
28 };
29 
31  public:
32  void set_channel(uint8_t channel) { channel_ = channel; }
33  void process(uint8_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
34 
35  protected:
36  uint8_t channel_{0};
37 };
38 
39 class CAP1188Component : public Component, public i2c::I2CDevice {
40  public:
41  void register_channel(CAP1188Channel *channel) { this->channels_.push_back(channel); }
42  void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
43  void set_allow_multiple_touches(bool allow_multiple_touches) {
44  this->allow_multiple_touches_ = allow_multiple_touches ? 0x41 : 0x80;
45  };
46  void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
47  void setup() override;
48  void dump_config() override;
49  float get_setup_priority() const override { return setup_priority::DATA; }
50  void loop() override;
51 
52  protected:
53  std::vector<CAP1188Channel *> channels_{};
54  uint8_t touch_threshold_{0x20};
55  uint8_t allow_multiple_touches_{0x80};
56 
57  GPIOPin *reset_pin_{nullptr};
58 
59  uint8_t cap1188_product_id_{0};
60  uint8_t cap1188_manufacture_id_{0};
61  uint8_t cap1188_revision_{0};
62 
63  enum ErrorCode {
64  NONE = 0,
66  } error_code_{NONE};
67 };
68 
69 } // namespace cap1188
70 } // namespace esphome
void setup()
void set_allow_multiple_touches(bool allow_multiple_touches)
Definition: cap1188.h:43
void loop()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
float get_setup_priority() const override
Definition: cap1188.h:49
void set_touch_threshold(uint8_t touch_threshold)
Definition: cap1188.h:42
void process(uint8_t data)
Definition: cap1188.h:33
void set_reset_pin(GPIOPin *reset_pin)
Definition: cap1188.h:46
void publish_state(bool state)
Publish a new state to the front-end.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void set_channel(uint8_t channel)
Definition: cap1188.h:32
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
void register_channel(CAP1188Channel *channel)
Definition: cap1188.h:41