ESPHome
2026.8.0-dev
Loading...
Searching...
No Matches
esphome
components
waveshare_io_ch32v003
output
waveshare_io_ch32v003_output.cpp
Go to the documentation of this file.
1
#include "
waveshare_io_ch32v003_output.h
"
2
#include "
esphome/core/log.h
"
3
#include <algorithm>
4
5
namespace
esphome::waveshare_io_ch32v003
{
6
7
static
const
char
*
const
TAG =
"waveshare_io_ch32v003.output"
;
8
9
void
WaveshareIOCH32V003Output::write_state
(
float
state
) {
10
uint8_t pwm_value =
static_cast<
uint8_t
>
(
state
* 255.0f);
11
uint8_t final_pwm_value = std::clamp(pwm_value, this->
pwm_min_value_
, this->
pwm_max_value_
);
12
if
(final_pwm_value != pwm_value) {
13
ESP_LOGVV(TAG,
"Clamping PWM value %u to safe range [%u, %u]"
, pwm_value, this->
pwm_min_value_
,
14
this->
pwm_max_value_
);
15
}
16
this->
parent_
->set_pwm_value(final_pwm_value);
17
}
18
19
}
// namespace esphome::waveshare_io_ch32v003
esphome::Parented< WaveshareIOCH32V003Component >::parent_
WaveshareIOCH32V003Component * parent_
Definition
helpers.h:1886
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Output::pwm_min_value_
uint8_t pwm_min_value_
Definition
waveshare_io_ch32v003_output.h:18
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Output::pwm_max_value_
uint8_t pwm_max_value_
Definition
waveshare_io_ch32v003_output.h:19
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Output::write_state
void write_state(float state) override
Definition
waveshare_io_ch32v003_output.cpp:9
state
bool state
Definition
fan.h:2
log.h
esphome::waveshare_io_ch32v003
Definition
waveshare_io_ch32v003_output.cpp:5
waveshare_io_ch32v003_output.h
Generated by
1.12.0