public static bool IsDefinedHIDUsage(HIDElementDescriptor hidElement) { bool isKnown = false; if (PageId.IsDefined(typeof(PageId), hidElement.usagePageID)) { switch ((PageId)hidElement.usagePageID) { case PageId.GenericDesktopPage: { isKnown = GenericDesktopUsage.IsDefined(typeof(GenericDesktopUsage), hidElement.usageID); } break; case PageId.SimulationPage: { isKnown = SimulationUsage.IsDefined(typeof(SimulationUsage), hidElement.usageID); } break; case PageId.ButtonPage: { isKnown = hidElement.usageID > 0 && hidElement.usageID <= kMaxButtons; } break; } } return(isKnown); }
static string GetUsageName(int pageId, int usageId) { string usageName = string.Format("Unknown[{0}][{1}]", pageId, usageId); switch ((PageId)pageId) { case PageId.GenericDesktopPage: { if (GenericDesktopUsage.IsDefined(typeof(GenericDesktopUsage), usageId)) { usageName = ((GenericDesktopUsage)usageId).ToString(); } } break; case PageId.SimulationPage: { if (SimulationUsage.IsDefined(typeof(SimulationUsage), usageId)) { usageName = ((SimulationUsage)usageId).ToString(); } } break; case PageId.ButtonPage: { usageName = string.Format("Button {0}", usageId); } break; default: break; } return(usageName); }
public static void AddDefaultControls(ControlSetup controlSetup) { System.Array usagesArray = GenericDesktopUsage.GetValues(typeof(GenericDesktopUsage)); for (int i = 0; i < usagesArray.Length; i++) { GenericDesktopUsage usageId = (GenericDesktopUsage)usagesArray.GetValue(i); string usageType = GetGenericDesktopUsageType(usageId); int controlId = GetControlId((int)PageId.GenericDesktopPage, (int)usageId); string usageName = GetUsageName((int)PageId.GenericDesktopPage, (int)usageId); AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, (int)usageId, (int)PageId.GenericDesktopPage)); } usagesArray = SimulationUsage.GetValues(typeof(SimulationUsage)); for (int i = 0; i < usagesArray.Length; i++) { SimulationUsage usageId = (SimulationUsage)usagesArray.GetValue(i); string usageType = GetSimulationUsageType(usageId); int controlId = GetControlId((int)PageId.SimulationPage, (int)usageId); string usageName = GetUsageName((int)PageId.SimulationPage, (int)usageId); AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, (int)usageId, (int)PageId.SimulationPage)); } // Usages are 1 based for (int i = 1; i <= kMaxButtons; i++) { string usageType = "Button"; int controlId = GetControlId((int)PageId.ButtonPage, i); string usageName = GetUsageName((int)PageId.ButtonPage, i); AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, i, (int)PageId.ButtonPage)); } }
static string GetSimulationUsageType(SimulationUsage usageId) { string usageType; switch (usageId) { case SimulationUsage.AutopilotEnable: case SimulationUsage.ChaffRelease: case SimulationUsage.ElectronicCountermeasures: case SimulationUsage.FlightCommunications: case SimulationUsage.FlareRelease: case SimulationUsage.LandingGear: case SimulationUsage.Trigger: case SimulationUsage.WeaponsArm: case SimulationUsage.WeaponsSelect: usageType = "Button"; break; case SimulationUsage.Aileron: case SimulationUsage.AileronTrim: case SimulationUsage.AntiTorqueControl: case SimulationUsage.CollectiveControl: case SimulationUsage.DiveBrake: case SimulationUsage.Elevator: case SimulationUsage.ElevatorTrim: case SimulationUsage.Rudder: case SimulationUsage.Throttle: case SimulationUsage.ToeBrake: case SimulationUsage.WingFlaps: case SimulationUsage.Accelerator: case SimulationUsage.Brake: case SimulationUsage.Clutch: case SimulationUsage.Shifter: case SimulationUsage.Steering: case SimulationUsage.TurretDirection: case SimulationUsage.BarrelElevation: case SimulationUsage.DivePlane: case SimulationUsage.Ballast: case SimulationUsage.BicycleCrank: case SimulationUsage.HandleBars: case SimulationUsage.FrontBrake: case SimulationUsage.RearBrake: default: usageType = "Axis"; break; } return(usageType); }