ESPHome  2022.12.8
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:36
ErrorCode read(uint8_t *data, size_t len)
Definition: i2c.h:48
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:211
void status_clear_warning()
Definition: component.cpp:149
void status_set_warning()
Definition: component.cpp:141
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:112
Definition: a4988.cpp:4
enum esphome::ttp229_lsf::TTP229LSFComponent::ErrorCode NONE