SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
|
A high level transform designed to control a digital output (such as a relay) via manual button presses or programatic commands. More...
#include <sensesp/controllers/smart_switch_controller.h>
Classes | |
class | SyncPath |
Used to store configuration internally. More... | |
Public Member Functions | |
SmartSwitchController (bool auto_initialize=true, String config_path="", const char *sk_sync_paths[]=NULL) | |
virtual bool | to_json (JsonObject &doc) override |
virtual bool | from_json (const JsonObject &config) override |
Public Member Functions inherited from sensesp::ValueProducer< bool > | |
ValueProducer () | |
ValueProducer (const bool &initial_value) | |
virtual const bool & | get () const |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< bool, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type | connect_to (std::shared_ptr< VConsumer > consumer) |
Connect a producer to a transform with a different input type. | |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< bool, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer *consumer) |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< bool, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer &consumer) |
void | emit (const bool &new_value) |
Public Member Functions inherited from sensesp::Observable | |
Observable () | |
Observable (Observable &&other) | |
Move constructor. | |
void | notify () |
void | attach (std::function< void()> observer) |
Public Attributes | |
LambdaConsumer< ClickTypes > | click_consumer_ |
LambdaConsumer< String > | truthy_string_consumer_ |
LambdaConsumer< bool > | swich_consumer_ |
Protected Attributes | |
bool | is_on_ = false |
bool | auto_initialize_ |
std::set< SyncPath > | sync_paths_ |
Protected Attributes inherited from sensesp::ValueProducer< bool > | |
bool | output_ |
A high level transform designed to control a digital output (such as a relay) via manual button presses or programatic commands.
To accomplish this, the controller accepts inputs from a generic boolean producer (usually a SignalK listener), as well as String and ClickType inputs. The latter allows a physical button to control the load as well as add special behaviors to the sensor application. In particular, a double click can be configured to set the state of multiple signal k paths, and an ultra long press of the button will cause the MCU to reboot.
A SmartSwitchController object behaves differently depending on the type of input it receives. If the input is a boolean or a "valid truth type" (which is a specialized type of boolean - see below), SmartSwitchController's output will be "on" if the input is "true", or "off" if the input is "false". If the input is a ClickType, or a String that's NOT a "valid truth type", SmartSwitchController's output will simply toggle the output back and forth between "on" and "off" with each input. There are two exceptions to this if the input is a ClickType:
Incoming String values are evaluated to see if they represent a "valid truth type". Examples include "on", "ON", "off", "true", "false", "one", "1", "123" (or any other string that represents a non-zero value), etc. Case is insensitive. Any incoming String that doesn't evaluate to a "valid truth type" will be treated as a "single click", and will toggle the output btween "on" and "off".
Definition at line 46 of file smart_switch_controller.h.
sensesp::SmartSwitchController::SmartSwitchController | ( | bool | auto_initialize = true, |
String | config_path = "", | ||
const char * | sk_sync_paths[] = NULL ) |
The constructor
auto_initialize | If TRUE, the controller will emit an initial "off" status when enabled. This is generally the desired case unless this controller is mirroring the state of a remote load. |
config_path | The path to save configuration data (blank for no saving) |
sk_sync_paths | An optional array of Signal K paths that should synchronize their status whenever a double click ClickType is received. Each path listed will have a PUT request issued to set the status to be the same as this SmartSwitchController each time a double click occurs. This list, if specified, should have a zero length string as its last entry. |
Definition at line 8 of file smart_switch_controller.cpp.
|
overridevirtual |
Deserializes the current object data from a JsonObject.
Reimplemented from sensesp::Serializable.
Definition at line 38 of file smart_switch_controller.cpp.
|
overridevirtual |
Serializes the current object data into a JsonObject.
Reimplemented from sensesp::Serializable.
Definition at line 30 of file smart_switch_controller.cpp.
|
protected |
Definition at line 129 of file smart_switch_controller.h.
LambdaConsumer<ClickTypes> sensesp::SmartSwitchController::click_consumer_ |
Definition at line 71 of file smart_switch_controller.h.
|
protected |
Definition at line 128 of file smart_switch_controller.h.
LambdaConsumer<bool> sensesp::SmartSwitchController::swich_consumer_ |
Definition at line 108 of file smart_switch_controller.h.
|
protected |
Definition at line 130 of file smart_switch_controller.h.
LambdaConsumer<String> sensesp::SmartSwitchController::truthy_string_consumer_ |
Definition at line 96 of file smart_switch_controller.h.