SpaIot Library
framedecoder.h
1/*
2 * SpaIot Library (c) by epsilonrt - epsilonrt@gmail.com
3 * This file is part of SpaIot library <https://github.com/epsilonrt/spaiot-lib>
4 * This file is based on DIYSCIP (c) by Geoffroy HUBERT
5 *
6 * SpaIot library is licensed under a
7 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
8 *
9 * You should have received a copy of the license along with this
10 * work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
11 *
12 * SpaIot library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY;
14 */
15#pragma once
16
17#include <map>
18#include "bussettings.h"
19
20namespace SpaIot {
21
36 public:
45 void begin();
52 bool isOpened() const;
58 bool hasLed (int key) const;
63 const BusSettings & busSettings() const;
69 const std::map <int, LedSettings> ledSettings() const;
78 uint16_t rawStatus() const;
85 uint8_t isLedOn (int key) const;
91 inline uint8_t isPowerOn() const;
99 inline uint8_t isFilterOn() const;
107 inline uint8_t isBubbleOn() const;
116 inline uint8_t isHeatReached() const;
124 inline uint8_t isJetOn() const;
132 inline uint8_t isSanitizerOn() const;
142 uint8_t isHeaterOn() const;
152 uint16_t waterTemp() const;
164 uint16_t desiredTemp() const;
170 uint16_t sanitizerTime() const;
176 uint32_t frameCounter() const;
188 uint32_t frameDropped() const;
199 uint16_t error();
215 uint8_t isDisplayBlink() const;
222 uint8_t waitUntilDisplayBlink (unsigned long MaxWaitingTimeMs = 5000) const;
233 uint16_t waitForWaterTemp (unsigned long MaxWaitingTimeMs = 25000) const;
234
235 protected:
236 FrameDecoder (const BusSettings & bus,
237 const std::map <int, LedSettings> & leds);
238 static uint16_t convertDisplayToCelsius (uint16_t m_displayValue);
239
240 protected:
241 const BusSettings & m_busSettings;
242 const std::map <int, LedSettings> & m_ledSettings;
243
244 // Parameters set by the constructor
245 static int m_dataPin;
246 static uint16_t m_frameLedPower;
247 static uint16_t m_frameLedFilter;
248 static uint16_t m_frameLedHeater;
249 static uint16_t m_frameLedHeaterReached;
250 static uint16_t m_frameLedBubble;
251 static uint16_t m_frameLedJet;
252 static uint16_t m_frameLedSanitizer;
253
254 // Data members of Decoder, updated by interrupt service routines
255 static volatile uint32_t m_frameCounter;
256 static volatile uint32_t m_frameDropped;
257 static volatile uint16_t m_rawStatus;
258 static volatile uint16_t m_errorValue;
259 static volatile uint16_t m_waterTemp;
260 static volatile uint16_t m_desiredTemp;
261 static volatile uint16_t m_sanitizerTime;
262
263 // Working status variables, updated by interrupt service routines
264 static volatile uint16_t m_frameValue;
265 static volatile uint16_t m_frameShift;
266 static volatile uint16_t m_displayValue;
267 static volatile uint32_t m_lastSanitizerFrameCounter;
268 static volatile uint32_t m_lastBlackDisplayFrameCounter;
269 static volatile bool m_isDisplayBlink;
270 static volatile uint32_t m_lastErrorChangeFrameCounter;
271 static volatile uint16_t m_latestLedStatus;
272 static volatile uint16_t m_stableLedStatusCounter;
273 static volatile uint16_t m_latestDisplayValue;
274 static volatile uint16_t m_stableDisplayValueCounter;
275 static volatile uint16_t m_latestDesiredTemp;
276 static volatile uint16_t m_latestWaterTemp;
277 static volatile uint16_t m_stableWaterTempCounter;
278 static volatile uint16_t m_unsetDigits;
279 static volatile uint8_t m_lastTempUnit;
280 static volatile uint32_t m_lastTempUnitChangeFrameCounter;
281 static volatile uint16_t m_counterTempUnitChanged;
282
283 static const unsigned long FramePeriodUs = 320;
284 static const uint32_t SetupTrigUnitChangeFrameCounterMax =
285 (SetupTrigUnitChangeStepMaxMs * 1000) / FramePeriodUs;
286 static const uint32_t ResetErrorFrameCounter =
287 (ResetErrorTimeMs * 1000) / FramePeriodUs;
288 private:
289 bool m_isopened;
290 static IRAM_ATTR void clkRisingInterrupt();
291 static IRAM_ATTR void holdRisingInterrupt();
292 };
293
294
295 //----------------------------------------------------------------------------
296 inline uint8_t FrameDecoder::isPowerOn() const {
297
298 return isLedOn (Power);
299 }
300
301 //----------------------------------------------------------------------------
302 inline uint8_t FrameDecoder::isFilterOn() const {
303
304 return isLedOn (Filter);
305 }
306
307 //----------------------------------------------------------------------------
308 inline uint8_t FrameDecoder::isBubbleOn() const {
309
310 return isLedOn (Bubble);
311 }
312
313 //----------------------------------------------------------------------------
314 inline uint8_t FrameDecoder::isHeatReached() const {
315
316 return isLedOn (HeatReached);
317 }
318
319 //----------------------------------------------------------------------------
320 inline uint8_t FrameDecoder::isJetOn() const {
321
322 return isLedOn (Jet);
323 }
324
325 //----------------------------------------------------------------------------
326 inline uint8_t FrameDecoder::isSanitizerOn() const {
327
328 return isLedOn (Sanitizer);
329 }
330
331}
This class decodes information from the technical block of the spa.
Definition: framedecoder.h:35
uint32_t frameDropped() const
Number of dropped frames.
bool isOpened() const
Indicates whether the connection with the spa is established.
uint16_t waterTemp() const
Water temperature in °C.
uint8_t isPowerOn() const
Last state of the Power LED.
Definition: framedecoder.h:296
uint8_t isBubbleOn() const
Last state of the Bubble LED.
Definition: framedecoder.h:308
uint8_t isHeaterOn() const
State of water heating.
void begin()
Initializes and connect with the spa.
uint16_t error()
Error code displayed by the control panel.
uint8_t isDisplayBlink() const
Check if the display blink.
const BusSettings & busSettings() const
Bus settings provides at the instantiation.
uint8_t isJetOn() const
Last state of the Jet LED.
Definition: framedecoder.h:320
bool isSetupModeTriggered() const
Reset request triggered.
uint8_t isLedOn(int key) const
Last state received from an LED.
uint16_t rawStatus() const
Last state of the LEDs received.
uint32_t frameCounter() const
Number of frames received from startup.
uint8_t isFilterOn() const
Last state of the Filter LED.
Definition: framedecoder.h:302
const std::map< int, LedSettings > ledSettings() const
Leds settings provides at the instantiation.
uint8_t isHeatReached() const
Last state of the HeatReached LED.
Definition: framedecoder.h:314
uint8_t isSanitizerOn() const
Last state of the Sanitizer LED.
Definition: framedecoder.h:326
uint16_t desiredTemp() const
Water temperature desired in °C.
uint8_t waitUntilDisplayBlink(unsigned long MaxWaitingTimeMs=5000) const
Wait until the display blink.
uint16_t sanitizerTime() const
Remaining sanitation time.
bool hasLed(int key) const
Check if the hardware configuration has the LED.
uint16_t waitForWaterTemp(unsigned long MaxWaitingTimeMs=25000) const
Wait until the water temperature could be read.
SpaIot name space.
Definition: bussettings.h:21
@ Jet
Jet Led or Button.
Definition: global.h:29
@ Filter
Filter Led or Button.
Definition: global.h:27
@ Sanitizer
Sanitizer Led or Button.
Definition: global.h:30
@ HeatReached
Heat Reached Led (Green)
Definition: global.h:32
@ Bubble
Bubble Led or Button.
Definition: global.h:28
@ Power
Power Led or Button.
Definition: global.h:26
const unsigned long SetupTrigUnitChangeStepMaxMs
Maximum time separating successive actions on the unit change button to trigger reset request.
Definition: global.h:44
const unsigned long ResetErrorTimeMs
Time after which an error can be erased.
Definition: global.h:47