ESPHome 2026.5.1
Loading...
Searching...
No Matches
ttp229_lsf.cpp
Go to the documentation of this file.
1#include "ttp229_lsf.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "ttp229_lsf";
7
9 uint8_t data[2];
10 if (this->read(data, 2) != i2c::ERROR_OK) {
11 this->error_code_ = COMMUNICATION_FAILED;
12 this->mark_failed();
13 return;
14 }
15}
17 ESP_LOGCONFIG(TAG, "ttp229:");
18 LOG_I2C_DEVICE(this);
19 switch (this->error_code_) {
21 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
22 break;
23 case NONE:
24 default:
25 break;
26 }
27}
29 uint16_t touched = 0;
30 if (this->read(reinterpret_cast<uint8_t *>(&touched), 2) != i2c::ERROR_OK) {
31 this->status_set_warning();
32 return;
33 }
34 touched = i2c::i2ctohs(touched);
36 touched = reverse_bits(touched);
37 for (auto *channel : this->channels_) {
38 channel->process(touched);
39 }
40}
41
42} // namespace esphome::ttp229_lsf
void mark_failed()
Mark this component as failed.
void status_clear_warning()
Definition component.h:306
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:163
enum esphome::ttp229_lsf::TTP229LSFComponent::ErrorCode NONE
std::vector< TTP229Channel * > channels_
Definition ttp229_lsf.h:28
uint16_t i2ctohs(uint16_t i2cshort)
Definition i2c.h:127
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14
uint8_t reverse_bits(uint8_t x)
Reverse the order of 8 bits.
Definition helpers.h:898