private bool ReactToAnalogEvents(List <AxisMapping> mappingsForDevice, JoystickState state) { int[] initialAxisValues = AxisMapping.GetValues(state); bool atLeastOneChange = false; for (int i = 0; i < mappingsForDevice.Count; i++) { var am = mappingsForDevice[i]; int value = initialAxisValues[i]; if (value != am.Value) { atLeastOneChange = true; am.Value = value; if (value == am.NeutralValue) { // TODO: carry out configured _released_ action, if appropriate } else { // TODO: carry out configured _value_ action, if appropriate } } } return(atLeastOneChange); }
private void ReloadDevices() { mButtonMappings.Clear(); mAxisMappings.Clear(); foreach (DeviceInstance di in mDeviceInstances) { Device d = new Device(di.InstanceGuid); d.SetCooperativeLevel(Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); d.SetDataFormat(DeviceDataFormat.Joystick); mDevices.Add(d); d.Acquire(); // TODO: investigate the use of d.SetEventNotification(); var buttonMappings = new List <ButtonMapping>(); for (int b = 0; b < d.Caps.NumberButtons; b++) { ButtonMapping bm = new ButtonMapping(d.DeviceInformation.InstanceGuid, d.DeviceInformation.InstanceName); bm.Alias = String.Format("#{0}", b + 1); bm.Pressed = false; bm.SoundFileToPlayOnPress = ""; mButtonMappings.Add(bm); buttonMappings.Add(bm); } // TODO: consider adding the "Point of View Hat" instances as a set of analog (and/or digital) inputs mButtonMappingsByDevice.Add(d, buttonMappings); var axisMappings = new List <AxisMapping>(); d.Poll(); int[] initialAxisValues = AxisMapping.GetValues(d.CurrentJoystickState); for (int a = 0; a < initialAxisValues.Length; a++) { AxisMapping am = new AxisMapping(d.DeviceInformation.InstanceGuid, d.DeviceInformation.InstanceName); am.Alias = String.Format("#{0}", a + 1); am.NeutralValue = initialAxisValues[a]; am.Value = 0; mAxisMappings.Add(am); axisMappings.Add(am); } mAxisMappingsByDevice.Add(d, axisMappings); } mButtonConfigurationBridge.DataSource = mButtonMappings; deviceButtonConfiguration.Refresh(); mAxisConfigurationBridge.DataSource = mAxisMappings; deviceAxisConfiguration.Refresh(); joystickPoll.Enabled = true; }