private static void Controller_DirectionChanged(ControllerVector sender) { FoundLocalControlsWorking = true; Debug.WriteLine("Direction: " + sender.Direction + ", Magnitude: " + sender.Magnitude); XBoxToRobotDirection((sender.Magnitude < 2500) ? ControllerDirection.None : sender.Direction, sender.Magnitude); }
/// <summary> /// Handler for processing/filtering input from the controller /// </summary> /// <param name="sender">HidDevice handle to the controller</param> /// <param name="args">InputReport received from the controller</param> private void inputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args) { int dPad = (int)args.Report.GetNumericControl(0x01, 0x39).Value; ControllerVector newVector = new ControllerVector() { Direction = (ControllerDirection)dPad, Magnitude = 10000 }; // DPad has priority over thumb stick, only bother with thumb stick // values if DPad is not providing a value. if (newVector.Direction == ControllerDirection.None) { // If direction is None, magnitude should be 0 newVector.Magnitude = 0; // Adjust X/Y so (0,0) is neutral position double stickX = args.Report.GetNumericControl(0x01, 0x30).Value - 32768; double stickY = args.Report.GetNumericControl(0x01, 0x31).Value - 32768; int stickMagnitude = (int)getMagnitude(stickX, stickY); // Only process if the stick is outside the dead zone if (stickMagnitude > 0) { newVector.Direction = coordinatesToDirection(stickX, stickY); newVector.Magnitude = stickMagnitude; if (MaxMagnitude[newVector.Direction] < newVector.Magnitude) { MaxMagnitude[newVector.Direction] = newVector.Magnitude; } } } // Only fire an event if the vector changed if (!this.DirectionVector.Equals(newVector)) { if (null != this.DirectionChanged) { this.DirectionVector = newVector; this.DirectionChanged(this.DirectionVector); } } }