ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
mpr121
binary_sensor
mpr121_binary_sensor.cpp
Go to the documentation of this file.
1
#include "
mpr121_binary_sensor.h
"
2
3
namespace
esphome::mpr121
{
4
5
void
MPR121BinarySensor::setup
() {
6
uint8_t touch_threshold = this->
touch_threshold_
.value_or(this->
parent_
->get_touch_threshold());
7
this->
parent_
->write_byte(
MPR121_TOUCHTH_0
+ 2 * this->
channel_
, touch_threshold);
8
9
uint8_t release_threshold = this->
release_threshold_
.value_or(this->
parent_
->get_release_threshold());
10
this->
parent_
->write_byte(
MPR121_RELEASETH_0
+ 2 * this->
channel_
, release_threshold);
11
}
12
13
void
MPR121BinarySensor::process
(uint16_t data) {
14
bool
new_state = data & (1 << this->
channel_
);
15
this->
publish_state
(new_state);
16
}
17
18
}
// namespace esphome::mpr121
esphome::Parented< MPR121Component >::parent_
MPR121Component * parent_
Definition
helpers.h:1872
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool new_state)
Publish a new state to the front-end.
Definition
binary_sensor.cpp:20
esphome::mpr121::MPR121BinarySensor::channel_
uint8_t channel_
Definition
mpr121_binary_sensor.h:19
esphome::mpr121::MPR121BinarySensor::release_threshold_
optional< uint8_t > release_threshold_
Definition
mpr121_binary_sensor.h:21
esphome::mpr121::MPR121BinarySensor::touch_threshold_
optional< uint8_t > touch_threshold_
Definition
mpr121_binary_sensor.h:20
esphome::mpr121::MPR121BinarySensor::process
void process(uint16_t data) override
Definition
mpr121_binary_sensor.cpp:13
esphome::mpr121::MPR121BinarySensor::setup
void setup() override
Definition
mpr121_binary_sensor.cpp:5
mpr121_binary_sensor.h
esphome::mpr121
Definition
mpr121_binary_sensor.cpp:3
esphome::mpr121::MPR121_TOUCHTH_0
@ MPR121_TOUCHTH_0
Definition
mpr121.h:30
esphome::mpr121::MPR121_RELEASETH_0
@ MPR121_RELEASETH_0
Definition
mpr121.h:31
Generated by
1.12.0