SensESP 2.7.2
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... | |
Protected Attributes | |
bool | is_on = false |
bool | auto_initialize_ |
std::set< SyncPath > | sync_paths |
Protected Attributes inherited from sensesp::Configurable | |
String | description_ = "" |
int | sort_order_ = 1000 |
Protected Attributes inherited from sensesp::ValueProducer< T > | |
T | output |
Additional Inherited Members | |
Static Public Member Functions inherited from sensesp::TransformBase | |
static const std::set< TransformBase * > & | get_transforms () |
Static Public Member Functions inherited from sensesp::Startable | |
static void | start_all () |
Public Attributes inherited from sensesp::Configurable | |
const String | config_path_ |
Protected Member Functions inherited from sensesp::Configurable | |
virtual void | load_configuration () |
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 43 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 7 of file smart_switch_controller.cpp.
|
overridevirtual |
Returns a configuration schema that specifies the key/value pairs that can be expected when calling get_configuration(), or are expected by set_configuration(). The schema will be in JSON Schema format
Reimplemented from sensesp::Configurable.
Definition at line 90 of file smart_switch_controller.cpp.
|
overridevirtual |
Returns the current configuration data as a JsonObject. In general, the current state of local member variables are saved to a new object created with JsonDocument::as<JsonObject>() and returned.
Reimplemented from sensesp::Configurable.
Definition at line 73 of file smart_switch_controller.cpp.
|
overridevirtual |
Sets the current state of local member variables using the data stored in config.
Reimplemented from sensesp::Configurable.
Definition at line 92 of file smart_switch_controller.cpp.
|
override |
Definition at line 30 of file smart_switch_controller.cpp.
|
overridevirtual |
Used to set an input of this consumer. It is usually called automatically by a ValueProducer.
new_value | the value of the input |
input_channel | Consumers can have one or more inputs feeding them. This parameter allows you to specify which input number the producer is connecting to. For single input consumers, leave the index at zero. |
Reimplemented from sensesp::ValueConsumer< ClickTypes >.
Definition at line 35 of file smart_switch_controller.cpp.
|
overridevirtual |
Used to set an input of this consumer. It is usually called automatically by a ValueProducer.
new_value | the value of the input |
input_channel | Consumers can have one or more inputs feeding them. This parameter allows you to specify which input number the producer is connecting to. For single input consumers, leave the index at zero. |
Reimplemented from sensesp::ValueConsumer< String >.
Definition at line 61 of file smart_switch_controller.cpp.
|
overridevirtual |
Called during the initialization process. Override this method to add runtime initialization code to your class
Reimplemented from sensesp::Startable.
Definition at line 24 of file smart_switch_controller.cpp.
|
protected |
Definition at line 91 of file smart_switch_controller.h.
Definition at line 90 of file smart_switch_controller.h.
|
protected |
Definition at line 92 of file smart_switch_controller.h.