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 {
25namespace Io {
26class Base;
27}
28
29class Mutex;
30
31namespace Control {
32
33enum LedState { NOT_INITIALIZED, ON, OFF };
34class BlinkingLed : public Supla::Element {
35 public:
36 explicit BlinkingLed(Supla::Io::Base *io,
37 uint8_t outPin,
38 bool invert = false);
39 explicit BlinkingLed(uint8_t outPin, bool invert = false);
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
65 protected:
66 void updatePin();
67 void turnOn();
68 void turnOff();
69
70 uint8_t outPin = 0;
71 uint8_t onLimitCounter = 0;
72 uint8_t onLimit = 0;
73 uint8_t repeatLimit = 0;
74 bool invert = false;
75 uint32_t onDuration = 0;
76 uint32_t offDuration = 1000;
77 uint32_t pauseDuration = 0;
78 uint32_t lastUpdate = 0;
79 LedState state = NOT_INITIALIZED;
80 Supla::Io::Base *io = nullptr;
81 Supla::Mutex *mutex = nullptr;
82 BlinkingLed *copyStateTo = nullptr;
83 bool enabled = true;
84};
85
86} // namespace Control
87
88} // namespace Supla
89
90#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:37
Definition io.h:35
Definition mutex.h:22