NerfUS mobile node that manages a target for the Nerf gun firing range
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
source/Target.cpp
- Committer:
- Maxime Dupuis
- Date:
- 2017-03-08
- Revision:
- 20:05e2c4941285
- Parent:
- 19:377887760869
- Child:
- 22:d9df16225df3
File content as of revision 20:05e2c4941285:
#include "Target.hpp" Target::Target(ServomotorInterface& servomotor, LedControllerInterface& led_controller, XbeeTransmitterInterface& xbee_transmitter): servomotor(servomotor), led_controller(led_controller), xbee_transmitter(xbee_transmitter) { } void Target::execute_command(Mode mode, int timeout_ms) { if(mode == Ally) { ally_command(); } else { enemy_command(); } } void Target::ally_command() { servomotor.set_position_up(); } void Target::enemy_command() { led_controller.turn_on(); servomotor.set_position_up(); } std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms) const { const uint8_t target_number_and_result = (target_number << 3) + result; const uint8_t time_taken_msb = time_taken_ms >> 8; const uint8_t time_taken_lsb = (time_taken_ms << 8) >> 8; std::vector<uint8_t> message; message.push_back(target_number_and_result); message.push_back(time_taken_msb); message.push_back(time_taken_lsb); return message; }