supla-device
Loading...
Searching...
No Matches
status_led.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_DEVICE_STATUS_LED_H_
20#define SRC_SUPLA_DEVICE_STATUS_LED_H_
21
22#include <supla/control/blinking_led.h>
23
24namespace Supla {
25
26enum LedMode : uint8_t {
27 LED_ON_WHEN_CONNECTED /* default */,
28 LED_OFF_WHEN_CONNECTED,
29 LED_ALWAYS_OFF,
30 LED_IN_CONFIG_MODE_ONLY
31};
32
33// States SERVER_CONNECTING, REGISTERED_AND_READY, PACZKOW_WE_HAVE_A_PROBLEM
34// may be different in multiprotocol scenario. We consider error as highest
35// priority LED status, then SERVER_CONNECTING, and lowest priority has
36// REGISTERED_AND_READY state. So for all states where Supla protocol has
37// SERVER_CONNECTING and REGISTERED_AND_READY we check also other protocol
38// layers state if they doesn't have any higher priority state.
39enum LedSequence : uint8_t {
40 NETWORK_CONNECTING /* initial state 2000/2000 ms */,
41 SERVER_CONNECTING /* flashing 500/500 ms */,
42 REGISTERED_AND_READY /* stable ON or OFF depending on config */,
43 CONFIG_MODE /* quick flashing 100/100 ms */,
44 SW_DOWNLOAD /* very fast flashing 20/20 ms */,
45 PACZKOW_WE_HAVE_A_PROBLEM /* some problem 300/100 ms */,
46 TESTING_PROCEDURE, /* used to indicate almost finished test 50/50 ms */
47 CUSTOM_SEQUENCE /* values set manually, state changes ignored */
48};
49
50namespace Device {
51
52
53class StatusLed : public Supla::Control::BlinkingLed {
54 public:
55 explicit StatusLed(Supla::Io *io, uint8_t outPin, bool invert = false);
56 explicit StatusLed(uint8_t outPin, bool invert = false);
57
58 void onLoadConfig(SuplaDeviceClass *) override;
59 void iterateAlways() override;
60 void onDeviceConfigChange(uint64_t fieldBit) override;
61
62 // Enables custom LED sequence based on given durations.
63 // Automatic sequence change will be disabled.
64 void setCustomSequence(uint32_t onDurationMs,
65 uint32_t offDurationMs,
66 uint32_t pauseDurrationMs = 0,
67 uint8_t onLimit = 0,
68 uint8_t repeatLimit = 0,
69 bool startWithOff = true) override;
70
71 enum LedSequence getCurrentSequence() const;
72
73 // Restores automatic LED sequence change based on device state.
74 // It is enabled by default, so if it wasn't disabled by calling
75 // setCustomSequence, then there is no need to call it.
76 void setAutoSequence();
77
78 // Sets status LED mode
79 void setMode(LedMode newMode);
80 LedMode getMode() const;
81 void storeModeToConfig();
82 void setDefaultMode(enum LedMode newMode);
83 void setUseDeviceConfig(bool value);
84 void identify();
85
86 protected:
87 LedSequence currentSequence = NETWORK_CONNECTING;
88 LedMode ledMode = LED_ON_WHEN_CONNECTED;
89 int8_t defaultMode = 0;
90 bool useDeviceConfig = true;
91};
92
93} // namespace Device
94} // namespace Supla
95
96#endif // SRC_SUPLA_DEVICE_STATUS_LED_H_
Definition SuplaDevice.h:96
Definition blinking_led.h:31
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition status_led.cpp:42
void onDeviceConfigChange(uint64_t fieldBit) override
Method called when device config is changed.
Definition status_led.cpp:306
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition status_led.cpp:110
Definition io.h:33