Exemple #1
0
        private void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            WiimoteState state = e.WiimoteState;

            BatteryLevel = state.Battery;

            A     = state.ButtonState.A;
            B     = state.ButtonState.B;
            Home  = state.ButtonState.Home;
            Minus = state.ButtonState.Minus;
            Plus  = state.ButtonState.Plus;
            One   = state.ButtonState.One;
            Two   = state.ButtonState.Two;

            Up    = state.ButtonState.Up;
            Down  = state.ButtonState.Down;
            Left  = state.ButtonState.Left;
            Right = state.ButtonState.Right;

            // Nunchuck
            NunchukState nunchuk = state.NunchukState;

            C        = nunchuk.C;
            Z        = nunchuk.Z;
            NunchukX = nunchuk.Joystick.X;
            NunchukY = nunchuk.Joystick.Y;
        }
Exemple #2
0
        public bool handleWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // Obtain mutual excluseion.
            WiimoteMutex.WaitOne();

            bool significant = false;

            try
            {
                WiimoteState ws = e.WiimoteState;
                this.Status.Battery = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);

                significant = keyMapper.processWiimoteState(ws);

                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);
        }
        private void Wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            var direccion = "";

            if (Math.Abs(DateTime.Now.Subtract(ultimoTiempo).Milliseconds) > intervaloTiempo)
            {
                if (e.WiimoteState.ButtonState.Down)
                {
                    direccion = "abajo";
                }
                else if (e.WiimoteState.ButtonState.Up)
                {
                    direccion = "arriba";
                }
                else if (e.WiimoteState.ButtonState.Left)
                {
                    direccion = "izquierda";
                }
                else if (e.WiimoteState.ButtonState.Right)
                {
                    direccion = "derecha";
                }
                else if (e.WiimoteState.ButtonState.Minus)
                {
                    Application.Current.Dispatcher.BeginInvoke(DeshacerMovimiento);
                }
                if (direccion != "")
                {
                    Application.Current.Dispatcher.BeginInvoke(MoverSeleccion, direccion);
                    ultimoTiempo = DateTime.Now;
                }
                direccion = "";
            }
            gestureCapturer.OnWiimoteChanged(e.WiimoteState);
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <String> ProcessSample(object sender, WiimoteChangedEventArgs e)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            if (ProcessCount >= Cap)
            {
                EventHandler <CoordinatesProcessedEventArgs> handler = Processed;
                if (handler != null)
                {
                    try {
                        AccelState[0] = e.WiimoteState.AccelState.RawValues.X;
                        AccelState[1] = e.WiimoteState.AccelState.RawValues.Y;
                        AccelState[2] = e.WiimoteState.AccelState.RawValues.Z;
                        IRState       = stabilizer.Update(e);
                        battery       = (e.WiimoteState.Battery > 100f ? 100 : (int)e.WiimoteState.Battery);

                        Notify(new CoordinatesProcessedEventArgs(((Wiimote)sender).HIDDevicePath, AccelState, IRState, battery, IRState[4]));
                        Reset();
                    }

                    catch (Exception ex)
                    { Console.WriteLine(ex); }
                }
            }
            ProcessCount++;

            return("Done");
        }
Exemple #5
0
 void wm_OnWiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     if (isReady)
     {
         Render();
     }
 }
Exemple #6
0
        private void wiiDevice_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            vypis++;
            WiimoteState ws = e.WiimoteState;

            //Thread.Sleep(500);


            if (vypis % 50 == 0)
            {
                //ws.ExtensionType = ExtensionType.MotionPlus;
                Debug.WriteLine(ws.AccelState.RawValues.ToString());
                Debug.WriteLine(ws.IRState.IRSensors[0].Position.X.ToString() + ws.IRState.IRSensors[0].Position.Y.ToString());
                Debug.WriteLine(ws.IRState.IRSensors[1].Position.X.ToString() + ws.IRState.IRSensors[1].Position.Y.ToString());
                //ws.IRState.IRSensors[0].Found
                Debug.WriteLine("X: " + headX.ToString() + " Y: " + headY.ToString() + " Z: " + headDist.ToString());



                Debug.WriteLine("motplus: " + ws.MotionPlusState.RawValues.ToString());
                Debug.WriteLine("motplusx: " + ws.MotionPlusState.RawValues.X.ToString());
                Debug.WriteLine("motplusy: " + ws.MotionPlusState.RawValues.Y.ToString());
                Debug.WriteLine("motplusz: " + ws.MotionPlusState.RawValues.Z.ToString());
                Debug.WriteLine("ext: " + ws.ExtensionType.ToString());


                vypis = 0;
            }


            // Called every time there is a sensor update, values available using e.WiimoteState.
            // Use this for tracking and filtering rapid accelerometer and gyroscope sensor data.
            // The balance board values are basic, so can be accessed directly only when needed.
        }
Exemple #7
0
        internal void OnChange(object sender, WiimoteChangedEventArgs arg)
        {
            List <Keys> keys = new List <Keys>();

            if (!UseStrum || (Manager.IsGuitarButtonPressed(GuitarButton.Strum_Down) || Manager.IsGuitarButtonPressed(GuitarButton.Strum_Up)))
            {
                if (Manager.IsGuitarButtonPressed(GuitarButton.Fret_Green))
                {
                    keys.Add(KeyData.Key1);
                }
                if (Manager.IsGuitarButtonPressed(GuitarButton.Fret_Red))
                {
                    keys.Add(KeyData.Key2);
                }
                if (Manager.IsGuitarButtonPressed(GuitarButton.Fret_Yellow))
                {
                    keys.Add(KeyData.Key3);
                }
                if (Manager.IsGuitarButtonPressed(GuitarButton.Fret_Blue))
                {
                    keys.Add(KeyData.Key4);
                }
                if (Manager.IsGuitarButtonPressed(GuitarButton.Fret_Orange))
                {
                    keys.Add(KeyData.Key5);
                }
            }

            this.keys = keys;
        }
Exemple #8
0
        private void OnWiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            mx.WaitOne();

            try
            {
                if (isCalibrated)
                {
                    controller.StartHandling(args.WiimoteState);
                }
                else if (calibrating)
                {
                    isCalibrated = calibrator.Calibrate(args.WiimoteState);
                    calibrating  = !isCalibrated;
                    if (isCalibrated)
                    {
                        lastCalibrationData = calibrator.GetCalibrationData();
                    }
                    if (calibrator.HasChanged())
                    {
                        Notify();
                    }
                }
            }
            catch (UserTerminatedException)
            {
                wiimote.Disconnect();
            }

            mx.ReleaseMutex();
        }
Exemple #9
0
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            var ws = args.WiimoteState;

            CheckAction(ws);
            previousBtns = ws.ButtonState;
        }
Exemple #10
0
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            pressingHome = ws.ButtonState.Home;
            if (!easterEgg)
            {
                CheckAction(ws);
            }
            else
            {
                // 裏モード
                // ボタンログ

                var btn = BtnToString(ws.ButtonState);
                if (btn != null)
                {
                    if (btn == "Home")
                    {
                        var com = "";
                        foreach (var b in Log)
                        {
                            com += b;
                        }
                        Debug.WriteLine(com);

                        if (com.Contains("UpUpDownDownLeftRightLeftRightBA") && !dialogShowing)
                        {
                            dialogShowing = true;
                            MessageBox.Show("KONMAI", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dialogShowing = false;
                        }

                        Log.Clear();
                    }
                    else if (Log.Count > 12)
                    {
                        Log.Clear();
                    }
                    else
                    {
                        Log.Enqueue(btn);
                    }
                }

                // 1ボタン + 2ボタンで終了
                if (ws.ButtonState.One && ws.ButtonState.Two)
                {
                    this.Close();
                    Environment.Exit(0);
                }
            }

            previousBtns = ws.ButtonState;

            // バッテリー残量
            statPbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);
            statLblBattery.Text = statPbBattery.Value.ToString() + "%";
        }
Exemple #11
0
 private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     if (recording)
     {
         WiimoteState ws = args.WiimoteState;
         UpdateImage(ws.IRState);
     }
 }
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            // when certain buttons are checked tick box
            clbButtons.SetItemChecked(0, ws.ButtonState.A);
            clbButtons.SetItemChecked(1, ws.ButtonState.B);
            clbButtons.SetItemChecked(2, ws.ButtonState.Minus);
            clbButtons.SetItemChecked(3, ws.ButtonState.Home);
            clbButtons.SetItemChecked(4, ws.ButtonState.Plus);
            clbButtons.SetItemChecked(5, ws.ButtonState.One);
            clbButtons.SetItemChecked(6, ws.ButtonState.Two);
            clbButtons.SetItemChecked(7, ws.ButtonState.Up);
            clbButtons.SetItemChecked(8, ws.ButtonState.Down);
            clbButtons.SetItemChecked(9, ws.ButtonState.Left);
            clbButtons.SetItemChecked(10, ws.ButtonState.Right);

            // sets the values of the accelerometer to lblAccel.Text
            lblAccel.Text = ws.AccelState.Values.ToString();


            switch (ws.ExtensionType)
            {
            case ExtensionType.Nunchuk:
                lblChuk.Text    = ws.NunchukState.AccelState.Values.ToString();
                lblChukJoy.Text = ws.NunchukState.Joystick.ToString();
                chkC.Checked    = ws.NunchukState.C;
                chkZ.Checked    = ws.NunchukState.Z;
                break;


            case ExtensionType.BalanceBoard:
                if (chkLbs.Checked)
                {
                    lblBBTL.Text    = ws.BalanceBoardState.SensorValuesLb.TopLeft.ToString();
                    lblBBTR.Text    = ws.BalanceBoardState.SensorValuesLb.TopRight.ToString();
                    lblBBBL.Text    = ws.BalanceBoardState.SensorValuesLb.BottomLeft.ToString();
                    lblBBBR.Text    = ws.BalanceBoardState.SensorValuesLb.BottomRight.ToString();
                    lblBBTotal.Text = ws.BalanceBoardState.WeightLb.ToString();
                }
                else
                {
                    lblBBTL.Text    = ws.BalanceBoardState.SensorValuesKg.TopLeft.ToString();
                    lblBBTR.Text    = ws.BalanceBoardState.SensorValuesKg.TopRight.ToString();
                    lblBBBL.Text    = ws.BalanceBoardState.SensorValuesKg.BottomLeft.ToString();
                    lblBBBR.Text    = ws.BalanceBoardState.SensorValuesKg.BottomRight.ToString();
                    lblBBTotal.Text = ws.BalanceBoardState.WeightKg.ToString();
                }
                lblCOG.Text = ws.BalanceBoardState.CenterOfGravity.ToString();
                break;
            }

            g.Clear(Color.Black);

            pbBattery.Value    = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);
            lblBattery.Text    = ws.Battery.ToString();
            lblDevicePath.Text = "Device Path: " + mWiimote.HIDDevicePath;
        }
        /// <summary>
        /// Calculates the Cursor Position on Screen by using the Midpoint of the 2 Leds in the sensor bar
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static Point GetPosition(WiimoteChangedEventArgs args)
        {
            int minXPos  = 0;
            int maxXPos  = Util.ScreenWidth;
            int maxWidth = maxXPos - minXPos;
            int x;
            int minYPos   = 0;
            int maxYPos   = Util.ScreenHeight;
            int maxHeight = maxYPos - minYPos;
            int y;

            PointF relativePosition = new PointF();

            if (args.WiimoteState.IRState.IRSensors[0].Found && args.WiimoteState.IRState.IRSensors[1].Found)
            {
                relativePosition = args.WiimoteState.IRState.Midpoint;
            }
            else if (args.WiimoteState.IRState.IRSensors[0].Found)
            {
                relativePosition.X = m_MidSensorPos.X + (args.WiimoteState.IRState.IRSensors[0].Position.X - m_FirstSensorPos.X);
                relativePosition.Y = m_MidSensorPos.Y + (args.WiimoteState.IRState.IRSensors[0].Position.Y - m_FirstSensorPos.Y);
            }
            else if (args.WiimoteState.IRState.IRSensors[1].Found)
            {
                relativePosition.X = m_MidSensorPos.X + (args.WiimoteState.IRState.IRSensors[1].Position.X - m_SecondSensorPos.X);
                relativePosition.Y = m_MidSensorPos.Y + (args.WiimoteState.IRState.IRSensors[1].Position.Y - m_SecondSensorPos.Y);
            }

            //Remember for next run
            m_FirstSensorPos  = args.WiimoteState.IRState.IRSensors[0].Position;
            m_SecondSensorPos = args.WiimoteState.IRState.IRSensors[1].Position;
            m_MidSensorPos    = relativePosition;

            x = Convert.ToInt32((float)maxWidth * (1.0F - relativePosition.X)) + minXPos;
            y = Convert.ToInt32((float)maxHeight * relativePosition.Y) + minYPos;
            if (x < 0)
            {
                x = 0;
            }
            else if (x > Util.ScreenWidth)
            {
                x = Util.ScreenWidth;
            }
            if (y < 0)
            {
                y = 0;
            }
            else if (y > Util.ScreenHeight)
            {
                y = Util.ScreenHeight;
            }

            Point point = new Point();

            point.X = x;
            point.Y = y;
            return(point);
        }
Exemple #14
0
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (e.WiimoteState.IRState.IRSensors[0].Found != lastSensor.on)
            {
                lastSensor = new SensorTime(e.WiimoteState.IRState.IRSensors[0].Found, lastSensor.date);
            }

            lastWMState = e.WiimoteState;
        }
Exemple #15
0
        /// <summary>
        /// Calculates the Cursor Position on Screen by using the Midpoint of the 2 Leds in the sensor bar
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static void SetPosition(WiimoteChangedEventArgs args)
        {
            double minXPos  = 0;
            double maxXPos  = System.Windows.SystemParameters.PrimaryScreenWidth;
            double maxWidth = maxXPos - minXPos;
            double x;
            double minYPos   = 0;
            double maxYPos   = System.Windows.SystemParameters.PrimaryScreenHeight;
            double maxHeight = maxYPos - minYPos;
            double y;

            PointF relativePosition = new PointF();

            if (args.WiimoteState.IRState.IRSensors[0].Found && args.WiimoteState.IRState.IRSensors[1].Found)
            {
                relativePosition = args.WiimoteState.IRState.Midpoint;
            }
            else if (args.WiimoteState.IRState.IRSensors[0].Found)
            {
                relativePosition.X = m_MidSensorPos.X + (args.WiimoteState.IRState.IRSensors[0].Position.X - m_FirstSensorPos.X);
                relativePosition.Y = m_MidSensorPos.Y + (args.WiimoteState.IRState.IRSensors[0].Position.Y - m_FirstSensorPos.Y);
            }
            else if (args.WiimoteState.IRState.IRSensors[1].Found)
            {
                relativePosition.X = m_MidSensorPos.X + (args.WiimoteState.IRState.IRSensors[1].Position.X - m_SecondSensorPos.X);
                relativePosition.Y = m_MidSensorPos.Y + (args.WiimoteState.IRState.IRSensors[1].Position.Y - m_SecondSensorPos.Y);
            }

            //Remember for next run
            m_FirstSensorPos  = args.WiimoteState.IRState.IRSensors[0].Position;
            m_SecondSensorPos = args.WiimoteState.IRState.IRSensors[1].Position;
            m_MidSensorPos    = relativePosition;

            x = Convert.ToInt32((float)maxWidth * (1.0F - relativePosition.X)) + minXPos;
            y = Convert.ToInt32((float)maxHeight * relativePosition.Y) + minYPos;
            if (x < 0)
            {
                x = 0;
            }
            else if (x > System.Windows.SystemParameters.PrimaryScreenWidth)
            {
                x = System.Windows.SystemParameters.PrimaryScreenWidth;
            }
            if (y < 0)
            {
                y = 0;
            }
            else if (y > System.Windows.SystemParameters.PrimaryScreenHeight)
            {
                y = System.Windows.SystemParameters.PrimaryScreenHeight;
            }

            WiimoteLib.Point point = new WiimoteLib.Point();
            point.X = (int)x;
            point.Y = (int)y;
            Win32.SetCursorPos((int)x, (int)y); //set mouse position to wii point
        }
Exemple #16
0
 private void onWiimoteChanged(object i_WiiMote, WiimoteChangedEventArgs i_WiimoteChangedEventArgs)
 {
     m_StateChangedMutex.WaitOne();
     m_CurrentWiiMoteState = i_WiimoteChangedEventArgs.WiimoteState;
     fireInfraRedEvents();
     fireButtonsEvents();
     fireBattteryEvents();
     m_PreviousWiiMoteState = copyWiiMoteState(m_CurrentWiiMoteState);
     m_StateChangedMutex.ReleaseMutex();
 }
        public void WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            if (current >= 0)
            {
                games[current].WiimoteChanged(args.WiimoteState);
            }

            if (big)
            {
                bigGame.WiimoteChanged(args.WiimoteState);
            }
        }
Exemple #18
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;

            Dispatcher.Invoke(new Action(() =>
            {
//                nowtai.Text = ((double)(((int)(bbs.WeightKg*10)))/10).ToString();
//                afetai.Text = ((double)(((int)(bbs.WeightKg*10 + change*10)))/10).ToString();
                nowtai.Text = ((int)(((int)(bbs.WeightKg * 10))) / 10).ToString();
                afetai.Text = ((int)(((int)(bbs.WeightKg * 10 + change * 10))) / 10).ToString();
            }));
        }
Exemple #19
0
 /// <summary>
 /// Delegate method to process the information recieved from the wii remote and sent it to the WiimoteCoordinate.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
 {
     foreach (var aggregator in aggregators)
     {
         if (aggregator != null)
         {
             if (aggregator.Wiimote == (Wiimote)sender)
             {
                 await aggregator.ProcessSample(sender, e);
             }
         }
     }
 }
Exemple #20
0
        private void UpdateWiimoteState(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            for (int j = 0; j < 4; j++)
            {
                if (ws.IRState.IRSensors[j].Found)
                {
                    points[j] = ws.IRState.IRSensors[j].RawPosition;
                    //TODO: Sort points?
                }
            }
        }
Exemple #21
0
        private static void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            var          wiimote = (IWiimote)sender;
            WiimoteState ws      = e.WiimoteState;

            //if (ws.ButtonState.A) Console.WriteLine("A");
            //if (ws.ButtonState.B) Console.WriteLine("B");
            //if (ws.ButtonState.Down) Console.WriteLine("Down");
            //if (ws.ButtonState.Home) Console.WriteLine("Home");
            //if (ws.ButtonState.Left) Console.WriteLine("Left");
            //if (ws.ButtonState.Minus) Console.WriteLine("Minus");
            //if (ws.ButtonState.One) Console.WriteLine("One");
            //if (ws.ButtonState.Plus) Console.WriteLine("Plus");
            //if (ws.ButtonState.Right) Console.WriteLine("Right");
            //if (ws.ButtonState.Two) Console.WriteLine("Two");
            //if (ws.ButtonState.Up) Console.WriteLine("Up");

            if (ws.ButtonState.Home)
            {
                exit = true;
            }

            wiimote.SetRumble(ws.ButtonState.B);

            if (ws.ButtonState.Plus && leds < 8)
            {
                leds = leds << 1;
            }

            if (ws.ButtonState.Minus && leds > 1)
            {
                leds = leds >> 1;
            }

            wiimote.SetLEDs(leds);

            if (ws.ExtensionType == ExtensionType.Nunchuk)
            {
                var ns = ws.NunchukState;

                //if (ns.C) Console.WriteLine("C");
                //if (ns.Z) Console.WriteLine("Z");

                //Console.WriteLine(ns.Joystick);

                var xangle = ns.Joystick.X * -180;
                var yangle = ns.Joystick.Y * 180;

                hexy.SetNeck(xangle);
            }
        }
Exemple #22
0
        public void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            ws.IRState.Mode = IRMode.Basic;
            float x = 0, y = 0;

            x = ws.IRState.IRSensors[0].Position.X;
            y = ws.IRState.IRSensors[0].Position.Y;
            if (ws.IRState.IRSensors[0].Found)
            {
                if ((x < 0.3f || x > 0.7f || y < 0.3f || y > 0.7f) && (((x < 0.3f && (y > 0.3f && y < 0.7f)) || (x > 0.7f && (y < 0.7f && y > 0.3f))) || ((y < 0.3f && (x > 0.3f && x < 0.7f)) || (y > 0.7f && (x < 0.7f && x > 0.3f)))))
                {
                    if (x > 0.7f)
                    {
                        //Izq
                        if (pelota.iquierda != null)
                        {
                            pelota = l.moverIzquierda(pelota);
                        }
                    }
                    else if (x < 0.3f)
                    {
                        //der
                        if (pelota.derecha != null)
                        {
                            pelota = l.moverDerecha(pelota);
                        }
                    }
                    else if (y > 0.7f)
                    {
                        //arriba
                        if (pelota.arriba != null)
                        {
                            pelota = l.moverArriba(pelota);
                        }
                    }
                    else if (y < 0.3f)
                    {
                        //abajo
                        if (pelota.abajo != null)
                        {
                            pelota = l.moverAbajo(pelota);
                        }
                    }
                    pcbPelota.Location = pelota.p;
                    Thread.Sleep(500);
                }
            }
        }
        void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            RawRotation = QuaternionHelper.EulerAnglesInDegToQuaternion(
                e.WiimoteState.MotionPlusState.Values.Y,
                e.WiimoteState.MotionPlusState.Values.X,
                e.WiimoteState.MotionPlusState.Values.Z);

            if (e.WiimoteState.ButtonState.Plus)
            {
                Dispatcher.Invoke((Action)(Calibrate));
            }

            Dispatcher.Invoke((Action)(UpdatePositionAndRotation));
        }
Exemple #24
0
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            //WiimoteStateの値を取得
            if (wiiBBFrameCount % 10 == 0)
            {
                WiimoteState ws = args.WiimoteState;

                //ここでWiiからアレがアレ
                vertex.x = ws.BalanceBoardState.CenterOfGravity.X;
                vertex.y = ws.BalanceBoardState.CenterOfGravity.Y;
                weight   = ws.BalanceBoardState.WeightKg;
                // Debug.WriteLine("vartex : {0} {1}", vartex.x, vartex.y);
            }
            wiiBBFrameCount++;
        }
Exemple #25
0
        public void UpdateState(WiimoteChangedEventArgs args)
        {
            if (InvokeRequired)
            {
                if (!IsHandleCreated)
                {
                    this.CreateControl();
                }

                BeginInvoke(new UpdateWiimoteStateDelegate(UpdateWiimoteChanged), args);
            }
            else
            {
                UpdateWiimoteChanged(args);
            }
        }
Exemple #26
0
        void Wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // get the current Wiimote state
            WiimoteState ws = e.WiimoteState;

            // if button 1 is pressed, toggle the Forward output
            _interfaceKit.outputs[0] = ws.ButtonState.One;

            // if button 2 is pressed, toggle the Backward output
            _interfaceKit.outputs[1] = ws.ButtonState.Two;

            // if the Wiimote is tilted far enough to the left, toggle the Left output
            _interfaceKit.outputs[2] = (ws.AccelState.Values.Y < -0.07f);

            // if the Wiimote is tilted far enough to the right, toggle the Reft output
            _interfaceKit.outputs[3] = (ws.AccelState.Values.Y > 0.07f);
        }
Exemple #27
0
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            // current state information
            WiimoteState ws = args.WiimoteState;


            // If you want to try either the comments to the console or the key presses, you
            // can uncomment the relevant parts of the code, below.

            if (ws.DrumsState.Blue)
            {
                // Console.WriteLine("Blue");
                // pressKey(VK_a);

                blue.Play();
            }
            if (ws.DrumsState.Red)
            {
                // Console.WriteLine("Red");
                //pressKey(VK_b);

                red.Play();
            }
            if (ws.DrumsState.Green)
            {
                //Console.WriteLine("Green");


                green.Play();
                //pressKey(VK_c);
            }
            if (ws.DrumsState.Orange)
            {
                //Console.WriteLine("Orange");

                orange.Play();
                // pressKey(VK_d);
            }
            if (ws.DrumsState.Yellow)
            {
                //Console.WriteLine("Yellow");

                yellow.Play();
                // pressKey(VK_e);
            }
        }
        private void WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            WiiBoardData singleDataPoint = dataMapper.MapFromWiiFormat(e.WiimoteState, this.acquisitionStartedAt);

            LOG.DebugFormat("Current value: topLeftKg={0}, topRightKg={1}, bottomLeftKg={2}, bottomRightKg={3}, weightKg={4}, gravity.X={5}, gravity.Y={6}, Horodate={7}, TIMESTAMP={8}", singleDataPoint.topLeftKg, singleDataPoint.topRightKg, singleDataPoint.bottomLeftKg, singleDataPoint.bottomRightKg, singleDataPoint.weightKg, singleDataPoint.gravity.X, singleDataPoint.gravity.Y, singleDataPoint.Horodate, singleDataPoint.TIMESTAMP);

            if (IsValidData(singleDataPoint))
            {
                WiiBoardDatas.Add(singleDataPoint);
                #if DEBUG
                LOG.DebugFormat("Wiimote callback from ID={0}: data was collected.", ((Wiimote)sender).ID);
                #endif
            }
            else
            {
                LOG.DebugFormat("Wiimote callback from ID={0}: no valid data.", ((Wiimote)sender).ID);
            }
        }
Exemple #29
0
        public void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            // current state information

            Wiimote wm = (Wiimote)sender;

            UpdateWiimoteChanged(args);
            observer.informMainWindow(this, (Wiimote)sender);
            //Change If statements from using "==" to use " Equals " method


            /*if (wm.ID.Equals(wiimote1_info.getWiimoteID()))
             *  observer.OnNext(wiimote1_info);
             * else if (wm.ID.Equals(wiimote2_info.getWiimoteID()))
             *  observer.OnNext(wiimote2_info);
             */
            Console.WriteLine(String.Concat(args.WiimoteState.AccelState.Values.ToString()));
        }
Exemple #30
0
        /// <summary>
        /// If the wii-remotes status changes it means there is a new
        /// accelerometer reading to put on the Queue.
        /// </summary>
        /// <param name="sender">Object initiating the function call.</param>
        /// <param name="args">The wii status message.</param>
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            RawData sample = new RawData();

            sample.accel_x = args.WiimoteState.AccelState.RawValues.X - args.WiimoteState.AccelCalibrationInfo.X0;
            sample.accel_y = args.WiimoteState.AccelState.RawValues.Y - args.WiimoteState.AccelCalibrationInfo.Y0;
            sample.accel_z = args.WiimoteState.AccelState.RawValues.Z - args.WiimoteState.AccelCalibrationInfo.Z0;

            //get the unix timestamp.
            TimeSpan span = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());

            sample.time = (long)span.TotalMilliseconds;

            //Lock the queue while the next sample is added.
            lock (rawDataQueue)
            {
                rawDataQueue.Enqueue(sample);
            }
        }
    // Used for updating the wiimote itself
    // This is where you put output statements to see changes in the wiimote state
    public void UpdateState(WiimoteChangedEventArgs args)
    {
        WiimoteState ws = args.WiimoteState;
        updateSemaphore.WaitOne();
        Console.SetCursorPosition(0, this.WiimoteLED);

        if ((temp = ws.AccelState.Values.X) < 1 && temp > -1)
            buff[0] = xAccel = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.AccelState.Values.Y) < 1 && temp > -1)
            buff[1] = yAccel = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.AccelState.Values.Z) < 1 && temp > -1)
            buff[2] = zAccel = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.NunchukState.AccelState.Values.X) < 1 && temp > -1)
            buff[3] = xNun = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.NunchukState.AccelState.Values.Y) < 1 && temp > -1)
            buff[4] = yNun = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.NunchukState.AccelState.Values.Z) < 1 && temp > -1)
            buff[5] = zNun = Convert.ToByte(temp * 128 + 127);
        if ((temp = ws.NunchukState.Joystick.X) < 0.5 && temp > -0.5)
            buff[6] = xJoy = Convert.ToByte(temp * 256 + 127);
        if ((temp = ws.NunchukState.Joystick.Y) < 0.5 && temp > -0.5)
            buff[7] = yJoy = Convert.ToByte(temp * 256 + 127);
        buff[8] = ABut = Convert.ToByte(ws.ButtonState.A);
        buff[9] = BBut = Convert.ToByte(ws.ButtonState.B);
        buff[10] = OneBut = Convert.ToByte(ws.ButtonState.One);
        buff[11] = TwoBut = Convert.ToByte(ws.ButtonState.Two);
        buff[12] = UpBut = Convert.ToByte(ws.ButtonState.Up);
        buff[13] = DownBut = Convert.ToByte(ws.ButtonState.Down);
        buff[14] = LeftBut = Convert.ToByte(ws.ButtonState.Left);
        buff[15] = RightBut = Convert.ToByte(ws.ButtonState.Right);
        buff[16] = PlusBut = Convert.ToByte(ws.ButtonState.Plus);
        buff[17] = MinusBut = Convert.ToByte(ws.ButtonState.Minus);
        buff[18] = HomeBut = Convert.ToByte(ws.ButtonState.Home);
        buff[19] = CBut = Convert.ToByte(ws.NunchukState.C);
        buff[20] = ZBut = Convert.ToByte(ws.NunchukState.Z);

        if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
        {
            buff[21] = xIR = Convert.ToByte(ws.IRState.IRSensors[0].Position.X*255);
            buff[22] = yIR = Convert.ToByte(ws.IRState.IRSensors[0].Position.Y*255);
           }
        Console.Clear();

        Console.WriteLine("\n\n\n\n\n" +
            xAccel + "     " + yAccel + "     " + zAccel + "\n" +
            xNun + "     " + yNun + "     " + zNun + "\n " +
            xJoy + "     " + yJoy + "     " + "\n" +
            ABut + BBut + OneBut + TwoBut + UpBut + DownBut + LeftBut + RightBut + PlusBut + MinusBut + HomeBut + CBut + ZBut + "\n" +
            xIR + "     " + yIR + "\n");

        if (modCount%10 == 0)
            sp.Write(buff, 0, 23);

        modCount++;
        if (modCount == 32000)
            modCount = 0;

        updateSemaphore.Release();
    }