private void axisMoved(JoystickOffset offset, int value, int range) { //indexes // 0 - pitch // 1 - roll // 2 - rudder // 3 - throttle // do some calculations to make it closer to [-1024, 1024] value -= range; value = value / 32; if (offset.ToString() == "X") { commands.movedJoystickAxis(1, value); } else if (offset.ToString() == "Y") { commands.movedJoystickAxis(0, value); } else if (offset.ToString() == "RotationZ") { // assumes twisted rudder commands.movedJoystickAxis(2, value); } else if ((offset.ToString() == "Z") || (offset.ToString().StartsWith("Slider"))) { // assumes a slider is for throttle // this might not be the case on the T. Flight Hotas where it is also yaw, but this should do for sticks like the 3D Pro. commands.movedJoystickAxis(3, value); } }
private static bool IsButtonOffset(JoystickOffset offset) { return( offset >= JoystickOffset.Buttons0 && offset <= JoystickOffset.Buttons127 ); }
private void HandlePovButton(JoystickOffset offset, int value) { if (_lastPovButton.ContainsKey(offset) || value == (int)JoystickOffsetValues.PointOfViewPositionValues.Released) { Logging.Log.Debug($"POV button release: {offset} - {value}"); var success = _lastPovButton.TryRemove(offset, out var translatedOffset); if (!success) { return; } if (!(GetMap(translatedOffset) is HOTASButton map)) { return; } HandleButtonReleased(map, translatedOffset); OnButtonRelease(translatedOffset); } else { var translatedOffset = TranslatePointOfViewOffset(offset, value); _lastPovButton.TryAdd(offset, translatedOffset); Logging.Log.Debug($"Pressing POV button: {offset} - {value}"); if (!(GetMap(translatedOffset) is HOTASButton map)) { return; } HandleButtonPressed(map, translatedOffset); OnButtonPress(translatedOffset); } }
public DButton(JoystickOffset offset) { Offset = offset; IsAnalog = false; Index = (offset - JoystickOffset.Buttons0); Name = NameUtils.GetButtonLabel(Index); }
private bool UnSubscribe(string guid, JoystickOffset offset, string id, int povDirection = 0) { // Block the Monitor thread from polling while we update the data structures lock (stickSubscriptions.DirectXSticks) { return(stickSubscriptions.Remove(guid, offset, id, povDirection)); } }
public static String Name(JoystickOffset id) { var pair = AllNames.FirstOrDefault(n => n.Key == id); if (pair.Equals(new KeyValuePair<JoystickOffset, String>())) return "Unknown"; else return pair.Value; }
public static int TranslatePointOfViewOffset(JoystickOffset offset, int value) { var translatedOffset = value; translatedOffset <<= 8; translatedOffset |= (int)offset; return(translatedOffset); }
public JoystickButtonToColor(Color color, JoystickOffset button, ControlTypeEnum buttonType, byte pressedBrightness, byte releasedBrightness, int[] minCenterMaxValue) { this._color = color; this._button = button; this._control_type = buttonType; this._pressed_brightness = pressedBrightness; this._Centered_brightness = releasedBrightness; this._min_max_value = minCenterMaxValue; }
protected bool AnalyseDataForButtons(List <JoystickUpdate> joystickUpdates, JoystickOffset offset, int value) { foreach (var ju in joystickUpdates) { if (ju.Offset == offset && ju.Value == value) { return(true); } } return(false); }
public bool Add(JoystickOffset offset, dynamic handler, string id, int povDirection = 0) { if (!SupportedInputs[offset]) { return(false); } if (!Inputs.ContainsKey(offset)) { Inputs.Add(offset, new SubscribedDIInput()); } return(Inputs[offset].Add(handler, id, povDirection)); }
public bool Remove(string guidStr, JoystickOffset offset, string id, int povDirection = 0) { Guid guid = new Guid(guidStr); if (!DirectXSticks.ContainsKey(guid)) { return(false); } var ret = DirectXSticks[guid].Remove(offset, id, povDirection); RemoveStickIfEmpty(guid); return(ret); }
private void SeedButtonMap(JoystickOffset startFrom, int length, HOTASButton.ButtonType type, ObservableCollection <IHotasBaseMap> buttonMap) { var indexStart = JoystickOffsetValues.GetIndex(startFrom.ToString()); for (var count = indexStart; count < indexStart + length; count++) { var offset = JoystickOffsetValues.GetOffset(count); buttonMap.Add(new HOTASButton() { MapId = (int)offset, Type = type, MapName = $"{JoystickOffsetValues.GetName(offset)}" }); } }
/// <summary> /// Deserializes a JSON object back to a RGB.NET.Core.Color /// </summary> /// <param name="reader"></param> /// <param name="objectType"></param> /// <param name="existingValue"></param> /// <param name="serializer"></param> /// <returns></returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); Byte.TryParse(jo["Color"]["A"].Value <string>(), out byte a); Byte.TryParse(jo["Color"]["R"].Value <string>(), out byte r); Byte.TryParse(jo["Color"]["G"].Value <string>(), out byte g); Byte.TryParse(jo["Color"]["B"].Value <string>(), out byte b); //Enums are stored as int64 on the JSON, to read it properly converting the index is needed JoystickOffset button = (JoystickOffset)jo["Button"].Value <Int64>(); ControlTypeEnum buttonType = (ControlTypeEnum)jo["ButtonType"].Value <Int64>(); return(new JoystickButtonToColor(new Color(a, r, g, b), button, buttonType, jo["PressedBrightness"].Value <byte>(), jo["ReleasedBrightness"].Value <byte>(), jo["MinCenterMaxValue"].Value <int[]>())); }
// DirectInput public bool Add(string guidStr, JoystickOffset offset, dynamic handler, string id, int povDirection = 0) { if (!RegisterStick(guidStr)) { return(false); } Guid guid = new Guid(guidStr); if (!DirectXSticks[guid].Add(offset, handler, id, povDirection)) { RemoveStickIfEmpty(guid); // If the stick was valid, but non-existent axis or button, then remove the stick again if it is empty return(false); } SetMonitorState(); return(true); }
public bool Remove(JoystickOffset offset, string id, int povDirection = 0) { if (!Inputs.ContainsKey(offset)) { return(false); } var ret = Inputs[offset].Remove(id, povDirection); if (ret) { if (Inputs[offset].IsEmpty()) { Inputs.Remove(offset); } } return(ret); }
protected bool IsPressed(Joystick joystick, JoystickOffset button, int value) { var shortMaskMax = 0xFF00; var shortMaskMin = 0xFF; //Console.WriteLine(button.ToString() + " " + value); if (joystick.Information.Type == DeviceType.Mouse) { if (button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.Buttons0 || button == JoystickOffset.Buttons1) { return(false); } if (button == JoystickOffset.Z) { return(true); } } if (button == JoystickOffset.Z || button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.RotationX || button == JoystickOffset.RotationY || button == JoystickOffset.RotationZ || button == JoystickOffset.Sliders0 || button == JoystickOffset.Sliders1) { return(value >= shortMaskMax || value <= shortMaskMin); } if (button == JoystickOffset.PointOfViewControllers0 || button == JoystickOffset.PointOfViewControllers1 || button == JoystickOffset.PointOfViewControllers2 || button == JoystickOffset.PointOfViewControllers3) { return(value != -1); } return(value != 0); }
public static BindingType OffsetToType(JoystickOffset offset) { int index = (int)offset; if (index <= (int)JoystickOffset.Sliders1) { return(BindingType.Axis); } if (index <= (int)JoystickOffset.PointOfViewControllers3) { return(BindingType.POV); } if (index <= (int)JoystickOffset.Buttons127) { return(BindingType.Button); } return(BindingType.Axis); }
private void buttonPressed(JoystickOffset offset, int value) { String state; // check button state based on value // this is the inverse of OS X, where != 0 is up if (value == 0) { state = "Up"; } else { state = "Down"; } int offsetValue = Int32.Parse(offset.ToString().Replace("Buttons", "")); // leave just a number commands.joystickButtonChanged(offsetValue, state); }
public DInputAxis(JoystickOffset offset) { Name = offset.ToString(); Offset = offset; switch (Offset) { case JoystickOffset.X: NominalAxis = NomialAxes.X; break; case JoystickOffset.Y: NominalAxis = NomialAxes.Y; break; case JoystickOffset.Z: NominalAxis = NomialAxes.Z; break; case JoystickOffset.RotationX: IsRotary = true; NominalAxis = NomialAxes.X; break; case JoystickOffset.RotationY: IsRotary = true; NominalAxis = NomialAxes.Y; break; case JoystickOffset.RotationZ: IsRotary = true; NominalAxis = NomialAxes.Z; break; case JoystickOffset.Sliders0: case JoystickOffset.Sliders1: NominalAxis = NomialAxes.Other; MotionMode = MotionModes.AbsoluteParametric; break; } }
private void povChanged(JoystickOffset offset, int value) { String state; int offsetValue = lastPovId; // prefixed by 11 to avoid duplicates with standard buttons // set offset depending on direction if (value == viewUpId) { offsetValue = 111; } else if (value == viewRightId) { offsetValue = 112; } else if (value == viewDownId) { offsetValue = 113; } else if (value == viewLeftId) { offsetValue = 114; } // set lastPovId lastPovId = offsetValue; // check POV state if (value == -1) { state = "Up"; } else { state = "Down"; } commands.joystickButtonChanged(Int32.Parse(offsetValue.ToString()), state); }
protected bool IsPressed(Joystick joystick, JoystickOffset button, int value) { var shortMaskMax = 0xFF00; var shortMaskMin = 0xFF; //Console.WriteLine(button.ToString() + " " + value); if (joystick.Information.Type == DeviceType.Mouse) { if (button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.Buttons0 || button == JoystickOffset.Buttons1) return false; if (button == JoystickOffset.Z) return true; } if (button == JoystickOffset.Z || button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.RotationX || button == JoystickOffset.RotationY || button == JoystickOffset.RotationZ || button == JoystickOffset.Sliders0 || button == JoystickOffset.Sliders1) return value >= shortMaskMax || value <= shortMaskMin; if (button == JoystickOffset.PointOfViewControllers0 || button == JoystickOffset.PointOfViewControllers1 || button == JoystickOffset.PointOfViewControllers2 || button == JoystickOffset.PointOfViewControllers3) return value != -1; return value != 0; }
private void SeedPointOfViewMap(JoystickOffset startFrom, int length, HOTASButton.ButtonType type, ObservableCollection <IHotasBaseMap> buttonMap) { var indexStart = JoystickOffsetValues.GetIndex(startFrom.ToString()); for (var count = indexStart; count < indexStart + length; count++) { var offset = JoystickOffsetValues.GetOffset(count); //each of the eight POV positions needs a unique offset number so that we don't have to have a compound index to do lookups with later. //so POV1 Offset is 0x00000020 and the value of the EAST position = 0x2328, then assign translated offset of 0x23280020 //so POV2 Offset is 0x00000024 and the value of the SOUTH EAST position = 0x34BC then assign translated offset of 0x34BC0024 for (uint position = 0; position < 8; position++) { var translatedOffset = HOTASQueue.TranslatePointOfViewOffset(offset, 4500 * (int)position); buttonMap.Add(new HOTASButton() { MapId = (int)translatedOffset, Type = type, MapName = Enum.GetName(typeof(JoystickOffsetValues.PointOfViewPositionValues), 4500 * position) }); } } }
public DHat(JoystickOffset offset) { Offset = offset; switch (offset) { case JoystickOffset.PointOfViewControllers0: Index = 0; break; case JoystickOffset.PointOfViewControllers1: Index = 1; break; case JoystickOffset.PointOfViewControllers2: Index = 2; break; case JoystickOffset.PointOfViewControllers3: Index = 3; break; } Name = "POV" + (Index + 1).ToString(); }
public void SetSaveCustomPositionHotkey() { SaveCustomPositionHotkey = GetPressedKey(); }
public void Set(JoystickOffset offset, int value) { if (Type != DeviceType.Virtual || _virtualJoystick == null) return; lock (lockSet) { if (offset >= JoystickOffset.Button0 && offset <= JoystickOffset.Button128) { _virtualJoystick.SetButton((uint)(offset - JoystickOffset.Button0), value == 128 ? true : false); return; } switch (offset) { case JoystickOffset.X: _virtualJoystick.X = value; break; case JoystickOffset.Y: _virtualJoystick.Y = value; break; case JoystickOffset.Z: _virtualJoystick.Z = value; break; case JoystickOffset.RX: _virtualJoystick.RX = value; break; case JoystickOffset.RY: _virtualJoystick.RY = value; break; case JoystickOffset.RZ: _virtualJoystick.RZ = value; break; case JoystickOffset.Slider0: _virtualJoystick.SL0 = value; break; case JoystickOffset.Slider1: _virtualJoystick.SL1 = value; break; } } }
public int Get(JoystickOffset offset) { try { var state = _device.CurrentJoystickState; switch (offset) { case JoystickOffset.X: return state.X; case JoystickOffset.Y: return state.Y; case JoystickOffset.Z: return state.Z; case JoystickOffset.RX: return state.Rx; case JoystickOffset.RY: return state.Ry; case JoystickOffset.RZ: return state.Rz; case JoystickOffset.Slider0: return state.GetSlider()[0]; case JoystickOffset.Slider1: return state.GetSlider()[1]; } } catch { Debug.Print("Get joystick value exception"); return 0; } return 0; }
public void AddAction(JoystickOffset key, Action<DirectInputData> action) { if (action == null) return; if (!_actionMap.Keys.Contains(key)) _actionMap.Add(key, new HashSet<Action<DirectInputData>>()); _actionMap[key].Add(action); }
public void DeleteActions(JoystickOffset key) { _actionMap.Remove(key); }
public void ForceButtonPress(JoystickOffset offset, bool isDown) { HandleStandardButton((int)offset, isDown ? 128 : 0); }
public override void UpdateState(JoystickOffset offset, int value) { switch (offset.ToString()) { case "RotationZ": LeftThrottle = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "Z": RightThrottle = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "Sliders0": Friction = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "X": SlewX = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "Y": SlewY = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "PointOfViewControllers0": CoolieSwitch.Update(value); break; case "Buttons0": SlewPush = GetButtonValue(value); break; case "Buttons1": MicSwitchPush = GetButtonValue(value); break; case "Buttons2": MicSwitch.Up = GetButtonValue(value); break; case "Buttons3": MicSwitch.Right = GetButtonValue(value); break; case "Buttons4": MicSwitch.Down = GetButtonValue(value); break; case "Buttons5": MicSwitch.Left = GetButtonValue(value); break; case "Buttons6": SpeedBreak = GetButtonValue(value); break; case "Buttons7": SpeedBreak = -GetButtonValue(value); break; case "Buttons8": BoatSwitch = GetButtonValue(value); break; case "Buttons9": BoatSwitch = -GetButtonValue(value); break; case "Buttons10": ChinaHat = GetButtonValue(value); break; case "Buttons11": ChinaHat = -GetButtonValue(value); break; case "Buttons12": PinkySwitch = GetButtonValue(value); break; case "Buttons13": PinkySwitch = -GetButtonValue(value); break; case "Buttons14": LeftThrottleButton = GetButtonValue(value); break; case "Buttons15": EngineFuelFlowLeft = GetButtonValue(value); break; case "Buttons16": EngineFuelFlowRight = GetButtonValue(value); break; case "Buttons19": APU = GetButtonValue(value); break; case "Buttons20": LandingGearHornSilence = GetButtonValue(value); break; case "Buttons23": EAC = GetButtonValue(value); break; case "Buttons24": RDR_ALT = GetButtonValue(value); break; case "Buttons25": AutopilotEngageDisengage = GetButtonValue(value); break; case "Buttons26": AutopilotSelect = GetButtonValue(value); break; case "Buttons27": AutopilotSelect = -GetButtonValue(value); break; case "Buttons28": RightThrottleOff = GetButtonValue(value); break; case "Buttons29": LeftThrottleOff = GetButtonValue(value); break; case "Buttons30": EngineOperateLeft = GetButtonValue(value); break; case "Buttons17": EngineOperateLeft = -GetButtonValue(value); break; case "Buttons31": EngineOperateRight = GetButtonValue(value); break; case "Buttons18": EngineOperateRight = -GetButtonValue(value); break; case "Buttons21": Flaps = GetButtonValue(value); break; case "Buttons22": Flaps = -GetButtonValue(value); break; default: Console.WriteLine("Unknown Throttle state: " + offset.ToString()); break; } }
public override void UpdateState(JoystickOffset offset, int value) { switch (offset.ToString()) { case "X": X = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "Y": Y = Remap(value, 0, 65535, -1.0f, 1.0f); break; case "Buttons0": Trigger1 = GetButtonValue(value); break; case "Buttons5": Trigger2 = GetButtonValue(value); break; case "Buttons4": MasterMode = GetButtonValue(value); break; case "Buttons1": Pickle = GetButtonValue(value); break; case "Buttons2": PinkySwitch = GetButtonValue(value); break; case "Buttons3": PinkyLever = GetButtonValue(value); break; case "PointOfViewControllers0": Trim.Update(value); break; case "Buttons6": TMS.Up = GetButtonValue(value); break; case "Buttons8": TMS.Down = GetButtonValue(value); break; case "Buttons9": TMS.Left = GetButtonValue(value); break; case "Buttons7": TMS.Right = GetButtonValue(value); break; case "Buttons10": DMS.Up = GetButtonValue(value); break; case "Buttons12": DMS.Down = GetButtonValue(value); break; case "Buttons13": DMS.Left = GetButtonValue(value); break; case "Buttons11": DMS.Right = GetButtonValue(value); break; case "Buttons14": CMS.Up = GetButtonValue(value); break; case "Buttons16": CMS.Down = GetButtonValue(value); break; case "Buttons17": CMS.Left = GetButtonValue(value); break; case "Buttons15": CMS.Right = GetButtonValue(value); break; case "Buttons18": CMS_Push = GetButtonValue(value); break; default: Console.WriteLine("Unknown Joystick state: " + offset.ToString() + " value: " + value); break; } }
protected string ToString(Joystick joystick, JoystickOffset button, int value) { var shortMaskMax = 0xFF00; var shortMaskMin = 0xFF; var originalName = button.ToString(); if (joystick.Information.Type == DeviceType.Mouse) { if (button == JoystickOffset.Z) { var result = value < LastScrollWheelValue ? "Scroll_Down" : "Scroll_Up"; LastScrollWheelValue = value; return result; } if (button == JoystickOffset.Buttons2) return "Middle"; } if (button == JoystickOffset.Z || button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.RotationX || button == JoystickOffset.RotationY || button == JoystickOffset.RotationZ || button == JoystickOffset.Sliders0 || button == JoystickOffset.Sliders1) return originalName + (value >= shortMaskMax ? '+' : '-'); if (button == JoystickOffset.PointOfViewControllers0 || button == JoystickOffset.PointOfViewControllers1 || button == JoystickOffset.PointOfViewControllers2 || button == JoystickOffset.PointOfViewControllers3) { if (button == JoystickOffset.PointOfViewControllers0) originalName = "POV_0_"; else if (button == JoystickOffset.PointOfViewControllers1) originalName = "POV_1_"; else if (button == JoystickOffset.PointOfViewControllers2) originalName = "POV_2_"; else originalName = "POV_3_"; if (value < 2250) return originalName + "Up"; else if (value < 6750) return originalName + "UpRight"; else if (value < 11250) return originalName + "Right"; else if (value < 15750) return originalName + "DownRight"; else if (value < 20250) return originalName + "Down"; else if (value < 24750) return originalName + "DownLeft"; else if (value < 29250) return originalName + "Left"; else if (value < 33750) return originalName + "UpLeft"; else return originalName + "Up"; } return originalName; }
public void controllerPoller() { var dInput = new DirectInput(); var guid = Guid.Empty; foreach (var instance in dInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { var tempGuid = instance.InstanceGuid; var tempJoystick = new Joystick(dInput, tempGuid); tempJoystick.Acquire(); var vendorId = tempJoystick.Properties.VendorId; var productId = tempJoystick.Properties.ProductId; var productName = tempJoystick.Properties.ProductName; Console.WriteLine("Found Gamepad: {0} VendorID: {1} ProductID: {2} GUID: {3}", productName, vendorId, productId, tempGuid); tempJoystick.Unacquire(); if (vendorId == 0x054c) { if (productId == 0x1000 || productId == 0x0002) { //Found the right device! guid = tempGuid; } } } if (guid == Guid.Empty) { Console.WriteLine("Didn't find a correct device"); //Console.ReadKey(); //Environment.Exit(1); //this.Close(); } else { //Joystick found, now for the meat of the thread. var joystick = new Joystick(dInput, guid); joystick.Properties.BufferSize = 128; joystick.Acquire(); bool[] buttons = new bool[20]; bool[] lastInputs = new bool[20]; //bool threadRunning = true; while (!endThreads) { joystick.Poll(); var data = joystick.GetBufferedData(); foreach (var state in data) { JoystickOffset offset = state.Offset; if (offset.ToString().StartsWith("Buttons")) { StringBuilder builder = new StringBuilder(); builder.Append(offset); builder.Replace("Buttons", ""); int chosenButton = int.Parse(builder.ToString()); if (state.Value == 0x0) { buttons[chosenButton] = false; } else { buttons[chosenButton] = true; } } } for (int i = 0; i < buttons.Length; i++) { if (buttons[i] != lastInputs[i]) { lastInputs[i] = buttons[i]; if (buttons[i]) { //A button was pushed. Now process it correctly. if (i % 5 == 0) { //buzzer was pushed. Are buzzers locked out? if (!buzzerLockout) { //No, take the lock, light up the buzzers, and light the indicator. buzzerLockout = true; buzzLights[i / 5] = true; buzzerPlayer = i / 5; try { this.Dispatcher.Invoke(new Action(delegate() { indicators[i].Fill = Brushes.Red; })); } catch (Exception e) { Console.WriteLine(e.ToString()); } dispatchGet(false); if (buzzSoundActive) { buzzSound.Play(); } } } else { //a choice was pushed. Has this player already locked in? if (!choiceLockouts[i / 5]) { //Nope, take the lock and light up the right choice choiceLockouts[i / 5] = true; choiceLights[i / 5] = true; Brush fillBrush = Brushes.White; if (i % 5 == 1) { fillBrush = Brushes.Goldenrod; choices[i / 5] = 3; } else if (i % 5 == 2) { fillBrush = Brushes.Green; choices[i / 5] = 2; } else if (i % 5 == 3) { fillBrush = Brushes.Orange; choices[i / 5] = 1; } else if (i % 5 == 4) { fillBrush = Brushes.Blue; choices[i / 5] = 0; } try { this.Dispatcher.Invoke(new Action(delegate() { indicators[i].Fill = fillBrush; })); } catch (Exception e) { Console.WriteLine(e.ToString()); } if (choiceSoundActive) { choiceSound.Play(); } if (sendImmediately) { dispatchGetSingle(i / 5); } } } } } } Thread.Sleep(1); } } }
public void ForceButtonPress(IHOTASDevice device, JoystickOffset offset, bool isDown) { device.ForceButtonPress(offset, isDown); }
private void axisMoved(JoystickOffset offset, int value, int range) { //indexes // 0 - pitch // 1 - roll // 2 - rudder // 3 - throttle // do some calculations to make it closer to [-1024, 1024] value -= range; value = value / 32; if (offset.ToString() == "X") { commands.movedJoystickAxis(1, value); } else if (offset.ToString() == "Y") { commands.movedJoystickAxis(0, value); } else if (offset.ToString() == "RotationZ") { // assumes twisted rudder commands.movedJoystickAxis(2, value); } else if ((offset.ToString() == "Z") || (offset.ToString().StartsWith("Slider"))) { // assumes a slider is for throttle // this might not be the case on the T. Flight Hotas where it is also yaw, but this should do for sticks like the 3D Pro. commands.movedJoystickAxis(3, value); } }
protected string ToString(Joystick joystick, JoystickOffset button, int value) { var shortMaskMax = 0xFF00; var shortMaskMin = 0xFF; var originalName = button.ToString(); if (joystick.Information.Type == DeviceType.Mouse) { if (button == JoystickOffset.Z) { var result = value < LastScrollWheelValue ? "Scroll_Down" : "Scroll_Up"; LastScrollWheelValue = value; return(result); } if (button == JoystickOffset.Buttons2) { return("Middle"); } } if (button == JoystickOffset.Z || button == JoystickOffset.X || button == JoystickOffset.Y || button == JoystickOffset.RotationX || button == JoystickOffset.RotationY || button == JoystickOffset.RotationZ || button == JoystickOffset.Sliders0 || button == JoystickOffset.Sliders1) { return(originalName + (value >= shortMaskMax ? '+' : '-')); } if (button == JoystickOffset.PointOfViewControllers0 || button == JoystickOffset.PointOfViewControllers1 || button == JoystickOffset.PointOfViewControllers2 || button == JoystickOffset.PointOfViewControllers3) { if (button == JoystickOffset.PointOfViewControllers0) { originalName = "POV_0_"; } else if (button == JoystickOffset.PointOfViewControllers1) { originalName = "POV_1_"; } else if (button == JoystickOffset.PointOfViewControllers2) { originalName = "POV_2_"; } else { originalName = "POV_3_"; } if (value < 2250) { return(originalName + "Up"); } else if (value < 6750) { return(originalName + "UpRight"); } else if (value < 11250) { return(originalName + "Right"); } else if (value < 15750) { return(originalName + "DownRight"); } else if (value < 20250) { return(originalName + "Down"); } else if (value < 24750) { return(originalName + "DownLeft"); } else if (value < 29250) { return(originalName + "Left"); } else if (value < 33750) { return(originalName + "UpLeft"); } else { return(originalName + "Up"); } } return(originalName); }
public abstract void UpdateState(JoystickOffset offset, int value);
private void povChanged(JoystickOffset offset, int value) { String state; int offsetValue = lastPovId; // prefixed by 11 to avoid duplicates with standard buttons // set offset depending on direction if (value == viewUpId) { offsetValue = 111; } else if (value == viewRightId) { offsetValue = 112; } else if (value == viewDownId) { offsetValue = 113; } else if (value == viewLeftId) { offsetValue = 114; } // set lastPovId lastPovId = offsetValue; // check POV state if (value == -1) { state = "Up"; } else { state = "Down"; } commands.joystickButtonChanged(Int32.Parse(offsetValue.ToString()), state); }
public void SetAxisFilter(JoystickOffset offset, int arrayLength) { AxisFilterMedian currentFilter; try { if (!_axisFilters.TryGetValue(offset, out currentFilter)) { _axisFilters.Add(offset, new AxisFilterMedian( arrayLength * 4 )); } else { _axisFilters[offset] = new AxisFilterMedian( arrayLength * 4 ); } } catch { Debug.Print("SetAxisFilter exception"); } }
public void SetToggleRecordHotkey() { ToggleRecordHotkey = GetPressedKey(); }
private void buttonPressed(JoystickOffset offset, int value) { String state; // check button state based on value // this is the inverse of OS X, where != 0 is up if (value == 0) { state = "Up"; } else { state = "Down"; } int offsetValue = Int32.Parse(offset.ToString().Replace("Buttons", "")); // leave just a number commands.joystickButtonChanged(offsetValue, state); }