Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_SmartSwitch.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Jan 28, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
9#include <common/cs_Types.h>
12
20class SmartSwitch : public EventListener {
21public:
22 void init(const boards_config_t& board);
23
29 void start();
30
40 cs_ret_code_t set(uint8_t intensity);
41
48
55
60
64 typedef function<void(uint8_t newIntensity)> callback_on_intensity_change_t;
65
70
74 void handleEvent(event_t& evt) override;
75
76private:
78
83
88
93
97 TYPIFY(CONFIG_DIMMING_ALLOWED) _allowDimming = false;
98
102 TYPIFY(CONFIG_SWITCH_LOCKED) _switchLocked = false;
103
108
113
118
124
130
136
141 cs_ret_code_t setDimmer(uint8_t intensity, bool fade = true);
142
147 cs_ret_code_t setDimmerUnchecked(uint8_t intensity, bool fade);
148
153
159 void sendUnexpectedIntensityUpdate(uint8_t newIntensity);
160
165 void store(switch_state_t newState);
166
172
178
180
182
184};
Event listener.
Definition: cs_EventListener.h:17
Class that takes care of safety of switch.
Definition: cs_SafeSwitch.h:21
Class that:
Definition: cs_SmartSwitch.h:20
void start()
Start switch.
cs_ret_code_t handleCommandSetRelay(bool on)
cs_ret_code_t handleCommandSetDimmer(uint8_t intensity)
TYPIFY(CONFIG_DIMMING_ALLOWED) _allowDimming
Cached value of what's stored in State.
cs_ret_code_t set(uint8_t intensity)
Set intended intensity.
function< void(uint8_t newIntensity)> callback_on_intensity_change_t
Callback function definition.
Definition: cs_SmartSwitch.h:64
TYPIFY(CONFIG_SWITCH_LOCKED) _switchLocked
Cached value of what's stored in State.
cs_ret_code_t resolveIntendedState()
From set intended state, try to set the relay and/or dimmer to correct values.
uint8_t getIntensityFromSwitchState(switch_state_t switchState)
Get intensity from a switch state.
bool _allowSwitchingOverride
Override of switch lock, necessary to restore state at startup.
Definition: cs_SmartSwitch.h:107
uint8_t getCurrentIntensity()
Get current switch intensity.
cs_ret_code_t setSwitchLock(bool lock)
Set switch lock.
void store(switch_state_t newState)
Store switch state to State class.
cs_ret_code_t setDimmerUnchecked(uint8_t intensity, bool fade)
Set dimmer without checks.
cs_ret_code_t setAllowDimming(bool allowed)
Set allow dimming.
TYPIFY(STATE_SWITCH_STATE) _storedState
Cached value of what's stored in State.
void handleAllowDimmingSet()
cs_ret_code_t setDimmer(uint8_t intensity, bool fade=true)
Set dimmer.
cs_ret_code_t setRelay(bool on)
Set relay.
bool allowSwitching()
Whether switch state is allowed to be changed.
void sendUnexpectedIntensityUpdate(uint8_t newIntensity)
Send intensity update to listeners.
callback_on_intensity_change_t _callbackOnIntensityChange
Callback to be called when switch state changes unexpectedly, so anything but set().
Definition: cs_SmartSwitch.h:87
uint8_t _intendedState
Intended switch state by the user, as percentage.
Definition: cs_SmartSwitch.h:82
void handleEvent(event_t &evt) override
Handle events.
void init(const boards_config_t &board)
void handleUnexpectedStateChange(switch_state_t newState)
Handle unexpected state change by safeSwitch.
void onUnexpextedIntensityChange(const callback_on_intensity_change_t &closure)
Register a callback function that's called when state changes unexpectedly.
cs_ret_code_t setRelayUnchecked(bool on)
Set relay without checks.
SafeSwitch _safeSwitch
Definition: cs_SmartSwitch.h:77
switch_state_t getActualState()
Get actual switch state.
uint8_t getIntendedState()
Get the intended switch state.
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
@ CONFIG_DIMMING_ALLOWED
@ CONFIG_SWITCH_LOCKED
@ STATE_SWITCH_STATE
Board configuration.
Definition: cs_Boards.h:169
Switch state: combination of relay and dimmer state.
Definition: cs_Packets.h:219