示例#1
0
        internal override void WiimoteChanged(WiimoteState ws)
        {
            var state = ws.AccelState;

            if(0 > state.Values.Y)
            {
                distance += 0 - state.Values.Y;
            } else
            {
                distance += state.Values.Y - 0;
            }

            if(count++ == 20)
            {
                speed = distance / 20;
                distance = 0;

                count = 0;
            }

            if (fps++ == 10)
            {
                fps = 0;

                UpdateView();
            }
        }
示例#2
0
        internal override void WiimoteChanged(WiimoteState ws)
        {
            var accel = ws.AccelState;

            distanceRawX += (accel.RawValues.X - 127);
            distanceRawY += (accel.RawValues.Y - 104);
            distanceRawZ += (accel.RawValues.Z - 129);
        }
示例#3
0
        public void InternalWiimoteChangedHandler(WiimoteChanged update)
        {
            _state = update.Body;

            // send a msg to our subscribers that the wiimote changed
            SendNotification <WiimoteChanged>(_subMgrPort, update);

            update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
        }
示例#4
0
 // Token: 0x06003039 RID: 12345
 // RVA: 0x00137868 File Offset: 0x00135A68
 internal static bool GetState()
 {
     if (Class808.wiimote_0 == null)
     {
         return false;
     }
     Class808.wiimoteState_0 = Class808.wiimote_0.get_WiimoteState();
     if (Class808.int_0 > 0 && Class808.int_0 <= Class115.int_1)
     {
         Class808.int_0 = -1;
         Class808.wiimote_0.SetRumble(false);
     }
     return Class808.wiimoteState_0 != null;
 }
 internal WiiState(WiimoteState ws)
 {
     ButtonA = ws.ButtonState.A;
     ButtonB = ws.ButtonState.B;
     Minus = ws.ButtonState.Minus;
     Plus = ws.ButtonState.Plus;
     Home = ws.ButtonState.Home;
     Down = ws.ButtonState.Down;
     Up = ws.ButtonState.Up;
     Left = ws.ButtonState.Left;
     Right = ws.ButtonState.Right;
     One = ws.ButtonState.One;
     Two = ws.ButtonState.Two;
     BatteryLevel = ws.Battery;
 }
示例#6
0
        private void DrawForms(WiimoteState ws)
        {
            //pictureBox1のグラフィックスを取得
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Black);     //画面を黒色にクリア

            //X、Y座標の計算
            float x =
                (wm.WiimoteState.BalanceBoardState.CenterOfGravity.X
                + 20.0f) * 10;    //表示位置(X座標)を求める
            float y =
                (wm.WiimoteState.BalanceBoardState.CenterOfGravity.Y
                + 12.0f) * 10;    //表示位置(Y座標)を求める

            //赤色でマーカを描写
            g.FillEllipse(Brushes.Red, x, y, 10, 10);

            g.Dispose();  //グラフィックスを開放
        }
        public void OnWiimoteChanged(WiimoteState state)
        {
            bool buttonBpressed = state.ButtonState.B;
            Point3F sample = state.AccelState.Values;

            if (buttonBpressedOld)
            {
                if (buttonBpressed)
                    gesture.AddSample(new double[] { sample.X, sample.Y, sample.Z });
                else if (GestureCaptured != null)
                    GestureCaptured(gesture);
            }
            else
            {
                if (buttonBpressed)
                    gesture = new Gesture();
                else
                    ; //Nada
            }
            buttonBpressedOld = buttonBpressed;
        }
        internal Wiimote(WiimoteDeviceInfo device)
        {
            this.device    = device;
            disposed       = false;
            ioLock         = new object();
            wiimoteState   = new WiimoteState();
            altWriteMethod = false;

            //mAltWriteMethod = false;

            device.HID.Open();

            try {
                // We're not ready for this yet
                BeginAsyncRead();

                // read the calibration info from the controller
                //ReadWiimoteCalibration();
                try {
                    ReadWiimoteCalibration();
                }
                catch {
                    // if we fail above, try the alternate HID writes
                    //Debug.WriteLine("AltWriteMethod");
                    altWriteMethod = true;
                    ReadWiimoteCalibration();
                }

                // force a status check to get the state of any extensions plugged in at startup
                GetStatus(500);
            }
            catch {
                Dispose();
                throw;
            }
        }
示例#9
0
        //Returns true if anything has changed from last report.
        public bool processWiimoteState(WiimoteState wiimoteState)
        {
            ButtonState buttonState = wiimoteState.ButtonState;
            bool significant = false;

            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.NunchukState.Joystick.Y > 0.3 && !PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickUp);
                }
                 else if (wiimoteState.NunchukState.Joystick.Y < 0.3 && PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickUp);
                }

                 if (wiimoteState.NunchukState.Joystick.Y < -0.3 && !PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickDown);
                }
                 else if (wiimoteState.NunchukState.Joystick.Y > -0.3 && PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickDown);
                }

                 if (wiimoteState.NunchukState.Joystick.X < -0.3 && !PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickLeft);
                }
                else if (wiimoteState.NunchukState.Joystick.X > -0.3 && PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickLeft);
                }
                if (wiimoteState.NunchukState.Joystick.X > 0.3 && !PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickRight);
                }
                else if (wiimoteState.NunchukState.Joystick.X < 0.3 && PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickRight);
                }

            }

            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 (wiimoteState.ClassicControllerState.JoystickL.Y > 0.3 && !PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickLUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLUp);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y < 0.3 && PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickLUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLUp);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.Y < -0.3 && !PressedButtons["Classic.StickLDown"])
                {
                    PressedButtons["Classic.StickLDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLDown);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y > -0.3 && PressedButtons["Classic.StickLDown"])
                {
                    PressedButtons["Classic.StickLDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLDown);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.X < -0.3 && !PressedButtons["Classic.StickLLeft"])
                {
                    PressedButtons["Classic.StickLLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLLeft);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X > -0.3 && PressedButtons["Classic.StickLLeft"])
                {
                    PressedButtons["Classic.StickLLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLLeft);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.X > 0.3 && !PressedButtons["Classic.StickLRight"])
                {
                    PressedButtons["Classic.StickLRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLRight);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X < 0.3 && PressedButtons["Classic.StickLRight"])
                {
                    PressedButtons["Classic.StickLRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLRight);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.Y > 0.3 && !PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickRUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRUp);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y < 0.3 && PressedButtons["Classic.StickRUp"])
                {
                    PressedButtons["Classic.StickRUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRUp);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.Y < -0.3 && !PressedButtons["Classic.StickRDown"])
                {
                    PressedButtons["Classic.StickRDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRDown);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y > -0.3 && PressedButtons["Classic.StickRDown"])
                {
                    PressedButtons["Classic.StickRDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRDown);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.X < -0.3 && !PressedButtons["Classic.StickRLeft"])
                {
                    PressedButtons["Classic.StickRLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRLeft);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X > -0.3 && PressedButtons["Classic.StickRLeft"])
                {
                    PressedButtons["Classic.StickRLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRLeft);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.X > 0.3 && !PressedButtons["Classic.StickRRight"])
                {
                    PressedButtons["Classic.StickRRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRRight);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X < 0.3 && PressedButtons["Classic.StickRRight"])
                {
                    PressedButtons["Classic.StickRRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRRight);
                }
            }

            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.KeyMap.executeButtonUp("Home");
                        }
                    }
                    else
                    {
                        this.KeyMap.executeButtonUp(button.Name);
                    }
                }
            }

            this.KeyMap.XinputDevice.Update(this.KeyMap.XinputReport);

            return significant;
        }
示例#10
0
 /// <summary>
 /// Indicates an update to the Wiimote sensors
 /// </summary>
 /// <param name="state"></param>
 public WiimoteChanged(WiimoteState state)
 {
     this.Body = state ?? new WiimoteState();
 }
示例#11
0
        public static Point? GetPosition(WiimoteState wiimoteState)
        {
            double screenWidth = SystemParameters.PrimaryScreenWidth;
            double screenHeight = SystemParameters.PrimaryScreenHeight;

            PointF relativePosition;
            //if (wiimoteState.IRState.IRSensors[0].Found && wiimoteState.IRState.IRSensors[1].Found)
            //{
            //    relativePosition = wiimoteState.IRState.Midpoint;
            //}
            //else
            if (wiimoteState.IRState.IRSensors[0].Found)
            {
                relativePosition = wiimoteState.IRState.IRSensors[0].Position;
            }
            else
            {
                return null;
            }

            return new Point(screenWidth*(1.0 - relativePosition.X), screenHeight*relativePosition.Y);
        }
    private void WiimoteChanged(object sender, WiimoteChangedEventArgs args)
    {
      WiimoteState ws = args.WiimoteState;

      if (_previousState != null)
      {
        if (ws.ButtonState.A && !_previousState.ButtonState.A) RemoteCallback(Name, "Wiimote_Button:A");
        if (ws.ButtonState.B && !_previousState.ButtonState.B) RemoteCallback(Name, "Wiimote_Button:B");
        if (ws.ButtonState.Home && !_previousState.ButtonState.Home) RemoteCallback(Name, "Wiimote_Button:Home");
        if (ws.ButtonState.Minus && !_previousState.ButtonState.Minus) RemoteCallback(Name, "Wiimote_Button:Minus");
        if (ws.ButtonState.One && !_previousState.ButtonState.One) RemoteCallback(Name, "Wiimote_Button:One");
        if (ws.ButtonState.Plus && !_previousState.ButtonState.Plus) RemoteCallback(Name, "Wiimote_Button:Plus");
        if (ws.ButtonState.Two && !_previousState.ButtonState.Two) RemoteCallback(Name, "Wiimote_Button:Two");

        if (ws.ButtonState.Down && !_previousState.ButtonState.Down) RemoteCallback(Name, "Wiimote_Pad:Down");
        if (ws.ButtonState.Left && !_previousState.ButtonState.Left) RemoteCallback(Name, "Wiimote_Pad:Left");
        if (ws.ButtonState.Right && !_previousState.ButtonState.Right) RemoteCallback(Name, "Wiimote_Pad:Right");
        if (ws.ButtonState.Up && !_previousState.ButtonState.Up) RemoteCallback(Name, "Wiimote_Pad:Up");

        if (ws.ExtensionType == ExtensionType.Nunchuk)
        {
          if (_useNunchukAsMouse) // Use nunchuk as mouse?
          {
            Mouse.MouseEvents mouseButtons = Mouse.MouseEvents.None;

            if (ws.NunchukState.C != _previousState.NunchukState.C)
              mouseButtons |= ws.NunchukState.C ? Mouse.MouseEvents.RightDown : Mouse.MouseEvents.RightUp;

            if (ws.NunchukState.Z != _previousState.NunchukState.Z)
              mouseButtons |= ws.NunchukState.Z ? Mouse.MouseEvents.LeftDown : Mouse.MouseEvents.LeftUp;

            int deltaX = (int) (ws.NunchukState.Joystick.X * 10 * _mouseSensitivity);
            int deltaY = (int) (ws.NunchukState.Joystick.Y * -10 * _mouseSensitivity);

            if (_handleMouseLocally)
            {
              if (deltaX != 0 || deltaY != 0)
                Mouse.Move(deltaX, deltaY, false);

              if (mouseButtons != Mouse.MouseEvents.None)
                Mouse.Button(mouseButtons);
            }
            else
            {
              if (deltaX != 0 || deltaY != 0 || mouseButtons != Mouse.MouseEvents.None)
                MouseCallback(Name, deltaX, deltaY, (int) mouseButtons);
            }
          }
          else
          {
            if (ws.NunchukState.C && !_previousState.NunchukState.C) RemoteCallback(Name, "WiimoteNunchuk_Button:C");
            if (ws.NunchukState.Z && !_previousState.NunchukState.Z) RemoteCallback(Name, "WiimoteNunchuk_Button:Z");
          }
        }

        if (ws.ExtensionType == ExtensionType.ClassicController)
        {
          if (ws.ClassicControllerState.ButtonState.A && !_previousState.ClassicControllerState.ButtonState.A)
            RemoteCallback(Name, "WiimoteClassic_Button:A");
          if (ws.ClassicControllerState.ButtonState.B && !_previousState.ClassicControllerState.ButtonState.B)
            RemoteCallback(Name, "WiimoteClassic_Button:B");
          if (ws.ClassicControllerState.ButtonState.Home && !_previousState.ClassicControllerState.ButtonState.Home)
            RemoteCallback(Name, "WiimoteClassic_Button:Home");
          if (ws.ClassicControllerState.ButtonState.Minus && !_previousState.ClassicControllerState.ButtonState.Minus)
            RemoteCallback(Name, "WiimoteClassic_Button:Minus");
          if (ws.ClassicControllerState.ButtonState.Plus && !_previousState.ClassicControllerState.ButtonState.Plus)
            RemoteCallback(Name, "WiimoteClassic_Button:Plus");
          if (ws.ClassicControllerState.ButtonState.X && !_previousState.ClassicControllerState.ButtonState.X)
            RemoteCallback(Name, "WiimoteClassic_Button:X");
          if (ws.ClassicControllerState.ButtonState.Y && !_previousState.ClassicControllerState.ButtonState.Y)
            RemoteCallback(Name, "WiimoteClassic_Button:Y");
          if (ws.ClassicControllerState.ButtonState.TriggerL &&
              !_previousState.ClassicControllerState.ButtonState.TriggerL)
            RemoteCallback(Name, "WiimoteClassic_Button:TriggerL");
          if (ws.ClassicControllerState.ButtonState.TriggerR &&
              !_previousState.ClassicControllerState.ButtonState.TriggerR)
            RemoteCallback(Name, "WiimoteClassic_Button:TriggerR");
          if (ws.ClassicControllerState.ButtonState.ZL && !_previousState.ClassicControllerState.ButtonState.ZL)
            RemoteCallback(Name, "WiimoteClassic_Button:ZL");
          if (ws.ClassicControllerState.ButtonState.ZR && !_previousState.ClassicControllerState.ButtonState.ZR)
            RemoteCallback(Name, "WiimoteClassic_Button:ZR");

          if (ws.ClassicControllerState.ButtonState.Down && !_previousState.ClassicControllerState.ButtonState.Down)
            RemoteCallback(Name, "WiimoteClassic_Pad:Down");
          if (ws.ClassicControllerState.ButtonState.Left && !_previousState.ClassicControllerState.ButtonState.Left)
            RemoteCallback(Name, "WiimoteClassic_Pad:Left");
          if (ws.ClassicControllerState.ButtonState.Right && !_previousState.ClassicControllerState.ButtonState.Right)
            RemoteCallback(Name, "WiimoteClassic_Pad:Right");
          if (ws.ClassicControllerState.ButtonState.Up && !_previousState.ClassicControllerState.ButtonState.Up)
            RemoteCallback(Name, "WiimoteClassic_Pad:Up");
        }

        if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
        {
          int x = (int)(ScreenWidth - (ws.IRState.IRSensors[0].Position.X + ws.IRState.IRSensors[1].Position.X) / 2 * ScreenWidth);
          int y = (int)((ws.IRState.IRSensors[0].Position.Y + ws.IRState.IRSensors[1].Position.Y) / 2 * ScreenHeight);

          if (_handleMouseLocally)
          {
            Mouse.Move(x, y, true);
          }
          else
          {
            int prevX = (int)(ScreenWidth - (_previousState.IRState.IRSensors[0].Position.X + _previousState.IRState.IRSensors[1].Position.X) / 2 * ScreenWidth);
            int prevY = (int)((_previousState.IRState.IRSensors[0].Position.Y + _previousState.IRState.IRSensors[1].Position.Y) / 2 * ScreenHeight);

            int deltaX = x - prevX;
            int deltaY = y - prevY;

            MouseCallback(Name, deltaX, deltaY, 0);
          }
        }
      }
      else
        _previousState = new WiimoteState();

      //_previousState.AccelCalibrationInfo.X0 = ws.AccelCalibrationInfo.X0;
      //_previousState.AccelCalibrationInfo.XG = ws.AccelCalibrationInfo.XG;
      //_previousState.AccelCalibrationInfo.Y0 = ws.AccelCalibrationInfo.Y0;
      //_previousState.AccelCalibrationInfo.YG = ws.AccelCalibrationInfo.YG;
      //_previousState.AccelCalibrationInfo.Z0 = ws.AccelCalibrationInfo.Z0;
      //_previousState.AccelCalibrationInfo.ZG = ws.AccelCalibrationInfo.ZG;

      //_previousState.AccelState.RawX = ws.AccelState.RawX;
      //_previousState.AccelState.RawY = ws.AccelState.RawY;
      //_previousState.AccelState.RawZ = ws.AccelState.RawZ;
      //_previousState.AccelState.X = ws.AccelState.X;
      //_previousState.AccelState.Y = ws.AccelState.Y;
      //_previousState.AccelState.Z = ws.AccelState.Z;

      //_previousState.Battery = ws.Battery;

      _previousState.ButtonState.A = ws.ButtonState.A;
      _previousState.ButtonState.B = ws.ButtonState.B;
      _previousState.ButtonState.Down = ws.ButtonState.Down;
      _previousState.ButtonState.Home = ws.ButtonState.Home;
      _previousState.ButtonState.Left = ws.ButtonState.Left;
      _previousState.ButtonState.Minus = ws.ButtonState.Minus;
      _previousState.ButtonState.One = ws.ButtonState.One;
      _previousState.ButtonState.Plus = ws.ButtonState.Plus;
      _previousState.ButtonState.Right = ws.ButtonState.Right;
      _previousState.ButtonState.Two = ws.ButtonState.Two;
      _previousState.ButtonState.Up = ws.ButtonState.Up;

      _previousState.Extension = ws.Extension;
      _previousState.ExtensionType = ws.ExtensionType;

      _previousState.IRState.IRSensors = ws.IRState.IRSensors;
      _previousState.IRState.Midpoint = ws.IRState.Midpoint;
      _previousState.IRState.Mode = ws.IRState.Mode;
      _previousState.IRState.RawMidpoint = ws.IRState.RawMidpoint;

      _previousState.NunchukState.C = ws.NunchukState.C;
      _previousState.NunchukState.Z = ws.NunchukState.Z;
    }
示例#13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ws">Wiimote state</param>
 public WiimoteChangedEventArgs(WiimoteState ws)
 {
     WiimoteState = ws;
 }
        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;
        }
 public WiimoteChangedEventArgs(WiimoteState ws)
 {
     this.WiimoteState = ws;
 }
示例#16
0
 internal abstract void WiimoteChanged(WiimoteState ws);
        public void InternalWiimoteChangedHandler(WiimoteChanged update)
        {
            _state = update.Body;

            // send a msg to our subscribers that the wiimote changed
            SendNotification<WiimoteChanged>(_subMgrPort, update);

            update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
        }
示例#18
0
        private void SetWiimoteState(int in_iMote, WiimoteState in_ws)
        {
            if (this.WindowState == FormWindowState.Normal && tabControl.SelectedIndex == 1)
            {
                if (in_iMote != comboBoxWiimotes.SelectedIndex) return;

                clbButtons.SetItemChecked(0, in_ws.ButtonState.A);
                clbButtons.SetItemChecked(1, in_ws.ButtonState.B);
                clbButtons.SetItemChecked(2, in_ws.ButtonState.Minus);
                clbButtons.SetItemChecked(3, in_ws.ButtonState.Home);
                clbButtons.SetItemChecked(4, in_ws.ButtonState.Plus);
                clbButtons.SetItemChecked(5, in_ws.ButtonState.One);
                clbButtons.SetItemChecked(6, in_ws.ButtonState.Two);
                clbButtons.SetItemChecked(7, in_ws.ButtonState.Up);
                clbButtons.SetItemChecked(8, in_ws.ButtonState.Down);
                clbButtons.SetItemChecked(9, in_ws.ButtonState.Left);
                clbButtons.SetItemChecked(10, in_ws.ButtonState.Right);
                clbButtons.SetItemChecked(11, in_ws.NunchukState.C);
                clbButtons.SetItemChecked(12, in_ws.NunchukState.Z);

                lblX.Text = in_ws.AccelState.X.ToString();
                lblY.Text = in_ws.AccelState.Y.ToString();
                lblZ.Text = in_ws.AccelState.Z.ToString();

                if (in_ws.ExtensionType == ExtensionType.Nunchuk)
                {
                    lblChukX.Text = in_ws.NunchukState.AccelState.X.ToString();
                    lblChukY.Text = in_ws.NunchukState.AccelState.Y.ToString();
                    lblChukZ.Text = in_ws.NunchukState.AccelState.Z.ToString();

                    lblChukJoyX.Text = in_ws.NunchukState.X.ToString();
                    lblChukJoyY.Text = in_ws.NunchukState.Y.ToString();
                }

                if (in_ws.IRState.Found1)
                {
                    lblIR1.Text = in_ws.IRState.X1.ToString() + ", " + in_ws.IRState.Y1.ToString() + ", " + in_ws.IRState.Size1;
                    lblIR1Raw.Text = in_ws.IRState.RawX1.ToString() + ", " + in_ws.IRState.RawY1.ToString();
                }
                if (in_ws.IRState.Found2)
                {
                    lblIR2.Text = in_ws.IRState.X2.ToString() + ", " + in_ws.IRState.Y2.ToString() + ", " + in_ws.IRState.Size2;
                    lblIR2Raw.Text = in_ws.IRState.RawX2.ToString() + ", " + in_ws.IRState.RawY2.ToString();
                }
                if (in_ws.IRState.Found3)
                {
                    lblIR3.Text = in_ws.IRState.X3.ToString() + ", " + in_ws.IRState.Y3.ToString() + ", " + in_ws.IRState.Size3;
                    lblIR3Raw.Text = in_ws.IRState.RawX3.ToString() + ", " + in_ws.IRState.RawY3.ToString();
                }
                if (in_ws.IRState.Found4)
                {
                    lblIR4.Text = in_ws.IRState.X4.ToString() + ", " + in_ws.IRState.Y4.ToString() + ", " + in_ws.IRState.Size4;
                    lblIR4Raw.Text = in_ws.IRState.RawX4.ToString() + ", " + in_ws.IRState.RawY4.ToString();
                }

                chkFound1.Checked = in_ws.IRState.Found1;
                chkFound2.Checked = in_ws.IRState.Found2;
                chkFound3.Checked = in_ws.IRState.Found3;
                chkFound4.Checked = in_ws.IRState.Found4;

                pbBattery.Value = (in_ws.Battery > 0xc8 ? 0xc8 : (int)in_ws.Battery);
                float f = (((100.0f * 48.0f * (float)(in_ws.Battery / 48.0f))) / 192.0f);
                lblBattery.Text = f.ToString("F") + "%";

                m_graphic.Clear(Color.Black);
                if (in_ws.IRState.Found1)
                    m_graphic.DrawEllipse(new Pen(Color.Red, 3), (int)(in_ws.IRState.RawX1 / 4), (int)(in_ws.IRState.RawY1 / 4), in_ws.IRState.Size1 + 1, in_ws.IRState.Size1 + 1);
                if (in_ws.IRState.Found2)
                    m_graphic.DrawEllipse(new Pen(Color.Blue, 3), (int)(in_ws.IRState.RawX2 / 4), (int)(in_ws.IRState.RawY2 / 4), in_ws.IRState.Size2 + 1, in_ws.IRState.Size2 + 1);
                if (in_ws.IRState.Found3)
                    m_graphic.DrawEllipse(new Pen(Color.Yellow, 3), (int)(in_ws.IRState.RawX3 / 4), (int)(in_ws.IRState.RawY3 / 4), in_ws.IRState.Size3 + 1, in_ws.IRState.Size3 + 1);
                if (in_ws.IRState.Found4)
                    m_graphic.DrawEllipse(new Pen(Color.Orange, 3), (int)(in_ws.IRState.RawX4 / 4), (int)(in_ws.IRState.RawY4 / 4), in_ws.IRState.Size4 + 1, in_ws.IRState.Size4 + 1);
                if (in_ws.IRState.Found1 && in_ws.IRState.Found2)
                    m_graphic.DrawEllipse(new Pen(Color.Green), (int)(in_ws.IRState.RawMidX / 4), (int)(in_ws.IRState.RawMidY / 4), 2, 2);
                pbIR.Image = m_bitmap;
            }
            else
            {
                if (in_iMote < 0 || in_iMote >= m_configManager.m_lstKeyConfig.Count) return;

                KeyConfig keyConfig = m_configManager.m_lstKeyConfig[in_iMote];

                if (keyConfig.bJoystick)
                {
                    m_HE.ResetJoy();

                    m_HE.SetJoyState(keyConfig.A, in_ws.ButtonState.A);
                    m_HE.SetJoyState(keyConfig.B, in_ws.ButtonState.B);
                    m_HE.SetJoyState(keyConfig.Minus, in_ws.ButtonState.Minus);
                    m_HE.SetJoyState(keyConfig.Home, in_ws.ButtonState.Home);
                    m_HE.SetJoyState(keyConfig.Plus, in_ws.ButtonState.Plus);
                    m_HE.SetJoyState(keyConfig.One, in_ws.ButtonState.One);
                    m_HE.SetJoyState(keyConfig.Two, in_ws.ButtonState.Two);
                    m_HE.SetJoyState(keyConfig.Up, in_ws.ButtonState.Up);
                    m_HE.SetJoyState(keyConfig.Down, in_ws.ButtonState.Down);
                    m_HE.SetJoyState(keyConfig.Left, in_ws.ButtonState.Left);
                    m_HE.SetJoyState(keyConfig.Right, in_ws.ButtonState.Right);
                    m_HE.SetJoyState(keyConfig.C, in_ws.NunchukState.C);
                    m_HE.SetJoyState(keyConfig.Z, in_ws.NunchukState.Z);
                }

                else
                {
                    SendKey(keyConfig.A, in_ws.ButtonState.A);
                    SendKey(keyConfig.B, in_ws.ButtonState.B);
                    SendKey(keyConfig.Minus, in_ws.ButtonState.Minus);
                    SendKey(keyConfig.Home, in_ws.ButtonState.Home);
                    SendKey(keyConfig.Plus, in_ws.ButtonState.Plus);
                    SendKey(keyConfig.One, in_ws.ButtonState.One);
                    SendKey(keyConfig.Two, in_ws.ButtonState.Two);
                    SendKey(keyConfig.Up, in_ws.ButtonState.Up);
                    SendKey(keyConfig.Down, in_ws.ButtonState.Down);
                    SendKey(keyConfig.Left, in_ws.ButtonState.Left);
                    SendKey(keyConfig.Right, in_ws.ButtonState.Right);
                    SendKey(keyConfig.C, in_ws.NunchukState.C);
                    SendKey(keyConfig.Z, in_ws.NunchukState.Z);
                }

                int dx = 0;
                int dy = 0;
                int nFound = 0;
                if (in_ws.IRState.Found1)
                {
                    dx += (int)((in_ws.IRState.X1 - 0.5) * 50.0);
                    dy += (int)(-(in_ws.IRState.Y1 - 0.5) * 50.0);
                    nFound++;
                }
                if (in_ws.IRState.Found2)
                {
                    dx += (int)((in_ws.IRState.X2 - 0.5) * 50.0);
                    dy += (int)(-(in_ws.IRState.Y2 - 0.5) * 50.0);
                    nFound++;
                }
                if (in_ws.IRState.Found1)
                {
                    dx += (int)((in_ws.IRState.X1 - 0.5) * 50.0);
                    dy += (int)(-(in_ws.IRState.Y1 - 0.5) * 50.0);
                    nFound++;
                }
                if (in_ws.IRState.Found1)
                {
                    dx += (int)((in_ws.IRState.X1 - 0.5) * 50.0);
                    dy += (int)(-(in_ws.IRState.Y1 - 0.5) * 50.0);
                    nFound++;
                }
                if (keyConfig.bMouse == true && nFound > 0) m_HE.MoveMouse(dx / nFound, dy / nFound);

                if (in_ws.ExtensionType == ExtensionType.Nunchuk)
                {
                    if (keyConfig.bJoystick)
                    {
                        m_HE.SetJoyState(keyConfig.NunchukLeft, in_ws.NunchukState.X);
                        m_HE.SetJoyState(keyConfig.NunchukUp, -in_ws.NunchukState.Y);
                    }
                    else
                    {
                        SendKey(keyConfig.NunchukRight, in_ws.NunchukState.X > m_fNunchukDelta);
                        SendKey(keyConfig.NunchukLeft, in_ws.NunchukState.X < -m_fNunchukDelta);
                        SendKey(keyConfig.NunchukUp, in_ws.NunchukState.Y > m_fNunchukDelta);
                        SendKey(keyConfig.NunchukDown, in_ws.NunchukState.Y < -m_fNunchukDelta);
                    }
                }
                if (keyConfig.bJoystick) m_HE.SendJoy();
            }
        }
示例#19
0
        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 void Update(WiimoteState ws)
 {
     // todo: reduce redundancy
     if (ws.ButtonState.A != A)
     {
         if (ws.ButtonState.A == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.A, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.A, true);
         }
     }
     if (ws.ButtonState.B != B)
     {
         if (ws.ButtonState.B == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.B, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.B, true);
         }
     }
     if (ws.ButtonState.Up != Up)
     {
         if (ws.ButtonState.Up == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Up, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Up, true);
         }
     }
     if (ws.ButtonState.Down != Down)
     {
         if (ws.ButtonState.Down == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Down, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Down, true);
         }
     }
     if (ws.ButtonState.Left != Left)
     {
         if (ws.ButtonState.Left == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Left, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Left, true);
         }
     }
     if (ws.ButtonState.Right != Right)
     {
         if (ws.ButtonState.Right == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Right, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Right, true);
         }
     }
     if (ws.ButtonState.Home != Home)
     {
         if (ws.ButtonState.Home == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Home, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Home, true);
         }
     }
     if (ws.ButtonState.Plus != Plus)
     {
         if (ws.ButtonState.Plus == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Plus, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Plus, true);
         }
     }
     if (ws.ButtonState.Minus != Minus)
     {
         if (ws.ButtonState.Minus == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Minus, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Minus, true);
         }
     }
     if (ws.ButtonState.One != One)
     {
         if (ws.ButtonState.One == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.One, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.One, true);
         }
     }
     if (ws.ButtonState.Two != Two)
     {
         if (ws.ButtonState.Two == true)
         {
             // Button Up
             ReturnStatusUpdate(Button.Two, false);
         }
         else
         {
             // Button Down
             ReturnStatusUpdate(Button.Two, true);
         }
     }
     A = ws.ButtonState.A;
     B = ws.ButtonState.B;
     Up = ws.ButtonState.Up;
     Down = ws.ButtonState.Down;
     Left = ws.ButtonState.Left;
     Right = ws.ButtonState.Right;
     Home = ws.ButtonState.Home;
     Plus = ws.ButtonState.Plus;
     Minus = ws.ButtonState.Minus;
     One = ws.ButtonState.One;
     Two = ws.ButtonState.Two;
 }
示例#21
0
        internal override void WiimoteChanged(WiimoteState ws)
        {
            x = CalibrateX(ws.IRState.Midpoint.X);
            y = CalibrateY(ws.IRState.Midpoint.Y);

            if (timer.Enabled)
            {
                if (x >= recPos.X && x <= recPos.X + RectangleSize && y >= recPos.Y && y <= recPos.Y + RectangleSize && ws.ButtonState.B)
                {
                    win--;

                    if (win == 0)
                    {
                        state = State.Won;
                        Console.WriteLine("WON");
                    }
                    else
                    {
                        Wm.SetRumble(true);
                    }

                    var randx = (float)(rnd.NextDouble() * Width) - RectangleSize;
                    var randy = (float)(rnd.NextDouble() * Height)- RectangleSize;

                    recPos.X = randx > 0 ? randx : 0;
                    recPos.Y = randy > 0 ? randy : 0;
                }
            }
        }
        /// <summary>
        /// Calculates difference between the curent coordinates and the previous coordinates recieved from the remote.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public PointF Stabilize(WiimoteState e)
        {
            PointF AvgDelta;
            AvgDelta.X = 0;
            AvgDelta.Y = 0;
            PointF[] delta = new PointF[4];

            int increment = 0;

            for(int i = 0; i < 4; i++)
            {
                if (e.IRState.IRSensors[i].Found)
                {
                    delta[i].X = e.IRState.IRSensors[i].Position.X - prev_IRState[i].X;
                    delta[i].Y = e.IRState.IRSensors[i].Position.Y - prev_IRState[i].Y;
                }
                else
                {
                    delta[i].X = float.NaN;
                    delta[i].Y = float.NaN;
                }
            }

            foreach (var D in delta)
            {
                if (!float.IsNaN(D.X) && !float.IsNaN(D.Y))
                {
                    AvgDelta.X += D.X;
                    AvgDelta.Y += D.Y;
                    increment++;
                }
            }

            AvgDelta.X = AvgDelta.X / increment;
            AvgDelta.Y = AvgDelta.Y / increment;
            
            return AvgDelta;

        }
示例#23
0
        //Returns true if anything has changed from last report.
        public bool processWiimoteState(WiimoteState wiimoteState)
        {
            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;
        }
示例#24
0
        internal override void WiimoteChanged(WiimoteState ws)
        {
            buttonState = ws.ButtonState;

            UpdateView();
        }
示例#25
0
 private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     wmState = args.WiimoteState;
 }
示例#26
0
        internal override void WiimoteChanged(WiimoteState ws)
        {
            x = CalibrateX(ws.IRState.Midpoint.X);
            y = CalibrateY(ws.IRState.Midpoint.Y);

            if (fps++ == 1)
            {
                fps = 0;

                UpdateView();
            }
        }