ESPHome  1.15.3
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::esp32_dac::ESP32DAC esphome::esp8266_pwm::ESP8266PWM esphome::ledc::LEDCOutput esphome::my9231::MY9231OutputComponent::Channel esphome::pca9685::PCA9685Channel esphome::pid::PIDSimulator esphome::slow_pwm::SlowPWMOutput esphome::sm16716::SM16716::Channel esphome::sx1509::SX1509FloatOutputChannel esphome::template_::TemplateFloatOutput esphome::tlc59208f::TLC59208FChannel

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_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 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}
 
- 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 20 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 22 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.

◆ 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, and esphome::esp8266_pwm::ESP8266PWM.

Definition at line 61 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 39 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 77 of file float_output.h.

◆ min_power_

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

Definition at line 78 of file float_output.h.


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