ESPHome  2024.10.2
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::output::FloatOutput Class Referenceabstract

Base class for all output components that can output a variable level, like PWM. More...

#include <float_output.h>

Inheritance diagram for esphome::output::FloatOutput:
esphome::output::BinaryOutput esphome::ac_dimmer::AcDimmer esphome::bp1658cj::BP1658CJ::Channel esphome::bp5758d::BP5758D::Channel esphome::dac7678::DAC7678Channel esphome::emc2101::EMC2101Output esphome::esp32_dac::ESP32DAC esphome::esp8266_pwm::ESP8266PWM esphome::gp8403::GP8403Output esphome::ledc::LEDCOutput esphome::libretiny_pwm::LibreTinyPWM esphome::max6956::MAX6956LedChannel esphome::mcp4725::MCP4725 esphome::mcp4728::MCP4728Channel esphome::mcp47a1::MCP47A1 esphome::modbus_controller::ModbusFloatOutput esphome::my9231::MY9231OutputComponent::Channel esphome::pca9685::PCA9685Channel esphome::pid::PIDSimulator esphome::pipsolar::PipsolarOutput esphome::rp2040_pwm::RP2040PWM esphome::sigma_delta_output::SigmaDeltaOutput esphome::slow_pwm::SlowPWMOutput esphome::sm10bit_base::Sm10BitBase::Channel esphome::sm16716::SM16716::Channel esphome::sm2135::SM2135::Channel esphome::sx1509::SX1509FloatOutputChannel esphome::template_::TemplateFloatOutput esphome::tlc59208f::TLC59208FChannel esphome::tlc5947::TLC5947Channel esphome::tlc5971::TLC5971Channel esphome::x9c::X9cOutput

Public Member Functions

void set_max_power (float max_power)
 Set the maximum power output of this component. More...
 
void set_min_power (float min_power)
 Set the minimum power output of this component. More...
 
void set_zero_means_zero (bool zero_means_zero)
 Sets this output to ignore min_power for a 0 state. More...
 
void set_level (float state)
 Set the level of this float output, this is called from the front-end. More...
 
virtual void update_frequency (float frequency)
 Set the frequency of the output for PWM outputs. More...
 
float get_max_power () const
 Get the maximum power output. More...
 
float get_min_power () const
 Get the minimum power output. More...
 
- Public Member Functions inherited from esphome::output::BinaryOutput
void set_inverted (bool inverted)
 Set the inversion state of this binary output. More...
 
void set_power_supply (power_supply::PowerSupply *power_supply)
 Use this to connect up a power supply to this output. More...
 
virtual void set_state (bool state)
 Enable or disable this binary output. More...
 
virtual void turn_on ()
 Enable this binary output. More...
 
virtual void turn_off ()
 Disable this binary output. More...
 
bool is_inverted () const
 Return whether this binary output is inverted. More...
 

Protected Member Functions

void write_state (bool state) override
 Implement BinarySensor's write_enabled; this should never be called. More...
 
virtual void write_state (float state)=0
 

Protected Attributes

float max_power_ {1.0f}
 
float min_power_ {0.0f}
 
bool zero_means_zero_
 
- Protected Attributes inherited from esphome::output::BinaryOutput
bool inverted_ {false}
 
power_supply::PowerSupplyRequester power_ {}
 

Detailed Description

Base class for all output components that can output a variable level, like PWM.

Floating Point Outputs always use output values in the range from 0.0 to 1.0 (inclusive), where 0.0 means off and 1.0 means fully on. While using floating point numbers might make computation slower, it makes using maths much easier and (in theory) supports all possible bit depths.

If you want to create a FloatOutput yourself, you essentially just have to override write_state(float). That method will be called for you with inversion and max-min power and offset to min power already applied.

This interface is compatible with BinaryOutput (and will automatically convert the binary states to floating point states for you). Additionally, this class provides a way for users to set a minimum and/or maximum power output

Definition at line 31 of file float_output.h.

Member Function Documentation

◆ get_max_power()

float esphome::output::FloatOutput::get_max_power ( ) const

Get the maximum power output.

Definition at line 14 of file float_output.cpp.

◆ get_min_power()

float esphome::output::FloatOutput::get_min_power ( ) const

Get the minimum power output.

Definition at line 22 of file float_output.cpp.

◆ set_level()

void esphome::output::FloatOutput::set_level ( float  state)

Set the level of this float output, this is called from the front-end.

Parameters
stateThe new state.

Definition at line 24 of file float_output.cpp.

◆ set_max_power()

void esphome::output::FloatOutput::set_max_power ( float  max_power)

Set the maximum power output of this component.

All values are multiplied by max_power - min_power and offset to min_power to get the adjusted value.

Parameters
max_powerAutomatically clamped from 0 or min_power to 1.

Definition at line 10 of file float_output.cpp.

◆ set_min_power()

void esphome::output::FloatOutput::set_min_power ( float  min_power)

Set the minimum power output of this component.

All values are multiplied by max_power - min_power and offset by min_power to get the adjusted value.

Parameters
min_powerAutomatically clamped from 0 to max_power or 1.

Definition at line 16 of file float_output.cpp.

◆ set_zero_means_zero()

void esphome::output::FloatOutput::set_zero_means_zero ( bool  zero_means_zero)

Sets this output to ignore min_power for a 0 state.

Parameters
zeroTrue if a 0 state should mean 0 and not min_power.

Definition at line 20 of file float_output.cpp.

◆ update_frequency()

virtual void esphome::output::FloatOutput::update_frequency ( float  frequency)
inlinevirtual

Set the frequency of the output for PWM outputs.

Implemented only by components which can set the output PWM frequency.

Parameters
frequenceThe new frequency.

Reimplemented in esphome::ledc::LEDCOutput, esphome::libretiny_pwm::LibreTinyPWM, esphome::esp8266_pwm::ESP8266PWM, and esphome::rp2040_pwm::RP2040PWM.

Definition at line 67 of file float_output.h.

◆ write_state() [1/2]

void esphome::output::FloatOutput::write_state ( bool  state)
overrideprotectedvirtual

Implement BinarySensor's write_enabled; this should never be called.

Implements esphome::output::BinaryOutput.

Definition at line 43 of file float_output.cpp.

◆ write_state() [2/2]

virtual void esphome::output::FloatOutput::write_state ( float  state)
protectedpure virtual

Field Documentation

◆ max_power_

float esphome::output::FloatOutput::max_power_ {1.0f}
protected

Definition at line 83 of file float_output.h.

◆ min_power_

float esphome::output::FloatOutput::min_power_ {0.0f}
protected

Definition at line 84 of file float_output.h.

◆ zero_means_zero_

bool esphome::output::FloatOutput::zero_means_zero_
protected

Definition at line 85 of file float_output.h.


The documentation for this class was generated from the following files: