ArmorLinkModule
ArmorLinkModule describes a module in an ArmorLink network.
It defines the module name, module type and the functionality exposed through ArmorLink.
For the conceptual overview, see Modules.
Basic Usage
Every ArmorLink sketch starts by creating an ArmorLinkModule instance.
ArmorLinkModule module(
"Helmet",
ArmorLinkModuleType::Helmet
);
The module is then passed to the ArmorLink runtime.
ArmorLinkOptions options;
options.enableEspNow = true;
ArmorLink.begin(module, options);
For more information about runtime initialization, see ArmorLink Runtime.
Constructor
ArmorLinkModule module(
"Module Name",
ArmorLinkModuleType::Generic
);
The constructor defines:
- Module name
- Module type
Module Name
The module name identifies the module inside the ArmorLink network.
Example:
ArmorLinkModule module("Helmet", ArmorLinkModuleType::Helmet);
The name is used when sending Commands.
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
Module names should be unique within an ArmorLink network.
For more information about command routing, see Commands.
Module Type
The module type describes what kind of module this is.
Example:
ArmorLinkModule module("Helmet", ArmorLinkModuleType::Helmet);
Module types are descriptive only.
They do not affect communication, routing or behavior.
Their primary purpose is to help identify and organize modules within the ArmorLink App.
Common Module Types
ArmorLink provides predefined module types for common use cases.
Examples include:
ArmorLinkModuleType::GenericArmorLinkModuleType::HelmetArmorLinkModuleType::ChestArmorLinkModuleType::BackArmorLinkModuleType::ArmArmorLinkModuleType::HandArmorLinkModuleType::Leg
Use Generic when no specific type matches your module.
Exposed Functionality
A module can expose functionality through:
- Actions
- Configuration
- Telemetry
These APIs are accessed through the module instance.
module.actions();
module.config();
actions()
actions() returns the module's Action collection.
Actions define functionality that can be executed through ArmorLink.
Example:
module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});
For more information, see Actions and Actions API.
config()
config() returns the module's Configuration collection.
Configuration values are persistent module settings that can be viewed and modified through the ArmorLink App.
Example:
module.config()
.addInt("volume", &volume, 20)
.label("Volume")
.range(0, 30)
.step(1)
.onIntChange([](int value)
{
dfplayer.volume(value);
});
For more information, see Configuration and Configuration API.
Gateway Modules
A module can also act as the Gateway.
This is controlled through ArmorLinkOptions, not through the module type.
Example:
ArmorLinkModule module("Chest", ArmorLinkModuleType::Chest);
ArmorLinkOptions options;
options.enableGateway = true;
ArmorLink.begin(module, options);
The Gateway is a role, not a dedicated device type.
For more information, see Gateway.
Single Module Projects
In a single module project, the module itself can act as the Gateway.
Example:
ArmorLinkModule module("Arc Reactor", ArmorLinkModuleType::Generic);
ArmorLinkOptions options;
options.enableGateway = true;
options.enableEspNow = false;
options.enableBle = true;
ArmorLink.begin(module, options);
ESP-NOW is not required when there are no additional modules to communicate with.
Complete Example
#include <ArmorLink.h>
ArmorLinkModule module("Helmet", ArmorLinkModuleType::Helmet);
ArmorLinkRuntime ArmorLink;
int volume = 20;
void setup()
{
Serial.begin(115200);
module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});
module.config()
.addInt("volume", &volume, 20)
.label("Volume")
.range(0, 30)
.step(1);
ArmorLinkOptions options;
options.enableEspNow = true;
ArmorLink.begin(module, options);
}
void loop()
{
ArmorLink.loop();
}
Summary
ArmorLinkModule defines a module inside an ArmorLink network.
A module has:
- A name
- A type
- Actions
- Configuration
- Telemetry
The module name is used for command routing.
The module type is descriptive and used mainly by the ArmorLink App.
Gateway behavior is enabled through ArmorLinkOptions.