Class CommandMapper

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 a CommandMapping sub-object. Once a command mapping is created, pass this command mapping to the CommandMapper’s addMap function. This will register the mapping such that the CommandMapping’s executeCommandMapping 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 a HoldCommandMapping and then add it to the CommandMapper as follows (where drivers is assumed to be a global drivers object that has a CommandMapper 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 Commands to the same RemoteMapState without knowing they did so. Instead, the user must explicitly add Commands 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.