ESPHome 2025.6.3
Loading...
Searching...
No Matches
cap1188.cpp
Go to the documentation of this file.
1#include "cap1188.h"
2#include "esphome/core/log.h"
3#include "esphome/core/hal.h"
4
5namespace esphome {
6namespace cap1188 {
7
8static const char *const TAG = "cap1188";
9
11 ESP_LOGCONFIG(TAG, "Running setup");
12
13 // Reset device using the reset pin
14 if (this->reset_pin_ != nullptr) {
15 this->reset_pin_->setup();
16 this->reset_pin_->digital_write(false);
17 delay(100); // NOLINT
18 this->reset_pin_->digital_write(true);
19 delay(100); // NOLINT
20 this->reset_pin_->digital_write(false);
21 delay(100); // NOLINT
22 }
23
24 // Check if CAP1188 is actually connected
28
29 if ((this->cap1188_product_id_ != 0x50) || (this->cap1188_manufacture_id_ != 0x5D)) {
30 this->error_code_ = COMMUNICATION_FAILED;
31 this->mark_failed();
32 return;
33 }
34
35 // Set sensitivity
36 uint8_t sensitivity = 0;
37 this->read_byte(CAP1188_SENSITVITY, &sensitivity);
38 sensitivity = sensitivity & 0x0f;
39 this->write_byte(CAP1188_SENSITVITY, sensitivity | this->touch_threshold_);
40
41 // Allow multiple touches
43
44 // Have LEDs follow touches
45 this->write_byte(CAP1188_LED_LINK, 0xFF);
46
47 // Speed up a bit
49}
50
52 ESP_LOGCONFIG(TAG, "CAP1188:");
53 LOG_I2C_DEVICE(this);
54 LOG_PIN(" Reset Pin: ", this->reset_pin_);
55 ESP_LOGCONFIG(TAG,
56 " Product ID: 0x%x\n"
57 " Manufacture ID: 0x%x\n"
58 " Revision ID: 0x%x",
60
61 switch (this->error_code_) {
63 ESP_LOGE(TAG, "Product ID or Manufacture ID of the connected device does not match a known CAP1188.");
64 break;
65 case NONE:
66 default:
67 break;
68 }
69}
70
72 uint8_t touched = 0;
73
75
76 if (touched) {
77 uint8_t data = 0;
78 this->read_register(CAP1188_MAIN, &data, 1);
79 data = data & ~CAP1188_MAIN_INT;
80
81 this->write_register(CAP1188_MAIN, &data, 2);
82 }
83
84 for (auto *channel : this->channels_) {
85 channel->process(touched);
86 }
87}
88
89} // namespace cap1188
90} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
virtual void setup()=0
virtual void digital_write(bool value)=0
enum esphome::cap1188::CAP1188Component::ErrorCode NONE
std::vector< CAP1188Channel * > channels_
Definition cap1188.h:53
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:25
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Definition i2c.h:266
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
Definition i2c.cpp:10
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
Definition i2c.h:239
@ CAP1188_STAND_BY_CONFIGURATION
Definition cap1188.h:21
@ CAP1188_MANUFACTURE_ID
Definition cap1188.h:20
@ CAP1188_SENSOR_INPUT_STATUS
Definition cap1188.h:16
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:29