ESPHome 2025.9.0-dev
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 // Reset device using the reset pin
12 if (this->reset_pin_ != nullptr) {
13 this->reset_pin_->setup();
14 this->reset_pin_->digital_write(false);
15 delay(100); // NOLINT
16 this->reset_pin_->digital_write(true);
17 delay(100); // NOLINT
18 this->reset_pin_->digital_write(false);
19 delay(100); // NOLINT
20 }
21
22 // Check if CAP1188 is actually connected
26
27 if ((this->cap1188_product_id_ != 0x50) || (this->cap1188_manufacture_id_ != 0x5D)) {
28 this->error_code_ = COMMUNICATION_FAILED;
29 this->mark_failed();
30 return;
31 }
32
33 // Set sensitivity
34 uint8_t sensitivity = 0;
35 this->read_byte(CAP1188_SENSITVITY, &sensitivity);
36 sensitivity = sensitivity & 0x0f;
37 this->write_byte(CAP1188_SENSITVITY, sensitivity | this->touch_threshold_);
38
39 // Allow multiple touches
41
42 // Have LEDs follow touches
43 this->write_byte(CAP1188_LED_LINK, 0xFF);
44
45 // Speed up a bit
47}
48
50 ESP_LOGCONFIG(TAG, "CAP1188:");
51 LOG_I2C_DEVICE(this);
52 LOG_PIN(" Reset Pin: ", this->reset_pin_);
53 ESP_LOGCONFIG(TAG,
54 " Product ID: 0x%x\n"
55 " Manufacture ID: 0x%x\n"
56 " Revision ID: 0x%x",
58
59 switch (this->error_code_) {
61 ESP_LOGE(TAG, "Product ID or Manufacture ID of the connected device does not match a known CAP1188.");
62 break;
63 case NONE:
64 default:
65 break;
66 }
67}
68
70 uint8_t touched = 0;
71
73
74 if (touched) {
75 uint8_t data = 0;
76 this->read_register(CAP1188_MAIN, &data, 1);
77 data = data & ~CAP1188_MAIN_INT;
78
79 this->write_register(CAP1188_MAIN, &data, 2);
80 }
81
82 for (auto *channel : this->channels_) {
83 channel->process(touched);
84 }
85}
86
87} // namespace cap1188
88} // 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:52
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