Actions
Actions are the primary way functionality is exposed through ArmorLink.
A module can expose one or more Actions that can be executed through the ArmorLink network.
Examples include:
- Open Helmet
- Close Helmet
- Toggle Faceplate
- Fire Missile
- Play Sound
Actions are automatically discovered by the ArmorLink App and presented to the user.
For more information about Modules, see Modules.
What is an Action?
An Action represents functionality that can be executed remotely.
Actions are not user interface elements.
Actions are not buttons.
Actions are not local events.
An Action defines how a module responds when a matching command is received.
Creating an Action
Actions are created using the module's action collection.
Example:
module.actions()
.add("openHelmet")
.label("Open Helmet")
.command("Facemask", "open")
.onExecute([]{
openFaceplate();
});
In this example:
openHelmetis the internal action identifierOpen Helmetis the user-visible labelFacemask/openis the command that triggers the actiononExecute()defines what happens when the action is executed
Actions and Commands
Actions and Commands are closely related, but they are not the same thing.
A Command is a message sent through the ArmorLink network.
An Action defines how a module reacts to a Command.
Incoming Command
?
?
Matching Action
?
?
onExecute()
For more information about Commands, see Commands.
The onExecute Callback
The onExecute() callback contains the code that should run when the Action is triggered.
Example:
module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});
When a matching command is received, ArmorLink automatically invokes the callback.
Actions in the ArmorLink App
Actions are automatically exposed to the ArmorLink App.
The App can discover available Actions and present them to the user without requiring custom user interface code.
Example:
module.actions()
.add("openHelmet")
.label("Open Helmet");
This Action automatically becomes available inside the ArmorLink App.
The App displays the Action label and allows the user to execute it remotely.
Actions vs Application Logic
A common misconception is that Actions and local events are the same thing.
They are not.
Consider the following example:
void btn1_handleClick()
{
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}
This is not an Action.
This is application logic.
A local button press causes a Command to be sent through the ArmorLink network.
The receiving module may then execute an Action.
Button Press
?
?
sendCommand(...)
?
?
Gateway
?
?
Target Module
?
?
Matching Action
?
?
onExecute()
For more information about command routing, see Gateway.
Multiple Actions
A module can expose any number of Actions.
Example:
module.actions()
.add("openHelmet")
.label("Open Helmet");
module.actions()
.add("closeHelmet")
.label("Close Helmet");
module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate");
Each Action can respond to a different command and perform different functionality.
Summary
Actions are the primary mechanism used to expose functionality through ArmorLink.
An Action:
- Represents functionality
- Can be discovered by the ArmorLink App
- Is triggered by incoming Commands
- Executes code through
onExecute()
Actions are not local events.
They define how a module reacts to Commands received through the ArmorLink network.