ESPHome  2022.6.3
modbus_output.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace modbus_controller {
9 
11  public:
14  this->start_address = start_address;
15  this->offset = offset;
16  this->bitmask = bitmask;
17  this->register_count = register_count;
18  this->sensor_value_type = value_type;
19  this->skip_updates = 0;
20  this->start_address += offset;
21  this->offset = 0;
22  }
23  void dump_config() override;
24 
25  void set_parent(ModbusController *parent) { this->parent_ = parent; }
26  void set_write_multiply(float factor) { multiply_by_ = factor; }
27  // Do nothing
28  void parse_and_publish(const std::vector<uint8_t> &data) override{};
29 
30  using write_transform_func_t = std::function<optional<float>(ModbusFloatOutput *, float, std::vector<uint16_t> &)>;
32  void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
33 
34  protected:
35  void write_state(float value) override;
37 
39  float multiply_by_{1.0};
41 };
42 
44  public:
47  this->start_address = start_address;
48  this->bitmask = bitmask;
50  this->skip_updates = 0;
51  this->register_count = 1;
52  this->start_address += offset;
53  this->offset = 0;
54  }
55  void dump_config() override;
56 
57  void set_parent(ModbusController *parent) { this->parent_ = parent; }
58  // Do nothing
59  void parse_and_publish(const std::vector<uint8_t> &data) override{};
60 
61  using write_transform_func_t = std::function<optional<bool>(ModbusBinaryOutput *, bool, std::vector<uint8_t> &)>;
63  void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
64 
65  protected:
66  void write_state(bool state) override;
68 
71 };
72 
73 } // namespace modbus_controller
74 } // namespace esphome
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
void parse_and_publish(const std::vector< uint8_t > &data) override
Definition: modbus_output.h:28
void set_write_template(write_transform_func_t &&f)
Definition: modbus_output.h:62
void set_parent(ModbusController *parent)
Definition: modbus_output.h:25
void parse_and_publish(const std::vector< uint8_t > &data) override
Definition: modbus_output.h:59
const nullopt_t nullopt((nullopt_t::init()))
void set_use_write_mutiple(bool use_write_multiple)
Definition: modbus_output.h:32
void write_state(float value) override
Write a value to the device.
ModbusBinaryOutput(uint16_t start_address, uint8_t offset)
Definition: modbus_output.h:45
optional< write_transform_func_t > write_transform_func_
Definition: modbus_output.h:36
ModbusFloatOutput(uint16_t start_address, uint8_t offset, SensorValueType value_type, int register_count)
Definition: modbus_output.h:12
Definition: a4988.cpp:4
std::function< optional< float >(ModbusFloatOutput *, float, std::vector< uint16_t > &)> write_transform_func_t
Definition: modbus_output.h:30
void set_parent(ModbusController *parent)
Definition: modbus_output.h:57
void set_use_write_mutiple(bool use_write_multiple)
Definition: modbus_output.h:63
std::function< optional< bool >(ModbusBinaryOutput *, bool, std::vector< uint8_t > &)> write_transform_func_t
Definition: modbus_output.h:61
void set_write_template(write_transform_func_t &&f)
Definition: modbus_output.h:31
bool state
Definition: fan.h:34