ESPHome  2024.3.2
micronova.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/log.h"
6 #include "esphome/core/defines.h"
7 #include "esphome/core/helpers.h"
8 
9 #include <vector>
10 
11 namespace esphome {
12 namespace micronova {
13 
14 static const char *const TAG = "micronova";
15 static const int STOVE_REPLY_DELAY = 60;
16 
17 static const std::string STOVE_STATES[11] = {"Off",
18  "Start",
19  "Pellets loading",
20  "Ignition",
21  "Working",
22  "Brazier Cleaning",
23  "Final Cleaning",
24  "Standby",
25  "No pellets alarm",
26  "No ignition alarm",
27  "Undefined alarm"};
28 
29 enum class MicroNovaFunctions {
43 };
44 
45 class MicroNova;
46 
48 // Interface classes.
50  public:
52  MicroNovaBaseListener(MicroNova *m) { this->micronova_ = m; }
53  virtual void dump_config();
54 
55  void set_micronova_object(MicroNova *m) { this->micronova_ = m; }
56 
57  void set_function(MicroNovaFunctions f) { this->function_ = f; }
58  MicroNovaFunctions get_function() { return this->function_; }
59 
60  void set_memory_location(uint8_t l) { this->memory_location_ = l; }
61  uint8_t get_memory_location() { return this->memory_location_; }
62 
63  void set_memory_address(uint8_t a) { this->memory_address_ = a; }
64  uint8_t get_memory_address() { return this->memory_address_; }
65 
66  protected:
67  MicroNova *micronova_{nullptr};
69  uint8_t memory_location_ = 0;
70  uint8_t memory_address_ = 0;
71 };
72 
74  public:
77  virtual void request_value_from_stove() = 0;
78  virtual void process_value_from_stove(int value_from_stove) = 0;
79 
80  void set_needs_update(bool u) { this->needs_update_ = u; }
81  bool get_needs_update() { return this->needs_update_; }
82 
83  protected:
84  bool needs_update_ = false;
85 };
86 
88  public:
90  virtual void request_value_from_stove() = 0;
91  virtual void process_value_from_stove(int value_from_stove) = 0;
92 
93  void set_needs_update(bool u) { this->needs_update_ = u; }
94  bool get_needs_update() { return this->needs_update_; }
95 
96  protected:
97  bool needs_update_ = false;
98 };
99 
101  public:
103  virtual void set_stove_state(bool v) = 0;
104  virtual bool get_stove_state() = 0;
105 
106  protected:
107  uint8_t memory_data_on_ = 0;
108  uint8_t memory_data_off_ = 0;
109 };
110 
112  public:
114 
115  protected:
116  uint8_t memory_data_ = 0;
117 };
118 
120 // Main component class
122  public:
124 
125  void setup() override;
126  void loop() override;
127  void update() override;
128  void dump_config() override;
129  void register_micronova_listener(MicroNovaSensorListener *l) { this->micronova_listeners_.push_back(l); }
130 
131  void request_address(uint8_t location, uint8_t address, MicroNovaSensorListener *listener);
132  void write_address(uint8_t location, uint8_t address, uint8_t data);
133  int read_stove_reply();
134 
135  void set_enable_rx_pin(GPIOPin *enable_rx_pin) { this->enable_rx_pin_ = enable_rx_pin; }
136 
137  void set_current_stove_state(uint8_t s) { this->current_stove_state_ = s; }
138  uint8_t get_current_stove_state() { return this->current_stove_state_; }
139 
140  void set_stove(MicroNovaSwitchListener *s) { this->stove_switch_ = s; }
141  MicroNovaSwitchListener *get_stove_switch() { return this->stove_switch_; }
142 
143  protected:
144  uint8_t current_stove_state_ = 0;
145 
146  GPIOPin *enable_rx_pin_{nullptr};
147 
151  uint8_t memory_address;
154  };
155 
158 
159  std::vector<MicroNovaSensorListener *> micronova_listeners_{};
160  MicroNovaSwitchListener *stove_switch_{nullptr};
161 };
162 
163 } // namespace micronova
164 } // namespace esphome
void setup()
void loop()
void set_enable_rx_pin(GPIOPin *enable_rx_pin)
Definition: micronova.h:135
MicroNovaSwitchListener * get_stove_switch()
Definition: micronova.h:141
uint8_t l
Definition: bl0939.h:19
This class simplifies creating components that periodically check a state.
Definition: component.h:283
MicroNovaSerialTransmission current_transmission_
Definition: micronova.h:157
uint8_t m
Definition: bl0939.h:20
void set_current_stove_state(uint8_t s)
Definition: micronova.h:137
void set_stove(MicroNovaSwitchListener *s)
Definition: micronova.h:140
void set_function(MicroNovaFunctions f)
Definition: micronova.h:57
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void register_micronova_listener(MicroNovaSensorListener *l)
Definition: micronova.h:129
Mutex implementation, with API based on the unavailable std::mutex.
Definition: helpers.h:538