ESPHome  2024.4.0
ttp229_lsf.cpp
Go to the documentation of this file.
1 #include "ttp229_lsf.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace ttp229_lsf {
6 
7 static 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);
37  this->status_clear_warning();
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
uint16_t i2ctohs(uint16_t i2cshort)
Definition: i2c.h:128
void status_set_warning(const char *message="unspecified")
Definition: component.cpp:151
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
Definition: i2c.h:160
std::vector< TTP229Channel * > channels_
Definition: ttp229_lsf.h:30
uint8_t reverse_bits(uint8_t x)
Reverse the order of 8 bits.
Definition: helpers.h:222
No error found during execution of method.
Definition: i2c_bus.h:13
void status_clear_warning()
Definition: component.cpp:166
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:118
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
enum esphome::ttp229_lsf::TTP229LSFComponent::ErrorCode NONE