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