ESPHome 2025.5.0
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
4namespace esphome {
5namespace ttp229_lsf {
6
7static const char *const TAG = "ttp229_lsf";
8
10 ESP_LOGCONFIG(TAG, "Setting up ttp229...");
11 uint8_t data[2];
12 if (this->read(data, 2) != i2c::ERROR_OK) {
13 this->error_code_ = COMMUNICATION_FAILED;
14 this->mark_failed();
15 return;
16 }
17}
19 ESP_LOGCONFIG(TAG, "ttp229:");
20 LOG_I2C_DEVICE(this);
21 switch (this->error_code_) {
23 ESP_LOGE(TAG, "Communication with TTP229 failed!");
24 break;
25 case NONE:
26 default:
27 break;
28 }
29}
31 uint16_t touched = 0;
32 if (this->read(reinterpret_cast<uint8_t *>(&touched), 2) != i2c::ERROR_OK) {
33 this->status_set_warning();
34 return;
35 }
36 touched = i2c::i2ctohs(touched);
38 touched = reverse_bits(touched);
39 for (auto *channel : this->channels_) {
40 channel->process(touched);
41 }
42}
43
44} // namespace ttp229_lsf
45} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
Definition i2c.h:164
enum esphome::ttp229_lsf::TTP229LSFComponent::ErrorCode NONE
std::vector< TTP229Channel * > channels_
Definition ttp229_lsf.h:30
uint16_t i2ctohs(uint16_t i2cshort)
Definition i2c.h:128
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:13
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint8_t reverse_bits(uint8_t x)
Reverse the order of 8 bits.
Definition helpers.h:231