/// <summary> /// propagates device commands to task events /// </summary> /// <param name="command"></param> public void ControlDeviceCommand(string command) { //Debug.WriteLine("TaskDispatcher: ControlDeviceCommand: " + command); ControlDeviceEventArgs args = new ControlDeviceEventArgs() { command = command }; foreach (var task in tasks) { task.OnControlDeviceCommand(args); } }
/// <summary> /// interprets the command from control device (i.e. a joystick) /// see ...\ControlDevices\RumblePad2.cs /// </summary> /// <param name="command"></param> void Behavior_controlDeviceEvent(object sender, ControlDeviceEventArgs e) { string command = e.command; double speed = 0.0d; double turn = 0.0d; switch (command) { case "button2": fullAuto = true; break; case "button3": fullAuto = false; break; default: if (command.StartsWith("speed|")) { string[] split = command.Split(new char[] { '|' }); speed = double.Parse(split[1]); // -100...+100 turn = double.Parse(split[2]); // -100...+100 } break; } if (fullAuto) { // cruise control desiredSpeed = fullAutoSpeed; desiredTurn = 0.0d; } else { desiredSpeed = speed; desiredTurn = turn; } }
public virtual void OnControlDeviceCommand(ControlDeviceEventArgs e) { controlDeviceEvent?.Invoke(this, e); }