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 NerfUS

Revision:
32:50b777bab5a4
Parent:
30:412a779cf607
Child:
34:85994e0501fb
--- a/source/TargetManager.cpp	Mon Mar 27 19:10:07 2017 -0400
+++ b/source/TargetManager.cpp	Mon Mar 27 20:39:08 2017 -0400
@@ -5,16 +5,51 @@
 	targets(targets),
 	nerfus_ticker(nerfus_ticker)
 {
+	for(int i=0; i<targets.size(); i++)
+	{
+		is_active_target.push_back(false);
+	}
+}
 
+void TargetManager::execute(const std::vector<TargetInfo> sequence)
+{
+	for(int i=0; i<sequence.size(); i++)
+	{
+		const TargetInfo& target_info = sequence[i];
+		TargetInterface& target = *(targets[target_info.id]);
+
+		if(target_info.type == TARGET_TYPE_ALLY)
+		{
+			target.ally_command();
+		}
+		else
+		{
+			target.enemy_command();
+		}
+
+		is_active_target[target_info.id] = true;
+
+		nerfus_ticker.start(target_info.timeout_ms);
+	}
 }
 
 void TargetManager::target_hit(int target_number)
 {
-
+	if(is_active_target[target_number])
+	{
+		targets[target_number]->hit(nerfus_ticker.get_time_ms());
+		nerfus_ticker.stop();
+		is_active_target[target_number] = false;
+	}
 }
 
 void TargetManager::target_missed(int target_number)
 {
-
+	if(is_active_target[target_number])
+	{
+		targets[target_number]->timeout(nerfus_ticker.get_time_ms());
+		nerfus_ticker.stop();
+		is_active_target[target_number] = false;
+	}
 }