Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
lampda::logic::SunTimerBase< BrightnessSunTime > Class Template Referenceabstract

Sun timer operations handler All sun operations are exclusive, thay cannot run at the same time. More...

#include <sun_timers.h>

Public Member Functions

bool is_enabled () const
 
uint32_t get_remaining_time_s () const
 Return the time left before the end of the timer, in seconds. 0 if the timer is not enabled.
 
bool cancel ()
 Cancel the current active timer.
 
void set_deadline (const uint32_t timeshutdown_s)
 Start the sun timer with a deadline, or prolonge the current sun timer.
 
void add_time_minutes (const uint8_t time_minutes)
 Add some time to the current timer, or start it with a target time in minutes. This time cannot be shorter than BrightnessSunTime_min.
 
void lock_brightness_update (bool shouldLock)
 Lock the hability of the sunset timer to control the brightness.
 
void shortcut_to_brightness_phase ()
 Shortcut the whole timer to the brightness control phase.
 
void sun_process_loop ()
 sun process task INTERNAL USE ONLY
 

Static Public Attributes

static constexpr uint32_t BrightnessSunTime_min = BrightnessSunTime
 
static constexpr uint32_t BrightnessSunTime_s = BrightnessSunTime_min * 60
 
static constexpr uint32_t BrightnessSunTime_ms = BrightnessSunTime_s * 1000
 
static constexpr uint16_t brightnessDecreasePerLoop = 1
 
static constexpr uint16_t brightnessIncreasePerLoop = 1
 Brightness increase per loop call during the brightness phase.
 
static constexpr uint16_t minimalSunUpdateCalls = 50
 minimum calls to the update sunset function that will be made
 
static constexpr uint16_t minimalSunLoopDuration_ms = 5
 Minimum time between sunset loop calls.
 

Protected Member Functions

virtual bool should_accept_start () const =0
 Overloadable: A timer can refuse to start under some conditions.
 
virtual void sun_timer_progress_update_callback (const float progress) const =0
 Wrapper to the custom user code to call for a sun timer update.
 
bool release ()
 Release the timer, without restoring the brightness scale.
 
virtual void end_of_timer_handle ()=0
 Called when the timer reaches its target. The brightness scale is left as is by the release: the handle must set it.
 
virtual void timer_brightness_progress_update (const float progress)=0
 Called when the timer progresses through the brightness phase.
 
uint32_t get_loop_timing_ms () const
 Compute the timing delay of the loop to stay at the target brightness control frequency.
 
float get_percent_of_advance () const
 Return the sun timer progress between 0 to 1.
 
float signal_sun_update () const
 Signal a sun timer update to consummers.
 

Protected Attributes

volatile uint32_t endTime_s = 0
 End of the timer operation, in the lamp time counter. 0 when the timer is not running. Atomic: the timer task and the main loop (inputs, CLI) can both release it.
 
bool isAllowedToControlBrightness = true
 Is the handler allowed to control lamp brightness.
 

Detailed Description

template<uint32_t BrightnessSunTime>
class lampda::logic::SunTimerBase< BrightnessSunTime >

Sun timer operations handler All sun operations are exclusive, thay cannot run at the same time.

Member Function Documentation

◆ cancel()

template<uint32_t T>
bool lampda::logic::SunTimerBase< T >::cancel

Cancel the current active timer.

Returns
true if the timer was running. Only one caller can release a running timer, so a timer canceled from another thread never runs its end of timer handle

◆ end_of_timer_handle()

template<uint32_t BrightnessSunTime>
virtual void lampda::logic::SunTimerBase< BrightnessSunTime >::end_of_timer_handle ( )
protectedpure virtual

Called when the timer reaches its target. The brightness scale is left as is by the release: the handle must set it.

Implemented in lampda::logic::SunsetTimer, and lampda::logic::SunriseTimer.

◆ release()

template<uint32_t T>
bool lampda::logic::SunTimerBase< T >::release
protected

Release the timer, without restoring the brightness scale.

Returns
true if the timer was running. See cancel

◆ should_accept_start()

template<uint32_t BrightnessSunTime>
virtual bool lampda::logic::SunTimerBase< BrightnessSunTime >::should_accept_start ( ) const
protectedpure virtual

Overloadable: A timer can refuse to start under some conditions.

Implemented in lampda::logic::SunsetTimer, and lampda::logic::SunriseTimer.

◆ signal_sun_update()

template<uint32_t T>
float lampda::logic::SunTimerBase< T >::signal_sun_update
protected

Signal a sun timer update to consummers.

Returns
the progress between 0 and 1

◆ sun_timer_progress_update_callback()

template<uint32_t BrightnessSunTime>
virtual void lampda::logic::SunTimerBase< BrightnessSunTime >::sun_timer_progress_update_callback ( const float  progress) const
protectedpure virtual

Wrapper to the custom user code to call for a sun timer update.

Parameters
[in]progressbetween 0 and 1

Implemented in lampda::logic::SunsetTimer, and lampda::logic::SunriseTimer.

◆ timer_brightness_progress_update()

template<uint32_t BrightnessSunTime>
virtual void lampda::logic::SunTimerBase< BrightnessSunTime >::timer_brightness_progress_update ( const float  progress)
protectedpure virtual

Called when the timer progresses through the brightness phase.

Implemented in lampda::logic::SunsetTimer, and lampda::logic::SunriseTimer.


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