Doxygen with github
Loading...
Searching...
No Matches
ksf::comps::ksLed Class Reference

A component that simplifies driving the LED. More...

#include <ksLed.h>

+ Inheritance diagram for ksf::comps::ksLed:

Public Member Functions

virtual const size_t getInstanceType () const
 Retrieves type ID of the object.
 
virtual bool isA (const size_t id) const
 Checks whether object is of given type.
 
 ksLed (uint8_t pin, bool activeLow=false, bool driveAsPushPull=false)
 Constructs the LED object.
 
bool init (ksApplication *owner) override
 Initializes the LED component.
 
bool loop (ksApplication *app) override
 Executes core of the LED component logic.
 
void setBlinking (uint32_t blinkIntervalMs, uint32_t blinkLoops=0)
 Sets LED blinking pattern.
 
bool isBlinking () const
 Returns whether LED is currently blinking.
 
bool isEnabled () const
 Returns whether the LED is actually enabled.
 
void setEnabled (bool enabled)
 Enables or disables the LED.
 
void setDriveAsPushPull (bool driveAsPushPull)
 Enables or disables the push/pull driving mode.
 
uint8_t getPin () const
 Returns a pin number assigned to the LED.
 
virtual ~ksLed ()
 Destructs the component and restores INPUT mode on the assigned pin.
 
- Public Member Functions inherited from ksf::ksComponent
virtual bool postInit (ksApplication *app)
 Method called after component initialization, used to setup references to other components.
 
- Public Member Functions inherited from ksf::ksRtti
template<typename TType >
TType * as ()
 Tries to cast object to the type provided as a template parameter.
 
template<typename TType >
const TType * as () const
 Tries to cast object to the type provided as a template parameter (const version).
 

Static Public Member Functions

static const size_t getClassType ()
 
- Static Public Member Functions inherited from ksf::ksComponent
static const size_t getClassType ()
 

Protected Attributes

uint8_t pin {0}
 Pin number assigned to LED.
 
uint32_t lastBlinkTimeMs {0}
 Timestamp of previous state change (milliseconds).
 
uint32_t blinkIntervalMs {0}
 Intervals between state change (0 to disable blinking).
 
uint32_t blinkLoops {0}
 Number of state change cycles (0 for infinite loop).
 
struct { 
 
   bool   activeLow: 1 
 True if the LED should be active low, otherwise false.
 
   bool   driveAsPushPull: 1 
 True if the LED should be driven as push-pull, otherwise false.
 
bitflags = {false, false} 
 
- Protected Attributes inherited from ksf::ksComponent
ksComponentState::TYPE componentState { ksComponentState::NotInitialized }
 

Detailed Description

A component that simplifies driving the LED.

It was designed to help the device to signal it's state using blink pattern. This component has also some extra features like state inversion (driveAsActiveLow) and low-power pin driving mode knowm as driveAsPushPull, which uses pull resistors and significantly reduces the amout of emitted light.

Constructor & Destructor Documentation

◆ ksLed()

ksf::comps::ksLed::ksLed ( uint8_t pin,
bool activeLow = false,
bool driveAsPushPull = false )

Constructs the LED object.

Parameters
pinPin number assigned to LED.
activeLowTrue if the LED should be active low, otherwise false
driveAsPushPullTrue if the LED should be driven as push-pull, otherwise false

References driveAsPushPull.

Member Function Documentation

◆ getInstanceType()

virtual const size_t ksf::comps::ksLed::getInstanceType ( ) const
inlinevirtual

Retrieves type ID of the object.

Returns
Object type ID.

Reimplemented from ksf::ksComponent.

◆ getPin()

uint8_t ksf::comps::ksLed::getPin ( ) const
inline

Returns a pin number assigned to the LED.

Returns
Pin number assigned to LED.

References pin.

◆ init()

bool ksf::comps::ksLed::init ( ksApplication * owner)
overridevirtual

Initializes the LED component.

Parameters
ownerPointer to parent ksApplication object.
Returns
True if init succedeed, otherwise false.

Reimplemented from ksf::ksComponent.

References pin, and setEnabled().

◆ isA()

virtual bool ksf::comps::ksLed::isA ( const size_t id) const
inlinevirtual

Checks whether object is of given type.

Parameters
idType ID to check against.
Returns
True if object is of given type, otherwise false.

Reimplemented from ksf::ksComponent.

◆ isBlinking()

bool ksf::comps::ksLed::isBlinking ( ) const

Returns whether LED is currently blinking.

Returns
True if the LED is currently blinking, otherwise false.

References blinkIntervalMs.

◆ isEnabled()

bool ksf::comps::ksLed::isEnabled ( ) const

Returns whether the LED is actually enabled.

Returns
True if the LED is enabled, otherwise false.

References pin.

Referenced by loop(), and setDriveAsPushPull().

◆ loop()

bool ksf::comps::ksLed::loop ( ksApplication * app)
overridevirtual

Executes core of the LED component logic.

Returns
True if everything is okay, otherwise false to break application logic.

Reimplemented from ksf::ksComponent.

References blinkIntervalMs, blinkLoops, isEnabled(), lastBlinkTimeMs, setBlinking(), and setEnabled().

◆ setBlinking()

void ksf::comps::ksLed::setBlinking ( uint32_t blinkIntervalMs,
uint32_t blinkLoops = 0 )

Sets LED blinking pattern.

Parameters
blinkIntervalMsInterval in milliseconds between toggle action (0 to disable blinking)
blinkLoopsNumber of state toggle loops/cycles (0 for infinite loop).

References blinkIntervalMs, blinkLoops, lastBlinkTimeMs, and setEnabled().

Referenced by loop().

◆ setDriveAsPushPull()

void ksf::comps::ksLed::setDriveAsPushPull ( bool driveAsPushPull)

Enables or disables the push/pull driving mode.

Parameters
driveAsPushPullTrue if LED should is driven as push-pull, false otherwise.

References driveAsPushPull, isEnabled(), pin, and setEnabled().

◆ setEnabled()

void ksf::comps::ksLed::setEnabled ( bool enabled)

Enables or disables the LED.

Parameters
enabledTrue to enable LED, false to disable.

References pin.

Referenced by init(), loop(), ksf::comps::ksWifiConfigurator::postInit(), setBlinking(), and setDriveAsPushPull().


The documentation for this class was generated from the following files: