Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
SmartSwitch Class Reference

Class that: More...

#include <cs_SmartSwitch.h>

Inheritance diagram for SmartSwitch:
Collaboration diagram for SmartSwitch:

Public Types

typedef function< void(uint8_t newIntensity)> callback_on_intensity_change_t
 Callback function definition. More...
 

Public Member Functions

void init (const boards_config_t &board)
 
void start ()
 Start switch. More...
 
cs_ret_code_t set (uint8_t intensity)
 Set intended intensity. More...
 
uint8_t getCurrentIntensity ()
 Get current switch intensity. More...
 
uint8_t getIntendedState ()
 Get the intended switch state. More...
 
switch_state_t getActualState ()
 Get actual switch state. More...
 
void onUnexpextedIntensityChange (const callback_on_intensity_change_t &closure)
 Register a callback function that's called when state changes unexpectedly. More...
 
void handleEvent (event_t &evt) override
 Handle events. More...
 
- Public Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 

Private Member Functions

 TYPIFY (STATE_SWITCH_STATE) _storedState
 Cached value of what's stored in State. More...
 
 TYPIFY (CONFIG_DIMMING_ALLOWED) _allowDimming
 Cached value of what's stored in State. More...
 
 TYPIFY (CONFIG_SWITCH_LOCKED) _switchLocked
 Cached value of what's stored in State. More...
 
bool allowSwitching ()
 Whether switch state is allowed to be changed. More...
 
uint8_t getIntensityFromSwitchState (switch_state_t switchState)
 Get intensity from a switch state. More...
 
cs_ret_code_t resolveIntendedState ()
 From set intended state, try to set the relay and/or dimmer to correct values. More...
 
cs_ret_code_t setRelay (bool on)
 Set relay. More...
 
cs_ret_code_t setRelayUnchecked (bool on)
 Set relay without checks. More...
 
cs_ret_code_t setDimmer (uint8_t intensity, bool fade=true)
 Set dimmer. More...
 
cs_ret_code_t setDimmerUnchecked (uint8_t intensity, bool fade)
 Set dimmer without checks. More...
 
void handleUnexpectedStateChange (switch_state_t newState)
 Handle unexpected state change by safeSwitch. More...
 
void sendUnexpectedIntensityUpdate (uint8_t newIntensity)
 Send intensity update to listeners. More...
 
void store (switch_state_t newState)
 Store switch state to State class. More...
 
cs_ret_code_t setSwitchLock (bool lock)
 Set switch lock. More...
 
cs_ret_code_t setAllowDimming (bool allowed)
 Set allow dimming. More...
 
void handleAllowDimmingSet ()
 
cs_ret_code_t handleCommandSetRelay (bool on)
 
cs_ret_code_t handleCommandSetDimmer (uint8_t intensity)
 

Private Attributes

SafeSwitch _safeSwitch
 
uint8_t _intendedState
 Intended switch state by the user, as percentage. More...
 
callback_on_intensity_change_t _callbackOnIntensityChange
 Callback to be called when switch state changes unexpectedly, so anything but set(). More...
 
bool _allowSwitchingOverride = false
 Override of switch lock, necessary to restore state at startup. More...
 

Detailed Description

Class that:

  • From intended intensity 0-100, decides whether to use the dimmer or relay.
  • Checks if dimming is allowed, and if switching is allowed.
  • Stores state in State class.
  • [future] Slowly (seconds) fades to intended state.

Member Typedef Documentation

◆ callback_on_intensity_change_t

typedef function<void(uint8_t newIntensity)> SmartSwitch::callback_on_intensity_change_t

Callback function definition.

Member Function Documentation

◆ allowSwitching()

bool SmartSwitch::allowSwitching ( )
private

Whether switch state is allowed to be changed.

◆ getActualState()

switch_state_t SmartSwitch::getActualState ( )

Get actual switch state.

◆ getCurrentIntensity()

uint8_t SmartSwitch::getCurrentIntensity ( )

Get current switch intensity.

Returns
The current switch intensity: 0-100.

◆ getIntendedState()

uint8_t SmartSwitch::getIntendedState ( )

Get the intended switch state.

Returns
Intended switch intensity: 0-100.

◆ getIntensityFromSwitchState()

uint8_t SmartSwitch::getIntensityFromSwitchState ( switch_state_t  switchState)
private

Get intensity from a switch state.

◆ handleAllowDimmingSet()

void SmartSwitch::handleAllowDimmingSet ( )
private

◆ handleCommandSetDimmer()

cs_ret_code_t SmartSwitch::handleCommandSetDimmer ( uint8_t  intensity)
private

◆ handleCommandSetRelay()

cs_ret_code_t SmartSwitch::handleCommandSetRelay ( bool  on)
private

◆ handleEvent()

void SmartSwitch::handleEvent ( event_t evt)
overridevirtual

Handle events.

Implements EventListener.

◆ handleUnexpectedStateChange()

void SmartSwitch::handleUnexpectedStateChange ( switch_state_t  newState)
private

Handle unexpected state change by safeSwitch.

◆ init()

void SmartSwitch::init ( const boards_config_t board)

◆ onUnexpextedIntensityChange()

void SmartSwitch::onUnexpextedIntensityChange ( const callback_on_intensity_change_t closure)

Register a callback function that's called when state changes unexpectedly.

◆ resolveIntendedState()

cs_ret_code_t SmartSwitch::resolveIntendedState ( )
private

From set intended state, try to set the relay and/or dimmer to correct values.

Does not set intended state.

◆ sendUnexpectedIntensityUpdate()

void SmartSwitch::sendUnexpectedIntensityUpdate ( uint8_t  newIntensity)
private

Send intensity update to listeners.

Only to be called when state changes due to events, not due to calls to set(). This prevents the user to get updates before the call is even finished, this is what return codes are for.

◆ set()

cs_ret_code_t SmartSwitch::set ( uint8_t  intensity)

Set intended intensity.

Intended state is only changed by this function.

Parameters
[in]Intensityvalue: 0-100
Returns
Return code. When it's not success, the current intensity might have changed to something else. ERR_NOT_POWERED when trying to dim while the dimmer is not powered.

◆ setAllowDimming()

cs_ret_code_t SmartSwitch::setAllowDimming ( bool  allowed)
private

Set allow dimming.

Also updates State.

◆ setDimmer()

cs_ret_code_t SmartSwitch::setDimmer ( uint8_t  intensity,
bool  fade = true 
)
private

Set dimmer.

Checks if dimming and switching is allowed.

◆ setDimmerUnchecked()

cs_ret_code_t SmartSwitch::setDimmerUnchecked ( uint8_t  intensity,
bool  fade 
)
private

Set dimmer without checks.

Also updates State.

◆ setRelay()

cs_ret_code_t SmartSwitch::setRelay ( bool  on)
private

Set relay.

Checks if switching is allowed.

◆ setRelayUnchecked()

cs_ret_code_t SmartSwitch::setRelayUnchecked ( bool  on)
private

Set relay without checks.

Also updates State.

◆ setSwitchLock()

cs_ret_code_t SmartSwitch::setSwitchLock ( bool  lock)
private

Set switch lock.

Also updates State.

◆ start()

void SmartSwitch::start ( )

Start switch.

To be called once there is enough power to switch relay, and enable dimmer.

◆ store()

void SmartSwitch::store ( switch_state_t  newState)
private

Store switch state to State class.

Also updates storedState.

◆ TYPIFY() [1/3]

SmartSwitch::TYPIFY ( CONFIG_DIMMING_ALLOWED  )
private

Cached value of what's stored in State.

◆ TYPIFY() [2/3]

SmartSwitch::TYPIFY ( CONFIG_SWITCH_LOCKED  )
private

Cached value of what's stored in State.

◆ TYPIFY() [3/3]

SmartSwitch::TYPIFY ( STATE_SWITCH_STATE  )
private

Cached value of what's stored in State.

Member Data Documentation

◆ _allowSwitchingOverride

bool SmartSwitch::_allowSwitchingOverride = false
private

Override of switch lock, necessary to restore state at startup.

◆ _callbackOnIntensityChange

callback_on_intensity_change_t SmartSwitch::_callbackOnIntensityChange
private

Callback to be called when switch state changes unexpectedly, so anything but set().

◆ _intendedState

uint8_t SmartSwitch::_intendedState
private

Intended switch state by the user, as percentage.

◆ _safeSwitch

SafeSwitch SmartSwitch::_safeSwitch
private

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