supla-device
Loading...
Searching...
No Matches
status_led.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_DEVICE_STATUS_LED_H_
5#define SRC_SUPLA_DEVICE_STATUS_LED_H_
6
7#include <supla/control/blinking_led.h>
8
9namespace Supla {
10
11namespace Io {
12class Base;
13} // namespace Io
14
15enum LedMode : uint8_t {
16 LED_ON_WHEN_CONNECTED /* default */,
17 LED_OFF_WHEN_CONNECTED,
18 LED_ALWAYS_OFF,
19 LED_IN_CONFIG_MODE_ONLY
20};
21
22// States SERVER_CONNECTING, REGISTERED_AND_READY, PACZKOW_WE_HAVE_A_PROBLEM
23// may be different in multiprotocol scenario. We consider error as highest
24// priority LED status, then SERVER_CONNECTING, and lowest priority has
25// REGISTERED_AND_READY state. So for all states where Supla protocol has
26// SERVER_CONNECTING and REGISTERED_AND_READY we check also other protocol
27// layers state if they doesn't have any higher priority state.
28enum LedSequence : uint8_t {
29 NETWORK_CONNECTING /* initial state 2000/2000 ms */,
30 SERVER_CONNECTING /* flashing 500/500 ms */,
31 REGISTERED_AND_READY /* stable ON or OFF depending on config */,
32 CONFIG_MODE /* quick flashing 100/100 ms */,
33 SW_DOWNLOAD /* very fast flashing 20/20 ms */,
34 PACZKOW_WE_HAVE_A_PROBLEM /* some problem 300/100 ms */,
35 TESTING_PROCEDURE, /* used to indicate almost finished test 50/50 ms */
36 CUSTOM_SEQUENCE, /* values set manually, state changes ignored */
37 NOT_CONFIGURED_MODE, /* double blink, pause */
38};
39
40namespace Device {
41
42
44 public:
45 explicit StatusLed(Supla::Io::Base *io, uint8_t outPin, bool invert = false);
46 explicit StatusLed(uint8_t outPin, bool invert = false);
47
48 void onLoadConfig(SuplaDeviceClass *) override;
49 void iterateAlways() override;
50 void onDeviceConfigChange(uint64_t fieldBit) override;
51
52 // Enables custom LED sequence based on given durations.
53 // Automatic sequence change will be disabled.
54 void setCustomSequence(uint32_t onDurationMs,
55 uint32_t offDurationMs,
56 uint32_t pauseDurrationMs = 0,
57 uint8_t onLimit = 0,
58 uint8_t repeatLimit = 0,
59 bool startWithOff = true) override;
60
61 enum LedSequence getCurrentSequence() const;
62
63 // Restores automatic LED sequence change based on device state.
64 // It is enabled by default, so if it wasn't disabled by calling
65 // setCustomSequence, then there is no need to call it.
66 void setAutoSequence();
67
68 // Sets status LED mode
69 void setMode(LedMode newMode);
70 LedMode getMode() const;
71 void storeModeToConfig();
72 void setDefaultMode(enum LedMode newMode);
73 void setUseDeviceConfig(bool value);
74 void identify();
75
76 protected:
77 LedSequence currentSequence = NETWORK_CONNECTING;
78 LedMode ledMode = LED_ON_WHEN_CONNECTED;
79 int8_t defaultMode = 0;
80 bool useDeviceConfig = true;
81};
82
83} // namespace Device
84} // namespace Supla
85
86#endif // SRC_SUPLA_DEVICE_STATUS_LED_H_
Definition SuplaDevice.h:167
Definition blinking_led.h:16
Definition status_led.h:43
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition status_led.cpp:29
void onDeviceConfigChange(uint64_t fieldBit) override
Method called when device config is changed.
Definition status_led.cpp:337
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition status_led.cpp:97
Definition io.h:23