Doxygen with github
Loading...
Searching...
No Matches
ksLed.h
1/*
2 * Copyright (c) 2021-2025, 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 <inttypes.h>
13
14#include "../ksComponent.h"
15
16namespace ksf::comps
17{
25 class ksLed : public ksComponent
26 {
27 KSF_RTTI_DECLARATIONS(ksLed, ksComponent)
28
29 protected:
30 uint8_t pin{0};
31 uint32_t lastBlinkTimeMs{0};
32 uint32_t blinkIntervalMs{0};
33 uint32_t blinkLoops{0};
34
35 struct {
36 bool activeLow : 1;
37 bool driveAsPushPull : 1;
38 } bitflags = {false, false};
39
40 public:
47 ksLed(uint8_t pin, bool activeLow = false, bool driveAsPushPull = false);
48
52 virtual ~ksLed();
53
59 bool init(ksApplication* owner) override;
60
65 bool loop(ksApplication* app) override;
66
72 void setBlinking(uint32_t blinkIntervalMs, uint32_t blinkLoops = 0);
73
78 bool isBlinking() const;
79
84 bool isEnabled() const;
85
90 void setEnabled(bool enabled);
91
97
102 uint8_t getPin() const { return pin; }
103 };
104}
A component that simplifies LED control.
Definition ksLed.h:26
void setEnabled(bool enabled)
Enables or disables the LED.
Definition ksLed.cpp:81
uint32_t blinkLoops
Number of state change cycles (0 for infinite loop).
Definition ksLed.h:33
virtual ~ksLed()
Destructs the component and restores INPUT mode on the assigned pin.
Definition ksLed.cpp:24
uint8_t getPin() const
Returns a pin number assigned to the LED.
Definition ksLed.h:102
bool isBlinking() const
Returns whether LED is currently blinking.
Definition ksLed.cpp:67
bool init(ksApplication *owner) override
Initializes the LED component.
Definition ksLed.cpp:29
uint8_t pin
Pin number assigned to LED.
Definition ksLed.h:30
uint32_t lastBlinkTimeMs
Timestamp of previous state change (milliseconds).
Definition ksLed.h:31
bool driveAsPushPull
True if the LED should be driven as push-pull, otherwise false.
Definition ksLed.h:37
ksLed(uint8_t pin, bool activeLow=false, bool driveAsPushPull=false)
Constructs the LED object.
Definition ksLed.cpp:17
uint32_t blinkIntervalMs
Intervals between state change (0 to disable blinking).
Definition ksLed.h:32
void setDriveAsPushPull(bool driveAsPushPull)
Enables or disables the push/pull driving mode.
Definition ksLed.cpp:72
bool loop(ksApplication *app) override
Executes core of the LED component logic.
Definition ksLed.cpp:38
void setBlinking(uint32_t blinkIntervalMs, uint32_t blinkLoops=0)
Sets LED blinking pattern.
Definition ksLed.cpp:59
bool isEnabled() const
Returns whether the LED is actually enabled.
Definition ksLed.cpp:54
bool activeLow
True if the LED should be active low, otherwise false.
Definition ksLed.h:36
A class that serves as the base for user-defined applications.
Definition ksApplication.h:44
Base component class.
Definition ksComponent.h:36