ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
ttp229_bsf.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7#include <vector>
8
9namespace esphome {
10namespace ttp229_bsf {
11
13 public:
14 void set_channel(uint8_t channel) { channel_ = channel; }
15 void process(uint16_t data) { this->publish_state(data & (1 << this->channel_)); }
16
17 protected:
18 uint8_t channel_;
19};
20
22 public:
23 void set_sdo_pin(GPIOPin *sdo_pin) { sdo_pin_ = sdo_pin; }
24 void set_scl_pin(GPIOPin *scl_pin) { scl_pin_ = scl_pin; }
25 void register_channel(TTP229BSFChannel *channel) { this->channels_.push_back(channel); }
26 void setup() override;
27 void dump_config() override;
28 void loop() override {
29 // check datavalid if sdo is high
30 if (!this->sdo_pin_->digital_read()) {
31 return;
32 }
33 uint16_t touched = 0;
34 for (uint8_t i = 0; i < 16; i++) {
35 this->scl_pin_->digital_write(false);
36 delayMicroseconds(2); // 500KHz
37 bool bitval = !this->sdo_pin_->digital_read();
38 this->scl_pin_->digital_write(true);
39 delayMicroseconds(2); // 500KHz
40
41 touched |= uint16_t(bitval) << i;
42 }
43 for (auto *channel : this->channels_) {
44 channel->process(touched);
45 }
46 }
47
48 protected:
51 std::vector<TTP229BSFChannel *> channels_{};
52};
53
54} // namespace ttp229_bsf
55} // namespace esphome
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
void set_channel(uint8_t channel)
Definition ttp229_bsf.h:14
void set_sdo_pin(GPIOPin *sdo_pin)
Definition ttp229_bsf.h:23
void set_scl_pin(GPIOPin *scl_pin)
Definition ttp229_bsf.h:24
void register_channel(TTP229BSFChannel *channel)
Definition ttp229_bsf.h:25
std::vector< TTP229BSFChannel * > channels_
Definition ttp229_bsf.h:51
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:31