/// <summary> /// 生成拼音和五笔代码(主) /// </summary> /// <param name="e"></param> private void CreateParentPYAndWBCode(DataChangedEventArgs e) { AnatomicOrganDO cherbPDo = e.Data as AnatomicOrganDO; cherbPDo.Pycode = InputMethods.GetJianPin(e.Input as string); cherbPDo.Wbcode = InputMethods.GetWuBi(e.Input as string); }
/// <summary> /// This function enables reading current speed of Motor 1 /// </summary> /// <returns>speed</returns> public async Task <int> GetSpeed() { float value = await InputMethods.GetReadySIValue(Brick.Socket, PortNumber, 0, 2); //return (int) Math.Floor(value); return(Convert.ToInt32(value)); }
static void Main(string[] args) { do { // INPUT VALUES Console.Clear(); Console.WriteLine("\nEnter your values' list separated with spaces.\nEx:1 3 4 3 3\n\nINSERT YOUR VALUES:"); float[] inputData = InputMethods.inputArray(); Console.WriteLine("Would you use intervals? Yes(y) No(n): "); bool useIntervals = Console.ReadLine() == "y" ? true : false; // CALCULATING STATISTICS switch (useIntervals) { case true: Console.WriteLine("How long your interval will be? "); int intervalsLength = int.Parse(Console.ReadLine()); Console.Clear(); StatisticsWithIntervals Data1 = new StatisticsWithIntervals(inputData, intervalsLength); Console.WriteLine("Your data would look like:"); OutputMethods.printTable(Data1); break; case false: StatisticsSimple Data2 = new StatisticsSimple(inputData); Console.WriteLine("Your data would look like:"); OutputMethods.printTable(Data2); break; } // OUTPUT VALUES Console.Write("Press <Enter> to make another table...\nPress any other key to exit..."); }while(Console.ReadKey().Key == ConsoleKey.Enter); }
/// <summary> /// Gets the value depending on the current mode /// </summary> /// <returns>value</returns> public async Task <int> GetValue() { //Documentation is wrong should be reverse getChanges = Bump and Get_bump = Touch int value = (Mode == TouchSensorMode.Bump) ? await InputMethods.GetChanges(Socket, PortNumber) : await InputMethods.GetBumps(Socket, PortNumber); Value = value; return(value); }
/// <summary> /// Gets the value depending on the current mode /// </summary> /// <returns>value</returns> public async Task <ColorSensorValue> GetValue() { int raw = await InputMethods.GetReadyRaw(Brick.Socket, PortNumber, 0, (int)Mode); ColorSensorValue value = ConvertToSensorValue(raw); Value = value; return(value); }
internal override DataType BatchCommand(PayLoadBuilder payLoadBuilder, int index) { //Documentation is wrong should be reverse getChanges = Bump and Get_bump = Touch if (Mode == TouchSensorMode.Bump) { return(InputMethods.GetChangesValue_BatchCommand(payLoadBuilder, Layer, PortNumber, index)); } return(InputMethods.GetBumpsValue_BatchCommand(payLoadBuilder, Layer, PortNumber, index)); }
/// <summary> /// Apply the default minimum and maximum raw value for device type to be used in scaling PCT and SI value /// </summary> /// <param name="type">Device type</param> /// <param name="mode">Device mode [0-7]</param> public async Task SetDefaultMinMax(DeviceType type, DeviceMode mode) { await InputMethods.SetDefaultMinMax(Brick.Socket, type, mode); }
public void touchesMoved(TouchpadEventArgs arg, bool dragging) { int touchesLen = arg.touches.Length; if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1)) { return; } int deltaX, deltaY; if (arg.touches[0].touchID != lastTouchID) { deltaX = deltaY = 0; horizontalRemainder = verticalRemainder = 0.0; horizontalDirection = verticalDirection = Direction.Neutral; lastTouchID = arg.touches[0].touchID; } else if (Global.TouchpadJitterCompensation[deviceNumber]) { // Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter... if (dragging && touchesLen > 1) { deltaX = arg.touches[1].deltaX; deltaY = arg.touches[1].deltaY; } else { deltaX = arg.touches[0].deltaX; deltaY = arg.touches[0].deltaY; } // allow only very fine, slow motions, when changing direction, even from neutral // TODO maybe just consume it completely? if (deltaX <= -1) { if (horizontalDirection != Direction.Negative) { deltaX = -1; horizontalRemainder = 0.0; } } else if (deltaX >= 1) { if (horizontalDirection != Direction.Positive) { deltaX = 1; horizontalRemainder = 0.0; } } if (deltaY <= -1) { if (verticalDirection != Direction.Negative) { deltaY = -1; verticalRemainder = 0.0; } } else if (deltaY >= 1) { if (verticalDirection != Direction.Positive) { deltaY = 1; verticalRemainder = 0.0; } } } else { if (dragging && touchesLen > 1) { deltaX = arg.touches[1].deltaX; deltaY = arg.touches[1].deltaY; } else { deltaX = arg.touches[0].deltaX; deltaY = arg.touches[0].deltaY; } } double coefficient = Global.TouchSensitivity[deviceNumber] / 100.0; // Collect rounding errors instead of losing motion. double xMotion = coefficient * deltaX; if (xMotion > 0.0) { if (horizontalRemainder > 0.0) { xMotion += horizontalRemainder; } } else if (xMotion < 0.0) { if (horizontalRemainder < 0.0) { xMotion += horizontalRemainder; } } int xAction = (int)xMotion; horizontalRemainder = xMotion - xAction; double yMotion = coefficient * deltaY; if (yMotion > 0.0) { if (verticalRemainder > 0.0) { yMotion += verticalRemainder; } } else if (yMotion < 0.0) { if (verticalRemainder < 0.0) { yMotion += verticalRemainder; } } int yAction = (int)yMotion; verticalRemainder = yMotion - yAction; if (yAction != 0 || xAction != 0) { InputMethods.MoveCursorBy(xAction, yAction); } horizontalDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral; verticalDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral; }
/// <summary> /// Method to override to the correct batchcommand to get the proper value /// </summary> /// <param name="payLoadBuilder">CodeBuilder</param> /// <param name="index">global index</param> /// <returns>Value type on return after executing command</returns> internal virtual DataType BatchCommand(PayLoadBuilder payLoadBuilder, int index) { //TODO switch mode/ valuemode etc.. to allow custom devices here InputMethods.GetRawValue_BatchCommand(payLoadBuilder, Layer, PortNumber, index); return(DataType.DATA_A4); }
public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInvert = false) { int touchesLen = arg.touches.Length; if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1)) { return; } int deltaX = 0, deltaY = 0; if (arg.touches[0].touchID != lastTouchID) { deltaX = deltaY = 0; horizontalRemainder = verticalRemainder = 0.0; horizontalDirection = verticalDirection = Direction.Neutral; lastTouchID = arg.touches[0].touchID; } else { if (dragging && touchesLen > 1) { deltaX = arg.touches[1].deltaX; deltaY = arg.touches[1].deltaY; } else { deltaX = arg.touches[0].deltaX; deltaY = arg.touches[0].deltaY; } } double tempAngle = System.Math.Atan2(-deltaY, deltaX); double normX = System.Math.Abs(System.Math.Cos(tempAngle)); double normY = System.Math.Abs(System.Math.Sin(tempAngle)); int signX = System.Math.Sign(deltaX); int signY = System.Math.Sign(deltaY); double coefficient = Global.getTouchSensitivity(deviceNumber) * 0.01; bool jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber); double xMotion = deltaX != 0 ? coefficient * deltaX + (normX * (TOUCHPAD_MOUSE_OFFSET * signX)) : 0.0; double yMotion = deltaY != 0 ? coefficient * deltaY + (normY * (TOUCHPAD_MOUSE_OFFSET * signY)) : 0.0; if (jitterCompenstation) { double absX = System.Math.Abs(xMotion); if (absX <= normX * 0.4) { xMotion = signX * System.Math.Pow(absX / 0.4f, 1.44) * 0.4; } double absY = System.Math.Abs(yMotion); if (absY <= normY * 0.4) { yMotion = signY * System.Math.Pow(absY / 0.4f, 1.44) * 0.4; } } // Collect rounding errors instead of losing motion. if (xMotion > 0.0 && horizontalRemainder > 0.0) { xMotion += horizontalRemainder; } else if (xMotion < 0.0 && horizontalRemainder < 0.0) { xMotion += horizontalRemainder; } int xAction = (int)xMotion; horizontalRemainder = xMotion - xAction; if (yMotion > 0.0 && verticalRemainder > 0.0) { yMotion += verticalRemainder; } else if (yMotion < 0.0 && verticalRemainder < 0.0) { yMotion += verticalRemainder; } int yAction = (int)yMotion; verticalRemainder = yMotion - yAction; if (disableInvert == false) { int touchpadInvert = tempInt = Global.getTouchpadInvert(deviceNumber); if ((touchpadInvert & 0x02) == 2) { xAction *= -1; } if ((touchpadInvert & 0x01) == 1) { yAction *= -1; } } if (yAction != 0 || xAction != 0) { InputMethods.MoveCursorBy(xAction, yAction); } horizontalDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral; verticalDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral; }
/// <summary> /// Scans all possible ports (all chainlayers) for connected devices /// </summary> /// <returns>A list of devices with absolute chained portnumbers and devices.</returns> public async Task <IEnumerable <PortInfo> > PortScan() { return(await InputMethods.PortScan(Brick.Socket)); }
/// <summary> /// Clear changes and bumps and sets value to 0 /// </summary> /// <returns></returns> public async Task Clear() { await InputMethods.ClearChanges(Socket, PortNumber); Value = 0; }
/// <summary> /// Checks if all devices are properly connected to the brick. False on any device/port error forcing brick to disconnect /// If true will beep once for OK, twice for OK and devices found (autoConnectDevices = true), Three times ERROR for device/port error(s) /// Test runs on setting PowerUpSelfTest <see cref="Configuration.PowerUpSelfTestOptions"/> /// Brick must be connected. /// </summary> /// <returns>False on Error, otherwise true</returns> private async Task <bool> PowerUpSelfTest() { //do not stop on error detected to enable logging for all errors. bool errorDetected = false; bool autoConnectDevices = Options.PowerUpSelfTest.AutoConnectDevices; bool autoDevicesConnected = false; IEnumerable <PortInfo> list = await InputMethods.PortScan(Socket); List <PortInfo> devices = new List <PortInfo>(); devices.AddRange(list); for (int layer = 0; layer < 4; layer++) { for (int portNumber = 0; portNumber < 4; portNumber++) { int index; PortInfo entry; PortStatus status; string message; #region Input Ports index = (layer * 4) + portNumber; entry = devices[index]; InputPort inputPort = IOPort.Input.Ports[index]; message = $"Brick {(ChainLayer)layer} Port {inputPort.Name}"; switch (entry.Status) { case PortStatus.OK: { status = inputPort.CheckDevice(entry.Device.Value, Options.PowerUpSelfTest.AutoConnectDevices); switch (status) { case PortStatus.Error: { Logger.LogWarning($"Invalid device {inputPort.Device.Type} {message}"); inputPort.Status = PortStatus.Error; errorDetected = true; break; } case PortStatus.Initializing: { autoDevicesConnected = true; break; } } break; } case PortStatus.Empty: { if (inputPort.Status == PortStatus.OK) { Logger.LogWarning($"Device {inputPort.Device.Type} is not connected {message}"); inputPort.Status = PortStatus.Error; //unconnected device! errorDetected = true; } break; } case PortStatus.Error: { Logger.LogWarning($"{message} Device {entry.Device}"); inputPort.Status = PortStatus.Error; // Output device connected to InputPort errorDetected = true; break; } default: { Logger.LogWarning($"{message} Device {entry.Device}"); inputPort.Status = PortStatus.Error; errorDetected = true; break; } } if (!errorDetected && inputPort.Status == PortStatus.OK) { await inputPort.InitializeDevice(); } #endregion #region Output Ports index = 16 + (layer * 4) + portNumber; entry = devices[index]; OutputPort outputPort = IOPort.Output.Ports[index]; message = $"Brick {(ChainLayer)layer} Port {outputPort.Name}"; switch (entry.Status) { case PortStatus.OK: { status = outputPort.CheckDevice(entry.Device.Value, autoConnectDevices); switch (status) { case PortStatus.Error: { Logger.LogWarning($"Invalid device {outputPort.Device.Type} {message}"); outputPort.Status = PortStatus.Error; errorDetected = true; break; } case PortStatus.Initializing: { autoDevicesConnected = true; break; } } break; } case PortStatus.Empty: { if (outputPort.Status == PortStatus.OK) { Logger.LogWarning($"Device {outputPort.Device.Type} is not connected {message}"); outputPort.Status = PortStatus.Error; //unconnected device! errorDetected = true; } break; } case PortStatus.Error: { Logger.LogWarning($"{message} Device {entry.Device}"); outputPort.Status = PortStatus.Error; // InputPort device connected to Outputport errorDetected = true; break; } default: { Logger.LogWarning($"{message} Device {entry.Device}"); outputPort.Status = PortStatus.Error; errorDetected = true; break; } } if (!errorDetected && outputPort.Status == PortStatus.OK) { await outputPort.InitializeDevice(); } #endregion } } int numberOfLoops = 1; // beep once for OK if (errorDetected) { numberOfLoops = 3; //beep three times } else if (autoDevicesConnected) { numberOfLoops = 2; //beep two times devices found, but all is still well :-) } bool beep = false; switch (numberOfLoops) { case 1: { beep = Options.PowerUpSelfTest.BeepOnOK; break; } case 2: { // all is still well so beep once if set anyhow. beep = (Options.PowerUpSelfTest.BeepOnAutoConnect) ? true : Options.PowerUpSelfTest.BeepOnOK; break; } case 3: { beep = Options.PowerUpSelfTest.BeepOnError; break; } } if (beep) { CancellationToken token = Socket.CancellationToken; await Task.Run(async() => { for (int i = 0; i < numberOfLoops; i++) { await SoundMethods.Tone(Socket, 50, 850, 150); await Task.Delay(400, token); } }, token); } if (errorDetected && Options.PowerUpSelfTest.DisconnectOnError) { await Disconnect(); } Logger.LogInformation($"PowerUpSelfTest: {((errorDetected) ? "ERROR" : "OK")}"); return(!errorDetected); }
/// <summary> /// Stops all input devices /// </summary> public async Task Stop() { await InputMethods.Stop(Brick.Socket); }
/// <summary> /// Clear all device counters and values /// </summary> /// <returns></returns> public async Task Reset() { await InputMethods.Reset(Brick.Socket); }
/// <summary> /// This function enables reading current speed /// </summary> /// <returns>speed</returns> protected async Task <int> GetSpeed() { float value = await InputMethods.GetReadySIValue(Socket, PortNumber, 0, 2); return(Convert.ToInt32(value)); }
/// <summary> /// Read information about external device /// </summary> /// <param name="port"></param> /// <param name="layer"></param> /// <returns></returns> public async Task <Format> GetFormat(OutputPortName port, ChainLayer layer = ChainLayer.One) { int portNumber = port.AbsolutePortNumber(layer); return(await InputMethods.GetFormat(Brick.Socket, layer, portNumber)); }
public static async Task<bool> SendUnicodeKeyChar(char c, InputMethods method = InputMethods.Vni, int time = 0) { return await SendUnicodeKeyChar(c, method, time, GetSymbolTable1(), GetSymbolTable2()); }
public static async Task<bool> SendUnicodeString(string s, InputMethods method = InputMethods.Vni, int time = 0) { //Dictionary<char, VirtualKeys>[] dicts = { GetSymbolTable1(), GetSymbolTable2() }; var result = true; foreach (var c in s) result &= await SendUnicodeKeyChar(c, method, time); return result; }
static bool GetLetterKeys(char c, ref List<VirtualKeys> keys, InputMethods method) //lower character only { if (char.IsUpper(c)) { keys.Add(VirtualKeys.Shift); c = char.ToLower(c); } if (c >= 'a' && c <= 'z') { keys.Add((VirtualKeys)Enum.Parse(typeof(VirtualKeys), c.ToString(), true)); return true; } if (c == 'đ') { keys.Add(VirtualKeys.D); switch (method) { case InputMethods.Vni: keys.Add(VirtualKeys.N9); return true; case InputMethods.Telex: keys.Add(VirtualKeys.D); return true; default: throw new NotImplementedException(); } } for (var i = 0; i < letterChars.Length; i++) if (letterChars[i].Contains(c) && GetLetterKeys(letterChars[i][0], ref keys, method)) { var index = letterChars[i].IndexOf(c); switch (method) { case InputMethods.Vni: keys.Add((VirtualKeys)((int)VirtualKeys.N0 + index)); return true; case InputMethods.Telex: if (index == 6) keys.Add(keys.Last()); else keys.Add(_telexInput[index]); return true; default: throw new NotImplementedException(); } } return false; }
public void Input(List <Character> CharacterList, MouseState oldState) //resstructure this aea to account for going backwards in the menu { if (SelectedChracterIndex == -1) { foreach (Character c in CharacterList) //looks for a character that has been clicked on (if none exist nothing happens, otherwise that character is selected) { if (IsVisibleLvl1 != true && InputMethods.checkIfMouseClickInBounds(oldState, new Vector2(c.Location.X * Constants.MapSquareSize, c.Location.Y * Constants.MapSquareSize), new Vector2(Constants.MapSquareSize, Constants.MapSquareSize), (int)Constants.MouseButtons.Left)) { SelectedChracterIndex = CharacterList.IndexOf(c); IsVisibleLvl1 = true; FilteredMenuItems = filterList(c); break; } } } else { if (IsVisibleLvl1 && !IsVisibleLvl2 && InputMethods.checkIfMouseClicked(oldState, (int)Constants.MouseButtons.Left)) //attack, items, abilities { if (InputMethods.checkIfMouseClickInBounds(oldState, new Vector2((CharacterList[SelectedChracterIndex].Location.X + 1) * Constants.MapSquareSize, CharacterList[SelectedChracterIndex].Location.Y * Constants.MapSquareSize), new Vector2(Constants.CharacterMenuWidth, Constants.CharacterMenuHeight * (FilteredMenuItems.Count)), (int)Constants.MouseButtons.Left)) { IsVisibleLvl2 = true; /*string * for (int x = 0; x < FilteredMenuItems.Count; x++) * { * * }*/ menuIndexLvl2 = (int)(Mouse.GetState().Y - (CharacterList[SelectedChracterIndex].Location.Y * Constants.MapSquareSize)) / Constants.CharacterMenuHeight; Console.Write(menuIndexLvl2); //display appropriat sub menu //enum switch if item menu selected display items } else { IsVisibleLvl1 = false; SelectedChracterIndex = -1; } //if (FilteredMenuItems) } else if (IsVisibleLvl1 && IsVisibleLvl2 && InputMethods.checkIfMouseClicked(oldState, (int)Constants.MouseButtons.Left)) { switch (FilteredMenuItems[menuIndexLvl2]) { case "Items": { Vector2 characterDisplacement = new Vector2((CharacterList[SelectedChracterIndex].Location.X + 1) * (Constants.MapSquareSize), CharacterList[SelectedChracterIndex].Location.Y * Constants.MapSquareSize); List <Item> EquippedItems = new List <Item>(); EquippedItems = CharacterList[SelectedChracterIndex].getEquipedItems(); bool forLoopHasWorked = false; for (int j = 0; j < EquippedItems.Count; j++) { if (InputMethods.checkIfMouseClickInBounds(oldState, new Vector2(Constants.CharacterMenuWidth + characterDisplacement.X, 32 * j + characterDisplacement.Y), new Vector2(Constants.CharacterMenuWidth, Constants.CharacterMenuHeight), (int)Constants.MouseButtons.Left)) { forLoopHasWorked = true; ItemLogic.useItem(CharacterList[SelectedChracterIndex], EquippedItems[j]); Console.WriteLine(CharacterList[SelectedChracterIndex].CurrentHealth); } } if (!forLoopHasWorked) { IsVisibleLvl1 = false; IsVisibleLvl2 = false; SelectedChracterIndex = -1; } else { CharacterList[SelectedChracterIndex].HasAction = false; IsVisibleLvl1 = false; IsVisibleLvl2 = false; SelectedChracterIndex = -1; } /*if () * { * } * else * { * IsVisibleLvl1 = false; * SelectedChracterIndex = -1; * }*/ } break; case "Wait": { CharacterList[SelectedChracterIndex].HasMove = false; CharacterList[SelectedChracterIndex].HasAction = false; IsVisibleLvl1 = false; IsVisibleLvl2 = false; SelectedChracterIndex = -1; } break; default: break; } } /*else if (IsVisibleLvl2 && InputMethods.chechIfMouseClicked(oldState, (int)Constants.MouseButtons.Left)) //no support for sub menues yet so hold off for testing //attack menue, item menu, abilities menu * { * if (InputMethods.checkIfMouseClickInBounds(oldState, new Vector2((CharacterList[SelectedChracterIndex].Location.X + 1) * Constants.MapSquareSize, CharacterList[SelectedChracterIndex].Location.Y * Constants.MapSquareSize), new Vector2(Constants.CharacterMenuWidth, Constants.CharacterMenuHeight * (FilteredMenuItems.Count - 1)), (int)Constants.MouseButtons.Left)) * { * //perform appropriate action * //enum switch if item in inverntory pressed use item * } * else * { * IsVisibleLvl1 = false; * IsVisibleLvl2 = false; * SelectedChracterIndex = -1; * } * }*/ } }
static async Task<bool> SendUnicodeKeyChar(char c, InputMethods method, int time, params Dictionary<char, VirtualKeys>[] dicts) { // Controls, digits, escape and space if (c >= 8 && c <= 13 || c >= 48 && c <= 57 || c == 32 || c == 27) return await SendKeyPress((VirtualKeys)c, time); var keys = new List<VirtualKeys>(); if (GetLetterKeys(c, ref keys, method)) { if (keys[0] == VirtualKeys.Shift) { SendKeyDown(VirtualKeys.Shift); SendKeyDown(keys[1]); SendKeyUp(VirtualKeys.Shift); SendKeyUp(keys[1]); await Task.Delay(time / 2); for (var i = 2; i < keys.Count; i++) { SendKeyPress(keys[i]); } await Task.Delay(time / 2); return true; } return await SendKeyCombination(keys.ToArray(), time); } /*if (dicts[0].ContainsKey(c)) return await SendKeyPress(dicts[0][c], time); if (dicts[1].ContainsKey(c)) return await SendKeyCombination(new VirtualKeys[] { VirtualKeys.Shift, dicts[1][c] }, time);*/ if (_symbolTable1.ContainsKey(c)) return await SendKeyPress(_symbolTable1[c], time); if (_symbolTable2.ContainsKey(c)) return await SendKeyCombination(new[] { VirtualKeys.Shift, _symbolTable2[c] }, time); return false; }
public virtual void sixaxisMoved(SixAxisEventArgs arg) { int deltaX = 0, deltaY = 0; deltaX = Global.getGyroMouseHorizontalAxis(deviceNumber) == 0 ? arg.sixAxis.gyroYawFull : arg.sixAxis.gyroRollFull; deltaY = -arg.sixAxis.gyroPitchFull; //tempDouble = arg.sixAxis.elapsed * 0.001 * 200.0; // Base default speed on 5 ms tempDouble = arg.sixAxis.elapsed * 200.0; // Base default speed on 5 ms gyroSmooth = Global.getGyroSmoothing(deviceNumber); double gyroSmoothWeight = 0.0; coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * GYRO_MOUSE_COEFFICIENT; double offset = GYRO_MOUSE_OFFSET; if (gyroSmooth) { gyroSmoothWeight = Global.getGyroSmoothingWeight(deviceNumber); if (gyroSmoothWeight > 0.0) { offset = GYRO_SMOOTH_MOUSE_OFFSET; } } double tempAngle = System.Math.Atan2(-deltaY, deltaX); double normX = System.Math.Abs(System.Math.Cos(tempAngle)); double normY = System.Math.Abs(System.Math.Sin(tempAngle)); int signX = System.Math.Sign(deltaX); int signY = System.Math.Sign(deltaY); if (deltaX == 0 || (hRemainder > 0 != deltaX > 0)) { hRemainder = 0.0; } if (deltaY == 0 || (vRemainder > 0 != deltaY > 0)) { vRemainder = 0.0; } int deadzoneX = (int)System.Math.Abs(normX * GYRO_MOUSE_DEADZONE); int deadzoneY = (int)System.Math.Abs(normY * GYRO_MOUSE_DEADZONE); if (System.Math.Abs(deltaX) > deadzoneX) { deltaX -= signX * deadzoneX; } else { deltaX = 0; } if (System.Math.Abs(deltaY) > deadzoneY) { deltaY -= signY * deadzoneY; } else { deltaY = 0; } double xMotion = deltaX != 0 ? coefficient * (deltaX * tempDouble) + (normX * (offset * signX)) : 0; int xAction = 0; if (xMotion != 0.0) { xMotion += hRemainder; } else { hRemainder = 0.0; } verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01; double yMotion = deltaY != 0 ? (coefficient * verticalScale) * (deltaY * tempDouble) + (normY * (offset * signY)) : 0; int yAction = 0; if (yMotion != 0.0) { yMotion += vRemainder; } else { vRemainder = 0.0; } if (gyroSmooth) { int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN; xSmoothBuffer[iIndex] = xMotion; ySmoothBuffer[iIndex] = yMotion; smoothBufferTail = iIndex + 1; double currentWeight = 1.0; double finalWeight = 0.0; double x_out = 0.0, y_out = 0.0; int idx = 0; for (int i = 0; i < SMOOTH_BUFFER_LEN; i++) { idx = System.Math.Abs(smoothBufferTail - i - 1) % SMOOTH_BUFFER_LEN; x_out += xSmoothBuffer[idx] * currentWeight; y_out += ySmoothBuffer[idx] * currentWeight; finalWeight += currentWeight; currentWeight *= gyroSmoothWeight; } x_out /= finalWeight; xMotion = x_out; y_out /= finalWeight; yMotion = y_out; } hRemainder = vRemainder = 0.0; if (xMotion != 0.0) { xAction = (int)xMotion; hRemainder = xMotion - xAction; } if (yMotion != 0.0) { yAction = (int)yMotion; vRemainder = yMotion - yAction; } int gyroInvert = Global.getGyroInvert(deviceNumber); if ((gyroInvert & 0x02) == 2) { xAction *= -1; } if ((gyroInvert & 0x01) == 1) { yAction *= -1; } if (yAction != 0 || xAction != 0) { InputMethods.MoveCursorBy(xAction, yAction); } hDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral; vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral; }
public void Update() { //Debug.Log("Run"); mousehits.Clear(); mousehits = InputMethods.MousePickedObjects(Camera.main); int mouseButton = 0; int mouseButtonDown = 0; int mouseButtonUp = 0; if (mousehits.Count > 0) { //Debug.Log(go.layer + ":" + go.name); for (int i = 0; i < 7; i++) { if (Input.GetMouseButtonDown(i)) { mouseButtonDown += 1 << (i); } else if (Input.GetMouseButtonUp(i)) { mouseButtonUp += 1 << (i); } else if (Input.GetMouseButton(i)) { mouseButton += 1 << (i); } } foreach (GameObject go in mousehits.Values) { if (mouseButton != 0) { //Debug.Log(go.name + ":" + ElementDefs.ElementEventMap.ContainsKey(go.name)); GuiElementDefs.HandleEvent(eventname: EventModel.EVENT_MOUSE, indexname: go.name, mousebutton: mouseButton); } if (mouseButtonDown != 0) { //Debug.Log(go.name + ":" + ElementDefs.ElementEventMap.ContainsKey(go.name)); GuiElementDefs.HandleEvent(eventname: EventModel.EVENT_MOUSE_DOWN, indexname: go.name, mousebutton: mouseButtonDown); } if (mouseButtonUp != 0) { //Debug.Log(go.name + ":" + ElementDefs.ElementEventMap.ContainsKey(go.name)); GuiElementDefs.HandleEvent(eventname: EventModel.EVENT_MOUSE_UP, indexname: go.name, mousebutton: mouseButtonUp); } } } if ((mouseButton + mouseButtonDown + mouseButtonUp) == 0) { //Debug.Log("started"); int currentKeyIndex = KeyEventIndex; if (KeyEventIndex == 0) { KeyEventIndex = 1; } else { KeyEventIndex = 0; } KeyUpEventPass[currentKeyIndex](KeyEventIndex); KeyDownEventPass[currentKeyIndex](KeyEventIndex); KeyUpEventPass[currentKeyIndex] = (index) => { }; KeyDownEventPass[currentKeyIndex] = (index) => { }; } }
internal override DataType BatchCommand(PayLoadBuilder payLoadBuilder, int index) { return(InputMethods.GetReadyRaw_BatchCommand(payLoadBuilder, Layer, PortNumber, 0, (int)Mode, 1, index)); }
public void Update() { LastMouseState = CurrentMouseState; CurrentMouseState = Mouse.GetState(); for (int i = 0; i < MaxInputs; i++) { LastKeyboardStates[i] = CurrentKeyboardStates[i]; LastGamePadStates[i] = CurrentGamePadStates[i]; CurrentKeyboardStates[i] = Keyboard.GetState((PlayerIndex)i); CurrentGamePadStates[i] = GamePad.GetState((PlayerIndex)i); if (CurrentGamePadStates[i].IsConnected) { GamePadWasConnected[i] = true; } } if (IsKeyboardInteracted() || IsMouseInteracted()) InputMethod = InputMethods.KeyboardMouse; if (IsGamepadInteracted()) InputMethod = InputMethods.Gamepad; }
//double gyroSmoothWeight = 0.0; public virtual void sixaxisMoved(SixAxisEventArgs arg) { int deltaX = 0, deltaY = 0; deltaX = -arg.sixAxis.gyroXFull; deltaY = -arg.sixAxis.gyroYFull; //Console.WriteLine(arg.sixAxis.deltaX); gyroSmooth = Global.getGyroSmoothing(deviceNumber); double gyroSmoothWeight = 0.0; coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * GYRO_MOUSE_COEFFICIENT; double offset = GYRO_MOUSE_OFFSET; if (gyroSmooth) { gyroSmoothWeight = Global.getGyroSmoothingWeight(deviceNumber); if (gyroSmoothWeight > 0.0) { offset = GYRO_SMOOTH_MOUSE_OFFSET; } } double tempAngle = System.Math.Atan2(-deltaY, deltaX); double normX = System.Math.Abs(System.Math.Cos(tempAngle)); double normY = System.Math.Abs(System.Math.Sin(tempAngle)); int signX = System.Math.Sign(deltaX); int signY = System.Math.Sign(deltaY); if ((hRemainder > 0) != (deltaX > 0)) { hRemainder = 0.0; } if ((vRemainder > 0) != (deltaY > 0)) { vRemainder = 0.0; } int deadzone = GYRO_MOUSE_DEADZONE; //int deadzone = 0; int deadzoneX = (int)System.Math.Abs(normX * deadzone); int deadzoneY = (int)System.Math.Abs(normY * deadzone); if (System.Math.Abs(deltaX) > deadzoneX) { deltaX -= signX * deadzoneX; } else { deltaX = 0; } if (System.Math.Abs(deltaY) > deadzoneY) { deltaY -= signY * deadzoneY; } else { deltaY = 0; } double xMotion = deltaX != 0 ? coefficient * deltaX + (normX * (offset * signX)) : 0; int xAction = 0; if (xMotion != 0.0) { xMotion += hRemainder; //xAction = (int)xMotion; //hRemainder = xMotion - xAction; } else { //hRemainder = 0.0; } //hRemainder -= (int)hRemainder; verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01; double yMotion = deltaY != 0 ? (coefficient * verticalScale) * deltaY + (normY * (offset * signY)) : 0; int yAction = 0; if (yMotion != 0.0) { yMotion += vRemainder; //yAction = (int)yMotion; //vRemainder = yMotion - yAction; } else { //vRemainder = 0.0; } if (gyroSmooth) { int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN; xSmoothBuffer[iIndex] = xMotion; ySmoothBuffer[iIndex] = yMotion; smoothBufferTail = iIndex + 1; double currentWeight = 1.0; double finalWeight = 0.0; double x_out = 0.0, y_out = 0.0; for (int i = 0; i < SMOOTH_BUFFER_LEN; i++) { int idx = System.Math.Abs(smoothBufferTail - i - 1) % SMOOTH_BUFFER_LEN; x_out += xSmoothBuffer[idx] * currentWeight; y_out += ySmoothBuffer[idx] * currentWeight; finalWeight += currentWeight; currentWeight *= gyroSmoothWeight; } x_out /= finalWeight; xMotion = x_out; y_out /= finalWeight; yMotion = y_out; } if (xMotion != 0.0) { xAction = (int)xMotion; hRemainder = xMotion - xAction; } else { hRemainder = 0.0; } if (yMotion != 0.0) { yAction = (int)yMotion; vRemainder = yMotion - yAction; } else { vRemainder = 0.0; } //vRemainder -= (int)vRemainder; int gyroInvert = Global.getGyroInvert(deviceNumber); if (gyroInvert == 2 || gyroInvert == 3) { xAction *= -1; } if (gyroInvert == 1 || gyroInvert == 3) { yAction *= -1; } if (yAction != 0 || xAction != 0) { InputMethods.MoveCursorBy(xAction, yAction); } hDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral; vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral; }
/// <summary> /// Apply new minimum and maximum raw value for device type to be used in scaling PCT and SI value /// </summary> /// <param name="type">Device type</param> /// <param name="mode">Device mode [0-7]</param> /// <param name="minimum">32 bit raw minimum value (Zero point)</param> /// <param name="maximum">32 bit raw maximum value (Full scale)</param> public async Task SetMinMax(DeviceType type, DeviceMode mode, int minimum, int maximum) { await InputMethods.SetMinMax(Brick.Socket, type, mode, minimum, maximum); }