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