ESPHome  2024.10.2
modbus_output.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace modbus_controller {
11 
13  public:
16  this->start_address = start_address;
17  this->offset = offset;
18  this->bitmask = bitmask;
19  this->register_count = register_count;
20  this->sensor_value_type = value_type;
21  this->skip_updates = 0;
22  this->start_address += offset;
23  this->offset = 0;
24  }
25  void dump_config() override;
26 
27  void set_parent(ModbusController *parent) { this->parent_ = parent; }
28  void set_write_multiply(float factor) { multiply_by_ = factor; }
29  // Do nothing
30  void parse_and_publish(const std::vector<uint8_t> &data) override{};
31 
32  using write_transform_func_t = std::function<optional<float>(ModbusFloatOutput *, float, std::vector<uint16_t> &)>;
34  void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
35 
36  protected:
37  void write_state(float value) override;
39 
41  float multiply_by_{1.0};
43 };
44 
46  public:
49  this->start_address = start_address;
50  this->bitmask = bitmask;
52  this->skip_updates = 0;
53  this->register_count = 1;
54  this->start_address += offset;
55  this->offset = 0;
56  }
57  void dump_config() override;
58 
59  void set_parent(ModbusController *parent) { this->parent_ = parent; }
60  // Do nothing
61  void parse_and_publish(const std::vector<uint8_t> &data) override{};
62 
63  using write_transform_func_t = std::function<optional<bool>(ModbusBinaryOutput *, bool, std::vector<uint8_t> &)>;
65  void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
66 
67  protected:
68  void write_state(bool state) override;
70 
73 };
74 
75 } // namespace modbus_controller
76 } // 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:30
void set_write_template(write_transform_func_t &&f)
Definition: modbus_output.h:64
void set_parent(ModbusController *parent)
Definition: modbus_output.h:27
void parse_and_publish(const std::vector< uint8_t > &data) override
Definition: modbus_output.h:61
const nullopt_t nullopt((nullopt_t::init()))
void set_use_write_mutiple(bool use_write_multiple)
Definition: modbus_output.h:34
void write_state(float value) override
Write a value to the device.
ModbusBinaryOutput(uint16_t start_address, uint8_t offset)
Definition: modbus_output.h:47
optional< write_transform_func_t > write_transform_func_
Definition: modbus_output.h:38
ModbusFloatOutput(uint16_t start_address, uint8_t offset, SensorValueType value_type, int register_count)
Definition: modbus_output.h:14
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::function< optional< float >(ModbusFloatOutput *, float, std::vector< uint16_t > &)> write_transform_func_t
Definition: modbus_output.h:32
void set_parent(ModbusController *parent)
Definition: modbus_output.h:59
void set_use_write_mutiple(bool use_write_multiple)
Definition: modbus_output.h:65
std::function< optional< bool >(ModbusBinaryOutput *, bool, std::vector< uint8_t > &)> write_transform_func_t
Definition: modbus_output.h:63
void set_write_template(write_transform_func_t &&f)
Definition: modbus_output.h:33
bool state
Definition: fan.h:34