SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::SmartSwitchController Class Reference

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>

Inheritance diagram for sensesp::SmartSwitchController:
[legend]

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)
 
void start () override
 
void set_input (bool new_value, uint8_t input_channel=0) override
 
void set_input (String new_value, uint8_t input_channel=0) override
 
void set_input (ClickTypes new_value, uint8_t input_channel=0) override
 
virtual void get_configuration (JsonObject &doc) override
 
virtual bool set_configuration (const JsonObject &config) override
 
virtual String get_config_schema () override
 
- Public Member Functions inherited from sensesp::SymmetricTransform< T >
 SymmetricTransform (String config_path="")
 
- Public Member Functions inherited from sensesp::Transform< T, T >
 Transform (String config_path="")
 
Transform< T, T > * connect_from (ValueProducer< T > *producer0, ValueProducer< T > *producer1=NULL, ValueProducer< T > *producer2=NULL, ValueProducer< T > *producer3=NULL, ValueProducer< T > *producer4=NULL)
 
- Public Member Functions inherited from sensesp::TransformBase
 TransformBase (String config_path="")
 
- Public Member Functions inherited from sensesp::Configurable
 Configurable (String config_path="", String description="", int sort_order=1000)
 
String get_description ()
 
void set_description (String description)
 Set the description of the Configurable.
 
int get_sort_order ()
 
void set_sort_order (int sort_order)
 
virtual void save_configuration ()
 
- Public Member Functions inherited from sensesp::Startable
 Startable (int priority=0)
 
const int get_start_priority ()
 
void set_start_priority (int priority)
 
- Public Member Functions inherited from sensesp::ValueConsumer< T >
void connect_from (ValueProducer< T > *producer, uint8_t input_channel=0)
 
- Public Member Functions inherited from sensesp::ValueProducer< T >
 ValueProducer ()
 
virtual const T & get () const
 
void connect_to (ValueConsumer< T > *consumer, uint8_t input_channel=0)
 
template<typename CT >
void connect_to (ValueConsumer< CT > *consumer, uint8_t input_channel=0)
 Connect a producer to a consumer of a different type.
 
template<typename T2 >
Transform< T, T2 > * connect_to (Transform< T, T2 > *consumer_producer, uint8_t input_channel=0)
 
template<typename TT , typename T2 >
Transform< TT, T2 > * connect_to (Transform< TT, T2 > *consumer_producer, uint8_t input_channel=0)
 Connect a producer to a transform with a different input type.
 
void emit (T new_value)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
void attach (std::function< void()> observer)
 
- Public Member Functions inherited from sensesp::ValueConsumer< ClickTypes >
void connect_from (ValueProducer< ClickTypes > *producer, uint8_t input_channel=0)
 
- Public Member Functions inherited from sensesp::ValueConsumer< String >
void connect_from (ValueProducer< String > *producer, uint8_t input_channel=0)
 

Protected Attributes

bool is_on = false
 
bool auto_initialize_
 
std::set< SyncPathsync_paths
 
- Protected Attributes inherited from sensesp::Configurable
String description_ = ""
 
int sort_order_ = 1000
 
- Protected Attributes inherited from sensesp::ValueProducer< 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 ()
 

Detailed Description

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:

  1. A value of ClickTypes::DoubleClick will toggle the output as well as send PUT requests to synchronize zero or more paths that are configured to do so
  2. A value of ClickTypes::UltraLongSingleClick will reboot the MCU.

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".

See also
TextToTruth
ClickType

Definition at line 43 of file smart_switch_controller.h.

Constructor & Destructor Documentation

◆ SmartSwitchController()

sensesp::SmartSwitchController::SmartSwitchController ( bool  auto_initialize = true,
String  config_path = "",
const char sk_sync_paths[] = NULL 
)

The constructor

Parameters
auto_initializeIf 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_pathThe path to save configuration data (blank for no saving)
sk_sync_pathsAn 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.

Here is the call graph for this function:

Member Function Documentation

◆ get_config_schema()

String sensesp::SmartSwitchController::get_config_schema ( )
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

See also
https://json-schema.org

Reimplemented from sensesp::Configurable.

Definition at line 90 of file smart_switch_controller.cpp.

◆ get_configuration()

void sensesp::SmartSwitchController::get_configuration ( JsonObject configObject)
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.

◆ set_configuration()

bool sensesp::SmartSwitchController::set_configuration ( const JsonObject config)
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.

◆ set_input() [1/3]

void sensesp::SmartSwitchController::set_input ( bool  new_value,
uint8_t  input_channel = 0 
)
override

Definition at line 30 of file smart_switch_controller.cpp.

Here is the call graph for this function:

◆ set_input() [2/3]

void sensesp::SmartSwitchController::set_input ( ClickTypes  new_value,
uint8_t  input_channel = 0 
)
overridevirtual

Used to set an input of this consumer. It is usually called automatically by a ValueProducer.

Parameters
new_valuethe value of the input
input_channelConsumers 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.

Here is the call graph for this function:

◆ set_input() [3/3]

void sensesp::SmartSwitchController::set_input ( String  new_value,
uint8_t  input_channel = 0 
)
overridevirtual

Used to set an input of this consumer. It is usually called automatically by a ValueProducer.

Parameters
new_valuethe value of the input
input_channelConsumers 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.

Here is the call graph for this function:

◆ start()

void sensesp::SmartSwitchController::start ( )
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.

Here is the call graph for this function:

Member Data Documentation

◆ auto_initialize_

bool sensesp::SmartSwitchController::auto_initialize_
protected

Definition at line 91 of file smart_switch_controller.h.

◆ is_on

bool sensesp::SmartSwitchController::is_on = false
protected

Definition at line 90 of file smart_switch_controller.h.

◆ sync_paths

std::set<SyncPath> sensesp::SmartSwitchController::sync_paths
protected

Definition at line 92 of file smart_switch_controller.h.


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