ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
waveshare_io_ch32v003
sensor
waveshare_io_ch32v003_sensor.cpp
Go to the documentation of this file.
1
#include "
waveshare_io_ch32v003_sensor.h
"
2
3
#include "
esphome/core/log.h
"
4
5
namespace
esphome::waveshare_io_ch32v003
{
6
7
ESPHOME_LOG_TAG
(TAG,
"waveshare_io_ch32v003.sensor"
);
8
9
void
WaveshareIOCH32V003Sensor::dump_config
() {
10
ESP_LOGCONFIG(TAG,
11
"WaveshareIOCH32V003Sensor:\n"
12
" Reference Voltage: %.2fV"
,
13
this->
reference_voltage_
);
14
}
15
16
float
WaveshareIOCH32V003Sensor::sample
() {
17
uint16_t adc_value = this->
parent_
->get_adc_value();
18
// Convert the ADC value to voltage. 10-bit ADC
19
float
voltage = adc_value * this->
reference_voltage_
/ 1023.0f;
20
return
voltage;
21
}
22
23
void
WaveshareIOCH32V003Sensor::update
() { this->
publish_state
(this->
sample
()); }
24
25
}
// namespace esphome::waveshare_io_ch32v003
esphome::Parented< WaveshareIOCH32V003Component >::parent_
WaveshareIOCH32V003Component * parent_
Definition
helpers.h:2171
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:65
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::sample
float sample() override
Definition
waveshare_io_ch32v003_sensor.cpp:16
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::dump_config
void dump_config() override
Definition
waveshare_io_ch32v003_sensor.cpp:9
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::reference_voltage_
float reference_voltage_
Definition
waveshare_io_ch32v003_sensor.h:25
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::update
void update() override
Definition
waveshare_io_ch32v003_sensor.cpp:23
log.h
esphome::waveshare_io_ch32v003
Definition
waveshare_io_ch32v003_sensor.cpp:5
esphome::waveshare_io_ch32v003::ESPHOME_LOG_TAG
ESPHOME_LOG_TAG(TAG, "waveshare_io_ch32v003.sensor")
waveshare_io_ch32v003_sensor.h
Generated by
1.12.0