LoomManager class
Manager to contain Loom modules and provide users with a simpler API.
Contents
Public types
- enum DeviceType { HUB, NODE, REPEATER }
- Different general types of devices.
Protected variables
- char device_name
- The name of the device.
- uint8_t instance
- The instance / channel ID within the subnet.
- uint16_t interval
- Default value for pause() Used so that manager can control interval, rather than code in .ino.
- DeviceType device_type
- Device type (Hub / Node)
- std::vector<LoomModule*> modules
- Vectors of LoomModule pointers.
- Verbosity print_verbosity
- Print detail verbosity.
- Verbosity package_verbosity
- Package detail verbosity.
- StaticJsonDocument<2000> doc
- Json data.
- uint packet_number
- Packet number, incremented each time package is called.
CONSTRUCTORS / DESTRUCTOR
-
LoomManager(const FactoryBase* factory_ptr,
const char* device_name = "Device",
const uint8_t instance = 1,
const DeviceType device_type = DeviceType::
NODE, const Verbosity print_verbosity = Verbosity:: V_HIGH, const Verbosity package_verbosity = Verbosity:: V_LOW, const uint16_t interval = 1000) - Loom Manager constructor.
OPERATION
- void begin_LED() const
- Begin LED.
- void begin_serial(const bool wait_for_monitor = false) const
- Begin Serial, optionally wait for user.
- auto parse_config(const char* json_config) -> bool
- Parse a JSON configuration string specifying enabled modules.
- auto parse_config_SD(const char* config_file) -> bool
- Parse a JSON configuration on SD card specifying enabled modules.
- auto parse_config_json(JsonObject config) -> bool
- Parse a JSON configuration object specifying enabled modules.
- void get_config()
- Get complete configuration of the device.
- void measure()
- Measure data of all managed sensors.
- void package(JsonObject json)
- Package data of all modules into provide JsonObject.
- void record()
- Measure and package data.
- auto package() -> JsonObject
- Package data of all modules into JsonObject and return.
- auto publish_all(const JsonObject json) -> bool
- Publish.
- auto publish_all() -> bool
- Publish.
- auto log_all(const JsonObject json) -> bool
- Log.
- auto log_all() -> bool
- Log.
- void dispatch(JsonObject json)
- Iterate over list of commands, forwarding to handling module.
- void dispatch()
- Iterate over list of commands, forwarding to handling module.
- void pause(const uint16_t ms) const
- Delay milliseconds.
- void pause() const
- Delay milliseconds based on interval member.
- void power_up()
- Iterate over modules, calling power up method.
- void power_down()
- Iterate over modules, calling power down method.
-
template<typename T>auto add_data(const char* module, const char* key, const T val) -> bool
- Append to a Json object of data.
-
template<typename T>auto get_data_as(const char* module, const char* key) -> T
- Get a data value from Json object of data.
-
auto has_module(const LoomModule::
Type type) const -> bool - Save current configuration to SD.
PRINT INFORMATION
- void print_config(const bool print_modules_config = false)
- Print the devices current configuration.
- void list_modules() const
- Print the linked modules.
- void display_data() const
- Print out the internal JSON object.
ADD MODULE TO MANAGER
- void add_module(LoomModule* module)
- Add a module to be managed.
GETTERS
- auto get_device_type() const -> DeviceType
- Get device type.
- auto internal_json(const bool clear = false) -> JsonObject
- Return reference to internal json object.
- void get_device_name(char* buf) const
- Get the device name, copies into provided buffer.
- auto get_device_name() const -> const char*
- Get the device name.
- auto get_instance_num() const -> uint8_t
- Get device instance number.
- auto get_print_verbosity() const -> Verbosity
- Get print verbosity.
- auto get_package_verbosity() const -> Verbosity
- Get package verbosity.
- auto get_interval() const -> uint16_t
- Get sampling interval.
SETTERS
- void set_device_name(const char* device_name)
- Set the device name.
- void set_instance_num(const uint8_t n)
- Set device instance number.
- void set_print_verbosity(const Verbosity v, const bool set_modules = false)
- Set print verbosity.
- void set_package_verbosity(const Verbosity v, const bool set_modules = false)
- Set package verbosity.
- void set_interval(const uint16_t ms)
- Set default time to use for .pause() \ .delay().
MISCELLANEOUS
- void flash_LED(const uint8_t count, const uint8_t time_high, const uint8_t time_low, const bool end_high = false) const
- Flash the built in LED.
- static auto enum_device_type_string(const DeviceType t) -> const char*
- Get c-string of name associated with device type enum.
MODULE ACCESS
-
auto find_module(const LoomModule::
Type type, const uint8_t idx = 0) const -> LoomModule* - Auxiliary function to search a list of modules for a module of specified type.
-
auto find_module_by_category(const LoomModule::
Category category, const uint8_t idx) const -> LoomModule* - Auxiliary function to search a list of modules for a module of specified category.
- void print_device_label() const protected
- Print the device name as '[device_name]'.
Enum documentation
enum LoomManager:: DeviceType
Different general types of devices.
Enumerators | |
---|---|
HUB |
Central device. |
NODE |
Data collecting / actuating node. |
REPEATER |
Forwards messages between other devices. |
Function documentation
LoomManager:: LoomManager(const FactoryBase* factory_ptr,
const char* device_name = "Device",
const uint8_t instance = 1,
const DeviceType device_type = DeviceType:: NODE,
const Verbosity print_verbosity = Verbosity:: V_HIGH,
const Verbosity package_verbosity = Verbosity:: V_LOW,
const uint16_t interval = 1000)
Loom Manager constructor.
Parameters | |
---|---|
factory_ptr | |
device_name in | String | <"Default"> | null | Manager name |
instance in | Int | <1> | [0-99] | Device instance number on its subnet |
device_type in | Set(DeviceType) | <1> | {0("Hub"), 1("Node"), 2("Repeater")} | Device's topological type |
print_verbosity in | Set(Verbosity) | <1> | {0("Off"), 1("Low"), 2("High")} | How detailed prints to the Serial Monitor should be |
package_verbosity in | Set(Verbosity) | <2> | {0("Off"), 1("Low"), 2("High")} | How detailed to package data |
interval in | Int | <1> | [0-60000] | Default milliseconds to pause |
void LoomManager:: begin_serial(const bool wait_for_monitor = false) const
Begin Serial, optionally wait for user.
Parameters | |
---|---|
wait_for_monitor in | True to wait for serial monitor to open |
bool LoomManager:: parse_config(const char* json_config)
Parse a JSON configuration string specifying enabled modules.
Parameters | |
---|---|
json_config in | Configuration |
Returns | True if success |
Enabled modules are instantiated with specified settings and added to manager lists for managing
bool LoomManager:: parse_config_SD(const char* config_file)
Parse a JSON configuration on SD card specifying enabled modules.
Returns | True if success |
---|
Enabled modules are instantiated with specified settings and added to manager lists for managing. Json should be on a single line in a .txt file.
bool LoomManager:: parse_config_json(JsonObject config)
Parse a JSON configuration object specifying enabled modules.
Returns | True if success |
---|
Enabled modules are instantiated with specified settings and added to manager lists for managing. Called by parse_config and parse_config_SD
void LoomManager:: get_config()
Get complete configuration of the device.
Generally used to save configuration to SD
void LoomManager:: package(JsonObject json)
Package data of all modules into provide JsonObject.
Parameters | |
---|---|
json out | JsonObject of packaged data of enabled modules |
How detailed data is can be modified with package_verbosity
void LoomManager:: record()
Measure and package data.
Convenience function, current just calls measure then package
JsonObject LoomManager:: package()
Package data of all modules into JsonObject and return.
Returns | JsonObject of packaged data of enabled modules |
---|
bool LoomManager:: publish_all(const JsonObject json)
Publish.
Parameters | |
---|---|
json in | Data object to publish |
Returns | True if success |
bool LoomManager:: publish_all()
Publish.
Returns | True if success |
---|
Calls publish_
bool LoomManager:: log_all(const JsonObject json)
Log.
Parameters | |
---|---|
json in | Data object to log |
Returns | True if success |
bool LoomManager:: log_all()
Log.
Returns | True if success |
---|
Calls log_
void LoomManager:: dispatch(JsonObject json)
Iterate over list of commands, forwarding to handling module.
Parameters | |
---|---|
json in | Object containing commands |
void LoomManager:: dispatch()
Iterate over list of commands, forwarding to handling module.
Uses internal json
void LoomManager:: pause() const
Delay milliseconds based on interval member.
Uses interval member as value
template<typename T>
bool LoomManager:: add_data(const char* module,
const char* key,
const T val)
Append to a Json object of data.
Parameters | |
---|---|
module in | Which module to add data to (will create if it doesn't exist) |
key in | Key of data to add |
val in | Value of data to add |
Returns | True if success |
If object is non-empty and contains non-data, will not add and will return false. Only call this after package, otherwise the data will be overriden
template<typename T>
T LoomManager:: get_data_as(const char* module,
const char* key)
Get a data value from Json object of data.
Parameters | |
---|---|
module in | LoomModule key is associated with |
key in | Key of data value to find |
Returns | Data value if found |
bool LoomManager:: has_module(const LoomModule:: Type type) const
Save current configuration to SD.
Parameters | |
---|---|
type in | Module type to check for |
Returns | True is success, false if fail or file not found Determine if the manager has a module of the specified type |
void LoomManager:: print_config(const bool print_modules_config = false)
Print the devices current configuration.
Lists modules. Optionally also prints configuration of linked modules.
JsonObject LoomManager:: internal_json(const bool clear = false)
Return reference to internal json object.
Parameters | |
---|---|
clear in | Whether or not to empty Json before returning it |
Returns | Reference to internal json object |
void LoomManager:: get_device_name(char* buf) const
Get the device name, copies into provided buffer.
Parameters | |
---|---|
buf out | The buffer copy device name into |
const char* LoomManager:: get_device_name() const
Get the device name.
Returns | String literal of device name. |
---|
Verbosity LoomManager:: get_package_verbosity() const
Get package verbosity.
Returns | package verbosity |
---|
void LoomManager:: set_device_name(const char* device_name)
Set the device name.
Parameters | |
---|---|
device_name in | The new device name |
void LoomManager:: set_instance_num(const uint8_t n)
Set device instance number.
Parameters | |
---|---|
n in | New instance number |
void LoomManager:: set_print_verbosity(const Verbosity v,
const bool set_modules = false)
Set print verbosity.
Parameters | |
---|---|
v in | New print verbosity |
set_modules in | Whether or not to also apply setting to modules |
void LoomManager:: set_package_verbosity(const Verbosity v,
const bool set_modules = false)
Set package verbosity.
Parameters | |
---|---|
v in | New package verbosity |
set_modules in | Whether or not to also apply setting to modules |
void LoomManager:: set_interval(const uint16_t ms)
Set default time to use for .pause() \ .delay().
Pause and delay can still take explicit times, but if not provided, this value will be used
void LoomManager:: flash_LED(const uint8_t count,
const uint8_t time_high,
const uint8_t time_low,
const bool end_high = false) const
Flash the built in LED.
Parameters | |
---|---|
count in | Number of times to flash |
time_high in | Milliseconds to stay on for |
time_low in | Milliseconds to stay off for |
end_high |
static const char* LoomManager:: enum_device_type_string(const DeviceType t)
Get c-string of name associated with device type enum.
Returns | C-string of device type |
---|
LoomModule* LoomManager:: find_module(const LoomModule:: Type type,
const uint8_t idx = 0) const
Auxiliary function to search a list of modules for a module of specified type.
Parameters | |
---|---|
type in | Type to search for |
idx |
LoomModule* LoomManager:: find_module_by_category(const LoomModule:: Category category,
const uint8_t idx) const
Auxiliary function to search a list of modules for a module of specified category.
Parameters | |
---|---|
category in | Category to search for |
idx |