ESPHome  2024.10.2
modbus_textsensor.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 
12 enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2, ANSI = 3 };
13 
15  public:
16  ModbusTextSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint8_t register_count,
17  uint16_t response_bytes, RawEncoding encode, uint16_t skip_updates, bool force_new_range) {
18  this->register_type = register_type;
19  this->start_address = start_address;
20  this->offset = offset;
21  this->response_bytes = response_bytes;
22  this->register_count = register_count;
23  this->encode_ = encode;
24  this->skip_updates = skip_updates;
25  this->bitmask = 0xFFFFFFFF;
26  this->sensor_value_type = SensorValueType::RAW;
27  this->force_new_range = force_new_range;
28  }
29 
30  void dump_config() override;
31 
32  void parse_and_publish(const std::vector<uint8_t> &data) override;
33  using transform_func_t =
34  std::function<optional<std::string>(ModbusTextSensor *, std::string, const std::vector<uint8_t> &)>;
35  void set_template(transform_func_t &&f) { this->transform_func_ = f; }
36 
37  protected:
39 
41 };
42 
43 } // namespace modbus_controller
44 } // namespace esphome
ModbusTextSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint8_t register_count, uint16_t response_bytes, RawEncoding encode, uint16_t skip_updates, bool force_new_range)
const nullopt_t nullopt((nullopt_t::init()))
std::function< optional< std::string >(ModbusTextSensor *, std::string, const std::vector< uint8_t > &)> transform_func_t
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7