supla-device
Loading...
Searching...
No Matches
blinking_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_CONTROL_BLINKING_LED_H_
20#define SRC_SUPLA_CONTROL_BLINKING_LED_H_
21
22#include <supla/element.h>
23
24namespace Supla {
25class Io;
26class Mutex;
27
28namespace Control {
29
30enum LedState { NOT_INITIALIZED, ON, OFF };
31class BlinkingLed : public Supla::Element {
32 public:
33 explicit BlinkingLed(Supla::Io *io, uint8_t outPin, bool invert = false);
34 explicit BlinkingLed(uint8_t outPin, bool invert = false);
35
36 void onInit() override;
37 void onTimer() override;
38
39 // Use inverted logic for GPIO output, when:
40 // false -> HIGH=ON, LOW=OFF
41 // true -> HIGH=OFF, LOW=ON
42 void setInvertedLogic(bool invertedLogic);
43
44 // Enables custom LED sequence based on given durations.
45 // Automatic sequence change will be disabled.
46 virtual void setCustomSequence(uint32_t onDurationMs,
47 uint32_t offDurationMs,
48 uint32_t pauseDurrationMs = 0,
49 uint8_t onLimit = 0,
50 uint8_t repeatLimit = 0,
51 bool startWithOff = true);
52
53 void setAlwaysOffSequence();
54 void setAlwaysOnSequence();
55
56 void setCopyStateTo(BlinkingLed *led);
57 void disable();
58 void enable();
59
60 protected:
61 void updatePin();
62 void turnOn();
63 void turnOff();
64
65 uint8_t outPin = 0;
66 uint8_t onLimitCounter = 0;
67 uint8_t onLimit = 0;
68 uint8_t repeatLimit = 0;
69 bool invert = false;
70 uint32_t onDuration = 0;
71 uint32_t offDuration = 1000;
72 uint32_t pauseDuration = 0;
73 uint32_t lastUpdate = 0;
74 LedState state = NOT_INITIALIZED;
75 Supla::Io *io = nullptr;
76 Supla::Mutex *mutex = nullptr;
77 BlinkingLed *copyStateTo = nullptr;
78 bool enabled = true;
79};
80
81} // namespace Control
82
83} // namespace Supla
84
85#endif // SRC_SUPLA_CONTROL_BLINKING_LED_H_
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition blinking_led.cpp:39
void onTimer() override
Method called on timer interupt.
Definition blinking_led.cpp:48
Base class for all elements of SuplaDevice.
Definition element.h:33
Definition io.h:33
Definition mutex.h:22