Class CommandMapper
Defined in File command_mapper.hpp
Class Documentation
-
class CommandMapper
Class that controls mapping remote state to actions. All the remote mappings will be handled here. One passes a RemoteMapState and a set of
Commands for which the RemoteMapState is mapped to aCommandMappingsub-object. Once a command mapping is created, pass this command mapping to theCommandMapper’saddMapfunction. This will register the mapping such that theCommandMapping’sexecuteCommandMappingfunction will be called each time new remote information is received.For example, given the command
coolCommand, to map a hold mapping to the left switch in the up position, we define aHoldCommandMappingand then add it to theCommandMapperas follows (wheredriversis assumed to be a global drivers object that has aCommandMapperobject):HoldCommandMapping leftSwitchUp( drivers, {&coolCommand}, RemoteMapState(Remote::Switch::LEFT_SWITCH, Remote::SwitchState::UP)); drivers->commandMapper.addMap(&leftSwitchUp);
Note
Only unique RemoteMapStates can be added to the CommandMapper. This ensures a user will not accidently map two
Commands to the same RemoteMapState without knowing they did so. Instead, the user must explicitly addCommands to a common vector that maps to a single RemoteMapState.Public Functions
-
inline explicit CommandMapper(Drivers *drivers)
-
~CommandMapper() = default
-
void handleKeyStateChange(uint16_t key, tap::communication::serial::Remote::SwitchState leftSwitch, tap::communication::serial::Remote::SwitchState rightSwitch, bool mouseL, bool mouseR)
The heart of the CommandMapper.
Iterates through all the current mappings to see which buttons are pressed in order to determine which commands should be added to or removed from the scheduler. Call when new remote information has been received.
-
void addMap(CommandMapping *mapping)
Verifies the mapping passed in can be added to
commandsToRunand if possible adds the mapping.- Parameters:
mapping – [in] A pointer to the CommandMapping to be added. The command mapper is not responsible for memory deallocation of this command mapping.
-
inline std::size_t getSize() const
- Returns:
the number of command mappings in the mapper.
-
const CommandMapping *getAtIndex(std::size_t index) const
- Returns:
The CommandMapping located at the specificed index, or
nullptrof the index is out of bounds.
-
inline explicit CommandMapper(Drivers *drivers)