public void updateCursorPosition(CursorPos cursorPosition) { KeymapOutConfig outConfig; if (this.config.TryGetValue("Pointer", out outConfig)) { foreach (IOutputHandler handler in outputHandlers) { ICursorHandler cursorHandler = handler as ICursorHandler; if (cursorHandler != null) { foreach (KeymapOutput output in outConfig.Stack) //Will normally be only one output config { if (output.Cursor) { if (cursorHandler.setPosition(output.Key, cursorPosition)) { break; // we will break for the first accepting handler, for each output key } } } } } } }
public ScreenPositionCalculator() { this.primaryScreen = DeviceUtils.DeviceUtil.GetScreen(Settings.Default.primaryMonitor); this.recalculateScreenBounds(this.primaryScreen); Settings.Default.PropertyChanged += SettingsChanged; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; lastPos = new CursorPos(0, 0, 0, 0, 0); }
public ScreenPositionCalculator() { this.primaryScreen = DeviceUtils.DeviceUtil.GetScreen(Settings.Default.primaryMonitor); this.recalculateScreenBounds(this.primaryScreen); Settings.Default.PropertyChanged += SettingsChanged; SystemEvents.DisplaySettingsChanged +=SystemEvents_DisplaySettingsChanged; lastPos = new CursorPos(0, 0, 0, 0, 0); }
public ScreenPositionCalculator() { this.primaryScreen = DeviceUtils.DeviceUtil.GetScreen(Settings.Default.primaryMonitor); this.recalculateScreenBounds(this.primaryScreen); Settings.Default.PropertyChanged += SettingsChanged; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; lastPos = new CursorPos(0, 0, 0, 0, 0); coordFilter = new CoordFilter(); this.smoothingBuffer = new RadiusBuffer(Settings.Default.pointer_positionSmoothing); }
public TouchHandler(ITouchProviderHandler handler, long id) { this.id = id; this.handler = handler; ulong touchStartID = (ulong)(id - 1) * 4 + 1;//This'll make sure the touch point IDs won't be the same. DuoTouch uses a span of 4 IDs. this.duoTouch = new DuoTouch(Settings.Default.pointer_positionSmoothing, touchStartID); this.lastCursorPos = new CursorPos(0, 0,0,0, 0); this.timeoutTimer = new System.Timers.Timer(); this.timeoutTimer.Interval = Settings.Default.pointer_cursorStillHideTimeout; this.timeoutTimer.Elapsed += timeoutTimer_Elapsed; this.timeoutTimer.Enabled = true; this.timeoutTimer.Start(); }
public WiimoteControl(int id, Wiimote wiimote) { this.Wiimote = wiimote; this.Status = new WiimoteStatus(); this.Status.ID = id; lastpoint = new CursorPos(0, 0, 0); this.screenBounds = Util.ScreenBounds; ulong touchStartID = (ulong)(id - 1) * 4 + 1; //This'll make sure the touch point IDs won't be the same. DuoTouch uses a span of 4 IDs. this.duoTouch = new DuoTouch(this.screenBounds, Properties.Settings.Default.pointer_positionSmoothing, touchStartID); this.keyMapper = new WiiKeyMapper(id); this.keyMapper.OnButtonDown += WiiButton_Down; this.keyMapper.OnButtonUp += WiiButton_Up; this.keyMapper.OnConfigChanged += WiiKeyMap_ConfigChanged; this.keyMapper.OnRumble += WiiKeyMap_OnRumble; this.inputSimulator = new InputSimulator(); this.screenPositionCalculator = new ScreenPositionCalculator(); this.useCustomCursor = Settings.Default.pointer_customCursor; if (this.useCustomCursor) { Color myColor = CursorColor.getColor(this.Status.ID); this.masterCursor = new D3DCursor((this.Status.ID - 1) * 2, myColor); this.slaveCursor = new D3DCursor((this.Status.ID - 1) * 2 + 1, myColor); masterCursor.Hide(); slaveCursor.Hide(); D3DCursorWindow.Current.AddCursor(masterCursor); D3DCursorWindow.Current.AddCursor(slaveCursor); this.keyMapper.SendConfigChangedEvt(); } }
public WiimoteControl(int id, Wiimote wiimote) { this.Wiimote = wiimote; this.Status = new WiimoteStatus(); this.Status.ID = id; lastpoint = new CursorPos(0,0,0); this.screenBounds = Util.ScreenBounds; ulong touchStartID = (ulong)(id - 1) * 4 + 1; //This'll make sure the touch point IDs won't be the same. DuoTouch uses a span of 4 IDs. this.duoTouch = new DuoTouch(this.screenBounds, Properties.Settings.Default.pointer_positionSmoothing, touchStartID); this.keyMapper = new WiiKeyMapper(id); this.keyMapper.OnButtonDown += WiiButton_Down; this.keyMapper.OnButtonUp += WiiButton_Up; this.keyMapper.OnConfigChanged += WiiKeyMap_ConfigChanged; this.keyMapper.OnRumble += WiiKeyMap_OnRumble; this.inputSimulator = new InputSimulator(); this.screenPositionCalculator = new ScreenPositionCalculator(); this.useCustomCursor = Settings.Default.pointer_customCursor; if (this.useCustomCursor) { Color myColor = CursorColor.getColor(this.Status.ID); this.masterCursor = new D3DCursor((this.Status.ID-1)*2,myColor); this.slaveCursor = new D3DCursor((this.Status.ID-1)*2+1,myColor); masterCursor.Hide(); slaveCursor.Hide(); D3DCursorWindow.Current.AddCursor(masterCursor); D3DCursorWindow.Current.AddCursor(slaveCursor); this.keyMapper.SendConfigChangedEvt(); } }
public bool processWiimoteState(WiimoteState wiimoteState) //Returns true if anything has changed from last report. { ButtonState buttonState = wiimoteState.ButtonState; bool significant = false; foreach (IOutputHandler handler in outputHandlers) { handler.startUpdate(); } CursorPos cursorPos = this.screenPositionCalculator.CalculateCursorPos(wiimoteState); this.KeyMap.updateCursorPosition(cursorPos); this.KeyMap.updateAccelerometer(wiimoteState.AccelState); if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.Nunchuk) { this.KeyMap.updateNunchuk(wiimoteState.NunchukState); significant |= checkButtonState(wiimoteState.NunchukState.C, "Nunchuk.C"); significant |= checkButtonState(wiimoteState.NunchukState.Z, "Nunchuk.Z"); } if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.ClassicController) { this.KeyMap.updateClassicController(wiimoteState.ClassicControllerState); ClassicControllerButtonState classicButtonState = wiimoteState.ClassicControllerState.ButtonState; significant |= checkButtonState(classicButtonState.A, "Classic.A"); significant |= checkButtonState(classicButtonState.B, "Classic.B"); significant |= checkButtonState(classicButtonState.Down, "Classic.Down"); significant |= checkButtonState(classicButtonState.Home, "Classic.Home"); significant |= checkButtonState(classicButtonState.Left, "Classic.Left"); significant |= checkButtonState(classicButtonState.Minus, "Classic.Minus"); significant |= checkButtonState(classicButtonState.Plus, "Classic.Plus"); significant |= checkButtonState(classicButtonState.Right, "Classic.Right"); significant |= checkButtonState(classicButtonState.TriggerL, "Classic.L"); significant |= checkButtonState(classicButtonState.TriggerR, "Classic.R"); significant |= checkButtonState(classicButtonState.Up, "Classic.Up"); significant |= checkButtonState(classicButtonState.X, "Classic.X"); significant |= checkButtonState(classicButtonState.Y, "Classic.Y"); significant |= checkButtonState(classicButtonState.ZL, "Classic.ZL"); significant |= checkButtonState(classicButtonState.ZR, "Classic.ZR"); } if (this.releaseHomeOnNextUpdate) { this.releaseHomeOnNextUpdate = false; this.KeyMap.executeButtonUp("Home"); } significant |= checkButtonState(buttonState.A, "A"); significant |= checkButtonState(buttonState.B, "B"); significant |= checkButtonState(buttonState.Down, "Down"); significant |= checkButtonState(buttonState.Home, "Home"); significant |= checkButtonState(buttonState.Left, "Left"); significant |= checkButtonState(buttonState.Minus, "Minus"); significant |= checkButtonState(buttonState.One, "One"); significant |= checkButtonState(buttonState.Plus, "Plus"); significant |= checkButtonState(buttonState.Right, "Right"); significant |= checkButtonState(buttonState.Two, "Two"); significant |= checkButtonState(buttonState.Up, "Up"); foreach (IOutputHandler handler in outputHandlers) { handler.endUpdate(); } if (significant) { Console.WriteLine("********************************significant"); } return(significant); }
public bool processWiimoteState(WiimoteState wiimoteState) //Returns true if anything has changed from last report. { ButtonState buttonState = wiimoteState.ButtonState; bool significant = false; foreach (IOutputHandler handler in outputHandlers) { handler.startUpdate(); } CursorPos cursorPos = this.screenPositionCalculator.CalculateCursorPos(wiimoteState); this.KeyMap.updateCursorPosition(cursorPos); this.KeyMap.updateAccelerometer(wiimoteState.AccelState); if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.Nunchuk) { this.KeyMap.updateNunchuk(wiimoteState.NunchukState); if (wiimoteState.NunchukState.C && !PressedButtons["Nunchuk.C"]) { PressedButtons["Nunchuk.C"] = true; significant = true; this.KeyMap.executeButtonDown(NunchukButton.C); } else if (!wiimoteState.NunchukState.C && PressedButtons["Nunchuk.C"]) { PressedButtons["Nunchuk.C"] = false; significant = true; this.KeyMap.executeButtonUp(NunchukButton.C); } if (wiimoteState.NunchukState.Z && !PressedButtons["Nunchuk.Z"]) { PressedButtons["Nunchuk.Z"] = true; significant = true; this.KeyMap.executeButtonDown(NunchukButton.Z); } else if (!wiimoteState.NunchukState.Z && PressedButtons["Nunchuk.Z"]) { PressedButtons["Nunchuk.Z"] = false; significant = true; this.KeyMap.executeButtonUp(NunchukButton.Z); } } if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.ClassicController) { this.KeyMap.updateClassicController(wiimoteState.ClassicControllerState); ClassicControllerButtonState classicButtonState = wiimoteState.ClassicControllerState.ButtonState; FieldInfo[] cbuttons = classicButtonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo button in cbuttons) { string buttonName = "Classic." + button.Name; if (button.Name == "TriggerL") { buttonName = "Classic.L"; } else if (button.Name == "TriggerR") { buttonName = "Classic.R"; } bool pressedNow = (bool)button.GetValue(classicButtonState); bool pressedBefore = PressedButtons[buttonName]; if (pressedNow && !pressedBefore) { PressedButtons[buttonName] = true; significant = true; this.KeyMap.executeButtonDown(buttonName); } else if (!pressedNow && pressedBefore) { PressedButtons[buttonName] = false; significant = true; this.KeyMap.executeButtonUp(buttonName); } } } if (this.releaseHomeOnNextUpdate) { this.releaseHomeOnNextUpdate = false; this.KeyMap.executeButtonUp("Home"); } FieldInfo[] buttons = buttonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo button in buttons) { bool pressedNow = (bool)button.GetValue(buttonState); bool pressedBefore = PressedButtons[button.Name]; if (pressedNow && !pressedBefore) { PressedButtons[button.Name] = true; significant = true; if (button.Name == "Home") { this.homeButtonTimer.Start(); if (OverlayWindow.Current.OverlayIsOn()) { this.hideOverlayOnUp = true; } } else { this.KeyMap.executeButtonDown(button.Name); } } else if (!pressedNow && pressedBefore) { PressedButtons[button.Name] = false; significant = true; if (button.Name == "Home") { this.homeButtonTimer.Stop(); if (this.hideOverlayOnUp) { this.hideOverlayOnUp = false; OverlayWindow.Current.HideOverlay(); } else if (OverlayWindow.Current.OverlayIsOn()) { } else { this.KeyMap.executeButtonDown("Home"); this.releaseHomeOnNextUpdate = true; } } else { this.KeyMap.executeButtonUp(button.Name); } } } foreach (IOutputHandler handler in outputHandlers) { handler.endUpdate(); } return(significant); }
public bool handleWiimoteChanged(object sender, WiimoteChangedEventArgs e) { // Obtain mutual excluseion. WiimoteMutex.WaitOne(); bool significant = false; try { this.screenBounds = Util.ScreenBounds; this.duoTouch.screenBounds = Util.ScreenBounds; Queue<WiiContact> lFrame = new Queue<WiiContact>(1); // Store the state. WiimoteState pState = e.WiimoteState; this.Status.Battery = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); bool pointerOutOfReach = false; CursorPos newpoint = lastpoint; newpoint = screenPositionCalculator.CalculateCursorPos(e); if (newpoint.X < 0 || newpoint.Y < 0) { newpoint = lastpoint; pointerOutOfReach = true; } WiimoteState ws = e.WiimoteState; if (keyMapper.processWiimoteState(ws)) { significant = true; this.lastWiimoteState = ws; } if (!pointerOutOfReach) { if (this.usingCursors() && !mouseMode && showPointer) { this.masterCursor.Show(); } significant = true; if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y)); if (this.touchDownSlave) { if (this.usingCursors() && !mouseMode && showPointer) { this.slaveCursor.Show(); } duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); if (this.usingCursors() && !mouseMode) { this.slaveCursor.Hide(); } } lastpoint = newpoint; lFrame = duoTouch.getFrame(); if (this.usingCursors() && !mouseMode) { WiiContact master = null; WiiContact slave = null; foreach (WiiContact contact in lFrame) { if (master == null) { master = contact; } else if (master.Priority > contact.Priority) { slave = master; master = contact; } else { slave = contact; } } if(master != null) { this.masterCursor.SetPosition(master.Position); this.masterCursor.SetRotation(newpoint.Rotation); } if(slave != null) { this.slaveCursor.SetPosition(slave.Position); this.slaveCursor.SetRotation(newpoint.Rotation); } } FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame); this.FrameQueue.Enqueue(pFrame); this.LastFrameEvent = pFrame; if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode { if (gamingMouse) { double deltaX = (newpoint.X - ((double)this.screenBounds.Width / 2.0)) / (double)this.screenBounds.Width; double deltaY = (newpoint.Y - ((double)this.screenBounds.Height / 2.0)) / (double)this.screenBounds.Height; deltaX = Math.Sign(deltaX) * deltaX * deltaX * 50; deltaY = Math.Sign(deltaY) * deltaY * deltaY * 50 * ((double)this.screenBounds.Width / (double)this.screenBounds.Height); deltaXBuffer += deltaX % 1; deltaYBuffer += deltaY % 1; int roundDeltaX = (int)deltaX; int roundDeltaY = (int)deltaY; if (deltaXBuffer > 1 || deltaXBuffer < -1) { roundDeltaX += Math.Sign(deltaXBuffer); deltaXBuffer -= Math.Sign(deltaXBuffer); } if (deltaYBuffer > 1 || deltaYBuffer < -1) { roundDeltaY += Math.Sign(deltaYBuffer); deltaYBuffer -= Math.Sign(deltaYBuffer); } this.inputSimulator.Mouse.MoveMouseBy(roundDeltaX, roundDeltaY); } else { this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.screenBounds.Width, (65535 * newpoint.Y) / this.screenBounds.Height); } MouseSimulator.WakeCursor(); } } else //pointer out of reach { if (this.usingCursors() && !mouseMode) { this.masterCursor.Hide(); this.masterCursor.SetPosition(new System.Windows.Point(lastpoint.X, lastpoint.Y)); } } if (significant) { this.LastSignificantWiimoteEventTime = DateTime.Now; } } catch (Exception ex) { Console.WriteLine("Error handling Wiimote in WiimoteControl: " + ex.Message); return significant; } //this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); // Release mutual exclusion. WiimoteMutex.ReleaseMutex(); return significant; }
public CursorPos CalculateCursorPos(WiimoteChangedEventArgs args) { int x; int y; IRState irState = args.WiimoteState.IRState; PointF relativePosition = new PointF(); bool foundMidpoint = false; /*for(int i=0;i<irState.IRSensors.Count() && !foundMidpoint;i++)//IRSensor sensor in irState.IRSensors) * { * IRSensor sensor = irState.IRSensors[i]; * if (sensor.Found) * { * for (int j = i + 1; j < irState.IRSensors.Count() && !foundMidpoint; j++) * { * IRSensor sensor2 = irState.IRSensors[j]; * if (sensor2.Found) * {*/ if (irState.IRSensors[0].Found && irState.IRSensors[1].Found) { foundMidpoint = true; relativePosition.X = (irState.IRSensors[0].Position.X + irState.IRSensors[1].Position.X) / 2.0f; relativePosition.Y = (irState.IRSensors[0].Position.Y + irState.IRSensors[1].Position.Y) / 2.0f; if (Settings.Default.pointer_considerRotation) { //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.RawValues.X, args.WiimoteState.AccelState.RawValues.Z)); //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue(); /* * while (accXhistory.Count >= Settings.Default.pointer_rotationSmoothing) * { * accXhistory.Dequeue(); * } * while (accZhistory.Count >= Settings.Default.pointer_rotationSmoothing) * { * accZhistory.Dequeue(); * } * * accXhistory.Enqueue(args.WiimoteState.AccelState.RawValues.X); * accZhistory.Enqueue(args.WiimoteState.AccelState.RawValues.Z); * * smoothedX = 0; * smoothedZ = 0; * * foreach (double accX in accXhistory) * { * smoothedX += accX; * } * smoothedX /= accXhistory.Count; * * foreach (double accZ in accZhistory) * { * smoothedZ += accZ; * } * smoothedZ /= accZhistory.Count; */ smoothedX = smoothedX * 0.9 + args.WiimoteState.AccelState.RawValues.X * 0.1; smoothedZ = smoothedZ * 0.9 + args.WiimoteState.AccelState.RawValues.Z * 0.1; double absx = Math.Abs(smoothedX - 128), absz = Math.Abs(smoothedZ - 128); if (orientation == 0 || orientation == 2) { absx -= 5; } if (orientation == 1 || orientation == 3) { absz -= 5; } if (absz >= absx) { if (absz > 5) { orientation = (smoothedZ > 128) ? 0 : 2; } } else { if (absx > 5) { orientation = (smoothedX > 128) ? 3 : 1; } } int l = leftPoint, r; //if (leftPoint == -1) //{ switch (orientation) { case 0: l = (irState.IRSensors[0].RawPosition.X < irState.IRSensors[1].RawPosition.X) ? 0 : 1; break; case 1: l = (irState.IRSensors[0].RawPosition.Y > irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break; case 2: l = (irState.IRSensors[0].RawPosition.X > irState.IRSensors[1].RawPosition.X) ? 0 : 1; break; case 3: l = (irState.IRSensors[0].RawPosition.Y < irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break; } leftPoint = l; //} r = 1 - l; double dx = irState.IRSensors[r].RawPosition.X - irState.IRSensors[l].RawPosition.X; double dy = irState.IRSensors[r].RawPosition.Y - irState.IRSensors[l].RawPosition.Y; double d = Math.Sqrt(dx * dx + dy * dy); dx /= d; dy /= d; smoothedRotation = 0.5 * smoothedRotation + 0.5 * Math.Atan2(dy, dx); /* * while (rotationHistory.Count >= Settings.Default.pointer_rotationSmoothing) * { * rotationHistory.Dequeue(); * } * * rotationHistory.Enqueue(rotation); * * double smoothedRotation = 0; * foreach (double rot in rotationHistory) * { * smoothedRotation += rot; * } * smoothedRotation /= rotationHistory.Count; */ //smoothedRotation = smoothedRotation * 0.9 + rotation * 0.1; //rotation = smoothedRotation; } //} //} //} } if (!foundMidpoint) { leftPoint = -1; CursorPos err = new CursorPos(-1, -1, 0); return(err); } int offsetY = 0; if (Properties.Settings.Default.pointer_sensorBarPos == "top") { offsetY = -SBPositionOffset; } else if (Properties.Settings.Default.pointer_sensorBarPos == "bottom") { offsetY = SBPositionOffset; } relativePosition.X = 1 - relativePosition.X; if (Settings.Default.pointer_considerRotation) { //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.Values.X, args.WiimoteState.AccelState.Values.Z)); //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue(); //rotation = -1 * (Math.Atan2(smoothedRotation.Y, smoothedRotation.X) - (Math.PI / 2.0)); relativePosition.X = relativePosition.X - 0.5F; relativePosition.Y = relativePosition.Y - 0.5F; relativePosition = this.rotatePoint(relativePosition, smoothedRotation); relativePosition.X = relativePosition.X + 0.5F; relativePosition.Y = relativePosition.Y + 0.5F; //relativePosition.X = 1 - relativePosition.X; //relativePosition.Y = 1 - relativePosition.Y; } x = Convert.ToInt32((float)maxWidth * relativePosition.X + minXPos); y = Convert.ToInt32((float)maxHeight * relativePosition.Y + minYPos) + offsetY; if (x <= 0) { x = 0; } else if (x >= Util.ScreenWidth) { x = Util.ScreenWidth - 1; } if (y <= 0) { y = 0; } else if (y >= Util.ScreenHeight) { y = Util.ScreenHeight - 1; } CursorPos result = new CursorPos(x, y, smoothedRotation); return(result); }
public bool setPosition(string key, CursorPos cursorPos) { key = key.ToLower(); if (key.Equals("360.stickl") || key.Equals("360.stickr")) { if (!cursorPos.OutOfReach) { Point smoothedPos = cursorPositionHelper.getSmoothedPosition(new Point(cursorPos.RelativeX, cursorPos.RelativeY)); double smoothedX = smoothedPos.X; double smoothedY = 1 - smoothedPos.Y; // Y is inverted switch (key) { case "360.stickl": report.StickLX = smoothedX; report.StickLY = smoothedY; break; case "360.stickr": report.StickRX = smoothedX; report.StickRY = smoothedY; break; } return true; } } return false; }
public bool handleWiimoteChanged(object sender, WiimoteChangedEventArgs e) { // Obtain mutual excluseion. WiimoteMutex.WaitOne(); bool significant = false; try { this.screenBounds = Util.ScreenBounds; this.duoTouch.screenBounds = Util.ScreenBounds; Queue <WiiContact> lFrame = new Queue <WiiContact>(1); // Store the state. WiimoteState pState = e.WiimoteState; this.Status.Battery = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); bool pointerOutOfReach = false; CursorPos newpoint = lastpoint; newpoint = screenPositionCalculator.CalculateCursorPos(e); if (newpoint.X < 0 || newpoint.Y < 0) { newpoint = lastpoint; pointerOutOfReach = true; } WiimoteState ws = e.WiimoteState; if (keyMapper.processWiimoteState(ws)) { significant = true; this.lastWiimoteState = ws; } if (!pointerOutOfReach) { if (this.usingCursors() && !mouseMode && showPointer) { this.masterCursor.Show(); } significant = true; if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y)); if (this.touchDownSlave) { if (this.usingCursors() && !mouseMode && showPointer) { this.slaveCursor.Show(); } duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); if (this.usingCursors() && !mouseMode) { this.slaveCursor.Hide(); } } lastpoint = newpoint; lFrame = duoTouch.getFrame(); if (this.usingCursors() && !mouseMode) { WiiContact master = null; WiiContact slave = null; foreach (WiiContact contact in lFrame) { if (master == null) { master = contact; } else if (master.Priority > contact.Priority) { slave = master; master = contact; } else { slave = contact; } } if (master != null) { this.masterCursor.SetPosition(master.Position); this.masterCursor.SetRotation(newpoint.Rotation); } if (slave != null) { this.slaveCursor.SetPosition(slave.Position); this.slaveCursor.SetRotation(newpoint.Rotation); } } FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame); this.FrameQueue.Enqueue(pFrame); this.LastFrameEvent = pFrame; if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode { if (gamingMouse) { double deltaX = (newpoint.X - ((double)this.screenBounds.Width / 2.0)) / (double)this.screenBounds.Width; double deltaY = (newpoint.Y - ((double)this.screenBounds.Height / 2.0)) / (double)this.screenBounds.Height; deltaX = Math.Sign(deltaX) * deltaX * deltaX * 50; deltaY = Math.Sign(deltaY) * deltaY * deltaY * 50 * ((double)this.screenBounds.Width / (double)this.screenBounds.Height); deltaXBuffer += deltaX % 1; deltaYBuffer += deltaY % 1; int roundDeltaX = (int)deltaX; int roundDeltaY = (int)deltaY; if (deltaXBuffer > 1 || deltaXBuffer < -1) { roundDeltaX += Math.Sign(deltaXBuffer); deltaXBuffer -= Math.Sign(deltaXBuffer); } if (deltaYBuffer > 1 || deltaYBuffer < -1) { roundDeltaY += Math.Sign(deltaYBuffer); deltaYBuffer -= Math.Sign(deltaYBuffer); } this.inputSimulator.Mouse.MoveMouseBy(roundDeltaX, roundDeltaY); } else { this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.screenBounds.Width, (65535 * newpoint.Y) / this.screenBounds.Height); } MouseSimulator.WakeCursor(); } } else //pointer out of reach { if (this.usingCursors() && !mouseMode) { this.masterCursor.Hide(); this.masterCursor.SetPosition(new System.Windows.Point(lastpoint.X, lastpoint.Y)); } } if (significant) { this.LastSignificantWiimoteEventTime = DateTime.Now; } } catch (Exception ex) { Console.WriteLine("Error handling Wiimote in WiimoteControl: " + ex.Message); return(significant); } //this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); // Release mutual exclusion. WiimoteMutex.ReleaseMutex(); return(significant); }
public bool endUpdate() { if (positionToPush != null) { this.setPosition(positionToPush); positionToPush = null; } return true; }
public CursorPos CalculateCursorPos(WiimoteState wiimoteState) { int x; int y; IRState irState = wiimoteState.IRState; PointF relativePosition = new PointF(); bool foundMidpoint = false; for (int i = 0; i < irState.IRSensors.Count() && !foundMidpoint; i++) { if (irState.IRSensors[i].Found) { for (int j = i + 1; j < irState.IRSensors.Count() && !foundMidpoint; j++) { if (irState.IRSensors[j].Found) { foundMidpoint = true; relativePosition.X = (irState.IRSensors[i].Position.X + irState.IRSensors[j].Position.X) / 2.0f; relativePosition.Y = (irState.IRSensors[i].Position.Y + irState.IRSensors[j].Position.Y) / 2.0f; if (Settings.Default.pointer_considerRotation) { smoothedX = smoothedX * 0.9f + wiimoteState.AccelState.RawValues.X * 0.1f; smoothedZ = smoothedZ * 0.9f + wiimoteState.AccelState.RawValues.Z * 0.1f; int l = leftPoint, r; if (leftPoint == -1) { double absx = Math.Abs(smoothedX - 128), absz = Math.Abs(smoothedZ - 128); if (orientation == 0 || orientation == 2) { absx -= 5; } if (orientation == 1 || orientation == 3) { absz -= 5; } if (absz >= absx) { if (absz > 5) { orientation = (smoothedZ > 128) ? 0 : 2; } } else { if (absx > 5) { orientation = (smoothedX > 128) ? 3 : 1; } } switch (orientation) { case 0: l = (irState.IRSensors[i].RawPosition.X < irState.IRSensors[j].RawPosition.X) ? i : j; break; case 1: l = (irState.IRSensors[i].RawPosition.Y > irState.IRSensors[j].RawPosition.Y) ? i : j; break; case 2: l = (irState.IRSensors[i].RawPosition.X > irState.IRSensors[j].RawPosition.X) ? i : j; break; case 3: l = (irState.IRSensors[i].RawPosition.Y < irState.IRSensors[j].RawPosition.Y) ? i : j; break; } } leftPoint = l; r = l == i ? j : i; double dx = irState.IRSensors[r].RawPosition.X - irState.IRSensors[l].RawPosition.X; double dy = irState.IRSensors[r].RawPosition.Y - irState.IRSensors[l].RawPosition.Y; double d = Math.Sqrt(dx * dx + dy * dy); dx /= d; dy /= d; smoothedRotation = Math.Atan2(dy, dx); } } } } } if (!foundMidpoint) { CursorPos err = lastPos; err.OutOfReach = true; leftPoint = -1; return(err); } int offsetY = 0; if (Properties.Settings.Default.pointer_sensorBarPos == "top") { offsetY = -SBPositionOffset; } else if (Properties.Settings.Default.pointer_sensorBarPos == "bottom") { offsetY = SBPositionOffset; } relativePosition.X = 1 - relativePosition.X; if (Settings.Default.pointer_considerRotation) { relativePosition.X = relativePosition.X - 0.5F; relativePosition.Y = relativePosition.Y - 0.5F; relativePosition = this.rotatePoint(relativePosition, smoothedRotation); relativePosition.X = relativePosition.X + 0.5F; relativePosition.Y = relativePosition.Y + 0.5F; } System.Windows.Point filteredPoint = coordFilter.AddGetFilteredCoord(new System.Windows.Point(relativePosition.X, relativePosition.Y), 1.0, 1.0); relativePosition.X = (float)filteredPoint.X; relativePosition.Y = (float)filteredPoint.Y; Vector smoothedPoint = smoothingBuffer.AddAndGet(new Vector(relativePosition.X, relativePosition.Y)); x = Convert.ToInt32((float)maxWidth * smoothedPoint.X + minXPos); y = Convert.ToInt32((float)maxHeight * smoothedPoint.Y + minYPos) + offsetY; if (x <= 0) { x = 0; } else if (x >= primaryScreen.Bounds.Width) { x = primaryScreen.Bounds.Width - 1; } if (y <= 0) { y = 0; } else if (y >= primaryScreen.Bounds.Height) { y = primaryScreen.Bounds.Height - 1; } CursorPos result = new CursorPos(x, y, smoothedPoint.X, smoothedPoint.Y, smoothedRotation); lastPos = result; return(result); }
private void setPosition(Provider.CursorPos cursorPos) { if(!mightTimeOut) { timeoutCursorPos = cursorPos; this.timeoutTimer.Start(); } if (!this.touchDownMaster && !this.touchDownSlave && Math.Abs(this.timeoutCursorPos.X - cursorPos.X) < Settings.Default.pointer_cursorStillThreshold && Math.Abs(this.timeoutCursorPos.Y - cursorPos.Y) < Settings.Default.pointer_cursorStillThreshold) { this.mightTimeOut = true; } else { this.mightTimeOut = false; this.timedOut = false; this.timeoutTimer.Stop(); } if (!cursorPos.OutOfReach && !timedOut) { if(timedOut) { this.timedOut = false; } Queue<WiiContact> lFrame = new Queue<WiiContact>(1); // Store the state. if (this.usingCursors()) { this.masterCursor.Show(); } //significant = true; if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); if (this.touchDownSlave) { if (this.usingCursors()) { this.slaveCursor.Show(); } duoTouch.setSlavePosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); if (this.usingCursors()) { this.slaveCursor.Hide(); } } lastCursorPos = cursorPos; lFrame = duoTouch.getFrame(); foreach (WiiContact contact in lFrame) { this.handler.queueContact(contact); } if (this.usingCursors()) { WiiContact master = null; WiiContact slave = null; foreach (WiiContact contact in lFrame) { if (master == null) { master = contact; } else if (master.Priority > contact.Priority) { slave = master; master = contact; } else { slave = contact; } } if (master != null) { this.masterCursor.SetPosition(master.Position); this.masterCursor.SetRotation(cursorPos.Rotation); } if (slave != null) { this.slaveCursor.SetPosition(slave.Position); this.slaveCursor.SetRotation(cursorPos.Rotation); } } } else //pointer out of reach { if (this.usingCursors()) { this.masterCursor.Hide(); this.masterCursor.SetPosition(new System.Windows.Point(cursorPos.X, cursorPos.Y)); } } }
private bool normalStickCursor(string key, double value) { int step = (int)Math.Round(30 * value); CursorPos fromPos; if (positionToPush != null) { fromPos = positionToPush; } else { fromPos = lastCursorPos; } if (key.ToLower().Equals("touchx-")) { int x = fromPos.X - step < 0 ? 0 : fromPos.X - step; positionToPush = new CursorPos(x, fromPos.Y,0,0, 0); return true; } else if (key.ToLower().Equals("touchx+")) { int x = fromPos.X + step > this.duoTouch.screenBounds.Width - 1 ? this.duoTouch.screenBounds.Width - 1 : fromPos.X + step; positionToPush = new CursorPos(x, fromPos.Y,0,0, 0); return true; } else if (key.ToLower().Equals("touchy-")) { int y = fromPos.Y + step > this.duoTouch.screenBounds.Height - 1 ? this.duoTouch.screenBounds.Height - 1 : fromPos.Y + step; positionToPush = new CursorPos(fromPos.X, y,0,0, 0); return true; } else if (key.ToLower().Equals("touchy+")) { int y = fromPos.Y - step < 0 ? 0 : fromPos.Y - step; positionToPush = new CursorPos(fromPos.X, y,0,0, 0); return true; } return false; }
private bool alternativeStickCursor(string key, double value) { value = value * 1.4; //We give it a default upscale so we can reach the edges of the screen. CursorPos fromPos; if (positionToPush != null) { fromPos = positionToPush; } else { fromPos = lastCursorPos; } if (key.ToLower().Equals("touchx-")) { int x = (int)((this.duoTouch.screenBounds.Width / 2) - value * (this.duoTouch.screenBounds.Width / 2) + 0.5); x = x < 0 ? 0 : x; positionToPush = new CursorPos(x, fromPos.Y,0,0, 0); return true; } else if (key.ToLower().Equals("touchx+")) { int x = (int)((this.duoTouch.screenBounds.Width / 2) + value * (this.duoTouch.screenBounds.Width / 2) + 0.5); x = x > this.duoTouch.screenBounds.Width - 1 ? this.duoTouch.screenBounds.Width - 1 : x; positionToPush = new CursorPos(x, fromPos.Y,0,0, 0); return true; } else if (key.ToLower().Equals("touchy-")) { int y = (int)((this.duoTouch.screenBounds.Height / 2) + value * (this.duoTouch.screenBounds.Height / 2) + 0.5); y = y > this.duoTouch.screenBounds.Height - 1 ? this.duoTouch.screenBounds.Height - 1 : y; positionToPush = new CursorPos(fromPos.X, y,0,0, 0); return true; } else if (key.ToLower().Equals("touchy+")) { int y = (int)((this.duoTouch.screenBounds.Height / 2) - value * (this.duoTouch.screenBounds.Height / 2) + 0.5); y = y < 0 ? 0 : y; positionToPush = new CursorPos(fromPos.X, y,0,0, 0); return true; } return false; }
public bool setPosition(string key, Provider.CursorPos cursorPos) { if (key.ToLower().Equals("touch")) { positionToPush = cursorPos; return true; } return false; }
public CursorPos CalculateCursorPos(WiimoteState wiimoteState) { int x; int y; IRState irState = wiimoteState.IRState; PointF relativePosition = new PointF(); bool foundMidpoint = false; /*for(int i=0;i<irState.IRSensors.Count() && !foundMidpoint;i++)//IRSensor sensor in irState.IRSensors) { IRSensor sensor = irState.IRSensors[i]; if (sensor.Found) { for (int j = i + 1; j < irState.IRSensors.Count() && !foundMidpoint; j++) { IRSensor sensor2 = irState.IRSensors[j]; if (sensor2.Found) {*/ if(irState.IRSensors[0].Found && irState.IRSensors[1].Found) { foundMidpoint = true; relativePosition.X = (irState.IRSensors[0].Position.X + irState.IRSensors[1].Position.X) / 2.0f; relativePosition.Y = (irState.IRSensors[0].Position.Y + irState.IRSensors[1].Position.Y) / 2.0f; if (Settings.Default.pointer_considerRotation) { //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.RawValues.X, args.WiimoteState.AccelState.RawValues.Z)); //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue(); /* while (accXhistory.Count >= Settings.Default.pointer_rotationSmoothing) { accXhistory.Dequeue(); } while (accZhistory.Count >= Settings.Default.pointer_rotationSmoothing) { accZhistory.Dequeue(); } accXhistory.Enqueue(args.WiimoteState.AccelState.RawValues.X); accZhistory.Enqueue(args.WiimoteState.AccelState.RawValues.Z); smoothedX = 0; smoothedZ = 0; foreach (double accX in accXhistory) { smoothedX += accX; } smoothedX /= accXhistory.Count; foreach (double accZ in accZhistory) { smoothedZ += accZ; } smoothedZ /= accZhistory.Count; */ smoothedX = smoothedX * 0.9 + wiimoteState.AccelState.RawValues.X * 0.1; smoothedZ = smoothedZ * 0.9 + wiimoteState.AccelState.RawValues.Z * 0.1; double absx = Math.Abs(smoothedX - 128), absz = Math.Abs(smoothedZ - 128); if (orientation == 0 || orientation == 2) absx -= 5; if (orientation == 1 || orientation == 3) absz -= 5; if (absz >= absx) { if (absz > 5) orientation = (smoothedZ > 128) ? 0 : 2; } else { if (absx > 5) orientation = (smoothedX > 128) ? 3 : 1; } int l = leftPoint, r; //if (leftPoint == -1) //{ switch (orientation) { case 0: l = (irState.IRSensors[0].RawPosition.X < irState.IRSensors[1].RawPosition.X) ? 0 : 1; break; case 1: l = (irState.IRSensors[0].RawPosition.Y > irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break; case 2: l = (irState.IRSensors[0].RawPosition.X > irState.IRSensors[1].RawPosition.X) ? 0 : 1; break; case 3: l = (irState.IRSensors[0].RawPosition.Y < irState.IRSensors[1].RawPosition.Y) ? 0 : 1; break; } leftPoint = l; //} r = 1 - l; double dx = irState.IRSensors[r].RawPosition.X - irState.IRSensors[l].RawPosition.X; double dy = irState.IRSensors[r].RawPosition.Y - irState.IRSensors[l].RawPosition.Y; double d = Math.Sqrt(dx * dx + dy * dy); dx /= d; dy /= d; smoothedRotation = 0.7 * smoothedRotation + 0.3 * Math.Atan2(dy, dx); /* while (rotationHistory.Count >= Settings.Default.pointer_rotationSmoothing) { rotationHistory.Dequeue(); } rotationHistory.Enqueue(rotation); double smoothedRotation = 0; foreach (double rot in rotationHistory) { smoothedRotation += rot; } smoothedRotation /= rotationHistory.Count; */ //smoothedRotation = smoothedRotation * 0.9 + rotation * 0.1; //rotation = smoothedRotation; } //} //} //} } if (!foundMidpoint) { CursorPos err = lastPos; err.OutOfReach = true; return err; } int offsetY = 0; if (Properties.Settings.Default.pointer_sensorBarPos == "top") { offsetY = -SBPositionOffset; } else if (Properties.Settings.Default.pointer_sensorBarPos == "bottom") { offsetY = SBPositionOffset; } relativePosition.X = 1 - relativePosition.X; if (Settings.Default.pointer_considerRotation) { //accelSmoothing.addValue(new System.Windows.Vector(args.WiimoteState.AccelState.Values.X, args.WiimoteState.AccelState.Values.Z)); //System.Windows.Vector smoothedRotation = accelSmoothing.getSmoothedValue(); //rotation = -1 * (Math.Atan2(smoothedRotation.Y, smoothedRotation.X) - (Math.PI / 2.0)); relativePosition.X = relativePosition.X - 0.5F; relativePosition.Y = relativePosition.Y - 0.5F; relativePosition = this.rotatePoint(relativePosition, smoothedRotation); relativePosition.X = relativePosition.X + 0.5F; relativePosition.Y = relativePosition.Y + 0.5F; //relativePosition.X = 1 - relativePosition.X; //relativePosition.Y = 1 - relativePosition.Y; } x = Convert.ToInt32((float)maxWidth * relativePosition.X + minXPos); y = Convert.ToInt32((float)maxHeight * relativePosition.Y + minYPos) + offsetY; if (x <= 0) { x = 0; } else if (x >= primaryScreen.Bounds.Width) { x = primaryScreen.Bounds.Width - 1; } if (y <= 0) { y = 0; } else if (y >= primaryScreen.Bounds.Height) { y = primaryScreen.Bounds.Height - 1; } CursorPos result = new CursorPos(x, y, relativePosition.X, relativePosition.Y, smoothedRotation); lastPos = result; return result; }
/// <summary> /// This is called when the state of the wiimote changes and a new state report is available. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void handleWiimoteChanged(object sender, WiimoteChangedEventArgs e) { // Obtain mutual excluseion. pDeviceMutex.WaitOne(); // If we not running then leave. if (!bRunning) { pDeviceMutex.ReleaseMutex(); return; } Queue <WiiContact> lFrame = new Queue <WiiContact>(1); // Store the state. WiimoteState pState = e.WiimoteState; // Contain active sensor data. List <SpatioTemporalInput> lInputs = new List <SpatioTemporalInput>(); bool pointerOutOfReach = false; WiimoteLib.Point newpoint = lastpoint; CursorPos temp = screenPositionCalculator.CalculateCursorPos(e); newpoint.X = temp.X; newpoint.Y = temp.Y; if (newpoint.X < 0 || newpoint.Y < 0) { newpoint = lastpoint; pointerOutOfReach = true; } //Temporary solution to the "diamond cursor" problem. /* * if (this.changeSystemCursor) * { * try * { * MouseSimulator.RefreshMainCursor(); * } * catch (Exception error) * { * Console.WriteLine(error.ToString()); * } * } */ WiimoteState ws = e.WiimoteState; keyMapper.processWiimoteState(ws); if (!pointerOutOfReach) { if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y)); if (this.touchDownSlave) { duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); } lastpoint = newpoint; lFrame = duoTouch.getFrame(); FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame); this.OnNewFrame(this, pFrame); if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode { this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.ScreenSize.X, (65535 * newpoint.Y) / this.ScreenSize.Y); MouseSimulator.WakeCursor(); //MouseSimulator.SetCursorPosition(newpoint.X, newpoint.Y); } } this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); // Release mutual exclusion. pDeviceMutex.ReleaseMutex(); }
public void updateCursorPosition(CursorPos cursorPosition) { KeymapOutConfig outConfig; if (this.config.TryGetValue("Pointer", out outConfig)) { foreach (IOutputHandler handler in outputHandlers) { ICursorHandler cursorHandler = handler as ICursorHandler; if (cursorHandler != null) { foreach (KeymapOutput output in outConfig.Stack) //Will normally be only one output config { if (output.Cursor) { if (cursorHandler.setPosition(output.Key,cursorPosition)) { break; // we will break for the first accepting handler, for each output key } } } } } } }