14static constexpr uint8_t TEXT_SENSOR_MAX_LEN = 14;
16static constexpr uint8_t MAX_BATTERIES = 16;
18static_assert(MAX_BATTERIES <=
sizeof(
battery_mask_t) * 8,
"battery mask too narrow");
20static constexpr uint8_t MAX_CELLS = 15;
22static_assert(MAX_CELLS <=
sizeof(
cell_mask_t) * 8,
"cell mask too narrow");
38 using CellArray = std::array<CellContents, MAX_CELLS>;
45#ifdef PYLONTECH_CELL_BATTERY_COUNT
65 void setup()
override;
70#ifdef PYLONTECH_CELL_BATTERY_COUNT
75#ifdef PYLONTECH_LISTENER_COUNT
80#ifdef PYLONTECH_CELL_BATTERY_COUNT
95#ifdef PYLONTECH_CELL_BATTERY_COUNT
104 static_assert(PYLONTECH_BATTERY_COUNT <= MAX_BATTERIES,
"more slots than batteries");
105 std::array<PylontechListener::LineContents, PYLONTECH_BATTERY_COUNT>
slots_;
106#ifdef PYLONTECH_CELL_BATTERY_COUNT
109 std::array<PylontechListener::CellArray, PYLONTECH_CELL_BATTERY_COUNT>
cell_slots_;
114#ifdef PYLONTECH_CELL_BATTERY_COUNT
115 std::array<cell_mask_t, PYLONTECH_CELL_BATTERY_COUNT>
cells_read_;
121#ifdef PYLONTECH_CELL_BATTERY_COUNT
Collects bytes into NUL terminated lines of up to N - 1 characters; IGNORE_CHAR bytes are skipped and...
This class simplifies creating components that periodically check a state.
Minimal static vector - saves memory by avoiding std::vector overhead.
StaticVector< PylontechListener *, PYLONTECH_LISTENER_COUNT > listeners_
void process_line_(const char *buffer)
void loop() override
Read data once available.
bool cell_polling_enabled_
battery_mask_t cells_pending_
void add_cell_battery(uint8_t bat_num)
Read the cells of this battery with "bat N" after every "pwr" reply.
void parse_header_(const char *buffer)
battery_mask_t batteries_
std::array< PylontechListener::CellArray, PYLONTECH_CELL_BATTERY_COUNT > cell_slots_
battery_mask_t cell_batteries_
void update() override
Schedule data readings.
LineReader< 200 > line_reader_
void setup() override
Setup the sensor and test for a connection.
std::array< cell_mask_t, PYLONTECH_CELL_BATTERY_COUNT > cells_read_
std::array< PylontechListener::LineContents, PYLONTECH_BATTERY_COUNT > slots_
void register_listener(PylontechListener *listener)
void set_cell_polling_enabled(bool enabled)
Turn the "bat N" cell readings after each "pwr" reply off or on; nothing to turn off without cell sen...
void dump_config() override
void parse_cell_line_(const char *buffer)
virtual void on_line_read(LineContents *line)=0
Called only with records for this listener's battery.
PylontechListener(uint8_t bat_num)
std::array< CellContents, MAX_CELLS > CellArray
virtual void on_cells_read(const CellArray &cells, cell_mask_t read)
Called with the cells of this listener's battery after a "bat N" reply; bit c of read is set when cel...
uint8_t get_battery() const
virtual void dump_config()=0
char base_st[TEXT_SENSOR_MAX_LEN]
char temp_st[TEXT_SENSOR_MAX_LEN]
char curr_st[TEXT_SENSOR_MAX_LEN]
char volt_st[TEXT_SENSOR_MAX_LEN]