Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::control::CommandMapper Class Reference

#include <command_mapper.hpp>

Public Member Functions

 CommandMapper (Drivers *drivers)
 
mockable ~CommandMapper ()=default
 
mockable void handleKeyStateChange (uint16_t key, tap::communication::serial::Remote::SwitchState leftSwitch, tap::communication::serial::Remote::SwitchState rightSwitch, bool mouseL, bool mouseR)
 
mockable void addMap (CommandMapping *mapping)
 
mockable std::size_t getSize () const
 
mockable const CommandMappinggetAtIndex (std::size_t index) const
 

Detailed Description

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);
control::CommandMapper commandMapper
Definition drivers.hpp:135
mockable void addMap(CommandMapping *mapping)
Definition command_mapper.cpp:67
Definition hold_command_mapping.hpp:45
Definition remote_map_state.hpp:56
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.

Constructor & Destructor Documentation

◆ CommandMapper()

tap::control::CommandMapper::CommandMapper ( Drivers drivers)
inlineexplicit

◆ ~CommandMapper()

mockable tap::control::CommandMapper::~CommandMapper ( )
default

Member Function Documentation

◆ addMap()

void tap::control::CommandMapper::addMap ( CommandMapping mapping)

Verifies the mapping passed in can be added to commandsToRun and if possible adds the mapping.

Parameters
[in]mappingA pointer to the CommandMapping to be added. The command mapper is not responsible for memory deallocation of this command mapping.

◆ getAtIndex()

const CommandMapping * tap::control::CommandMapper::getAtIndex ( std::size_t  index) const
Returns
The CommandMapping located at the specificed index, or nullptr of the index is out of bounds.

◆ getSize()

mockable std::size_t tap::control::CommandMapper::getSize ( ) const
inline
Returns
the number of command mappings in the mapper.

◆ handleKeyStateChange()

void tap::control::CommandMapper::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.


The documentation for this class was generated from the following files: