Doxygen with github
Loading...
Searching...
No Matches
ksLed.h
1/*
2 * Copyright (c) 2021-2023, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFramework library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include <Arduino.h>
13#include "../ksComponent.h"
14
15namespace ksf::comps
16{
24 class ksLed : public ksComponent
25 {
26 KSF_RTTI_DECLARATIONS(ksLed, ksComponent)
27
28 protected:
29 uint8_t pin{0};
30 uint32_t lastBlinkTimeMs{0};
31 uint32_t blinkIntervalMs{0};
32 uint32_t blinkLoops{0};
33
34 struct {
35 bool activeLow : 1;
36 bool driveAsPushPull : 1;
37 } bitflags = {false, false};
38
39 public:
46 ksLed(uint8_t pin, bool activeLow = false, bool driveAsPushPull = false);
47
53 bool init(ksApplication* owner) override;
54
59 bool loop(ksApplication* app) override;
60
66 void setBlinking(uint32_t blinkIntervalMs, uint32_t blinkLoops = 0);
67
72 bool isBlinking() const;
73
78 bool isEnabled() const;
79
84 void setEnabled(bool enabled);
85
91
96 uint8_t getPin() const { return pin; }
97
101 virtual ~ksLed();
102 };
103}
A component that simplifies driving the LED.
Definition ksLed.h:25
void setEnabled(bool enabled)
Enables or disables the LED.
Definition ksLed.cpp:75
uint32_t blinkLoops
Number of state change cycles (0 for infinite loop).
Definition ksLed.h:32
virtual ~ksLed()
Destructs the component and restores INPUT mode on the assigned pin.
Definition ksLed.cpp:88
uint8_t getPin() const
Returns a pin number assigned to the LED.
Definition ksLed.h:96
bool isBlinking() const
Returns whether LED is currently blinking.
Definition ksLed.cpp:61
bool init(ksApplication *owner) override
Initializes the LED component.
Definition ksLed.cpp:23
uint8_t pin
Pin number assigned to LED.
Definition ksLed.h:29
uint32_t lastBlinkTimeMs
Timestamp of previous state change (milliseconds).
Definition ksLed.h:30
bool driveAsPushPull
True if the LED should be driven as push-pull, otherwise false.
Definition ksLed.h:36
ksLed(uint8_t pin, bool activeLow=false, bool driveAsPushPull=false)
Constructs the LED object.
Definition ksLed.cpp:16
uint32_t blinkIntervalMs
Intervals between state change (0 to disable blinking).
Definition ksLed.h:31
void setDriveAsPushPull(bool driveAsPushPull)
Enables or disables the push/pull driving mode.
Definition ksLed.cpp:66
bool loop(ksApplication *app) override
Executes core of the LED component logic.
Definition ksLed.cpp:32
void setBlinking(uint32_t blinkIntervalMs, uint32_t blinkLoops=0)
Sets LED blinking pattern.
Definition ksLed.cpp:53
bool isEnabled() const
Returns whether the LED is actually enabled.
Definition ksLed.cpp:48
bool activeLow
True if the LED should be active low, otherwise false.
Definition ksLed.h:35
A class that is a base for user-defined application.
Definition ksApplication.h:43
Base component class.
Definition ksComponent.h:51