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
Command
s for which the RemoteMapState is mapped to aCommandMapping
sub-object. Once a command mapping is created, pass this command mapping to theCommandMapper
’saddMap
function. This will register the mapping such that theCommandMapping
’sexecuteCommandMapping
function 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 aHoldCommandMapping
and then add it to theCommandMapper
as follows (wheredrivers
is assumed to be a global drivers object that has aCommandMapper
object):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
Command
s to the same RemoteMapState without knowing they did so. Instead, the user must explicitly addCommand
s 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
commandsToRun
and 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
nullptr
of the index is out of bounds.
-
inline explicit CommandMapper(Drivers *drivers)