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;
        }
#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";

        }
 private void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
 {
     if (Kart != null)
     {
         Kart.Acceleration = e.WiimoteState.ButtonState.A ? 1 : 0;
         Kart.Acceleration -= e.WiimoteState.ButtonState.B ? 1 : 0;
         Kart.TurnMultiplier = -e.WiimoteState.NunchukState.Joystick.X * 2;
     }
 }
Beispiel #4
0
        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));
        }
        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()));
        }
Beispiel #6
0
        private static void wm_WiimoteChanged(object obj, WiimoteChangedEventArgs e)
        {
            // Data buffer for incoming data. // 1024
            byte[] dIN = new byte[1024];

            // Outgoing data
            float x = ((int)(e.WiimoteState.NunchukState.Joystick.X * 200)) / 100F;
            float y = ((int)(e.WiimoteState.NunchukState.Joystick.Y * 200)) / 100F;

            byte btn2 = 0;
            btn2 |= (byte)((e.WiimoteState.ButtonState.A   ? 1 : 0) << 0);
            btn2 |= (byte)((e.WiimoteState.ButtonState.B   ? 1 : 0) << 1);
            btn2 |= (byte)((e.WiimoteState.ButtonState.One ? 1 : 0) << 2);
            btn2 |= (byte)((e.WiimoteState.ButtonState.Two ? 1 : 0) << 3);
            btn2 |= (byte)((e.WiimoteState.NunchukState.C  ? 1 : 0) << 4);
            btn2 |= (byte)((e.WiimoteState.NunchukState.Z  ? 1 : 0) << 5);

            if (e.WiimoteState.ButtonState.Home)
            {
                // send disconnect signal
                btn2 |= 1 << 7;
            }

            List<byte> msg = new List<byte>();
            msg.Add(btn2);
            msg.AddRange(BitConverter.GetBytes(x));
            msg.AddRange(BitConverter.GetBytes(y));

            // Send the data through the socket.
            if (sender != null && (btn2 != btnOld || e.WiimoteState.NunchukState.Z))
            {
                try
                {
                    int bytesSent = sender.Send(msg.ToArray());
                    Console.WriteLine("{2}\tx: {0}\ty: {1}", x, y, e.WiimoteState.ButtonState.B);

                    // Receive the response from the remote device.
                    int bytesRec = sender.Receive(dIN);

                    btnOld = btn2;
                    Console.WriteLine("Echoed test = {0}", Convert.ToString(msg[0], 2));
                }
                catch { }
            }

            if (e.WiimoteState.ButtonState.Home) EndConnection();
        }
Beispiel #7
0
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            //WiimoteStateの値を取得
            WiimoteState ws = e.WiimoteState;

            //ピクチャーボックスへ描画
            this.DrawForms(ws);

            //ラベル

            //重さ(Kg)表示
            this.label1.Text = ws.BalanceBoardState.WeightKg + "kg";
            //重心のX座標表示
            this.label2.Text = "X:" +
                ws.BalanceBoardState.CenterOfGravity.X;
            //重心のY座標表示
            this.label3.Text = "Y:" +
                ws.BalanceBoardState.CenterOfGravity.Y;
        }
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (_firstValue == true && e.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight != 0)
            {
                _firstState = e.WiimoteState.BalanceBoardState;
                _firstValue = false;
            }

            //Sensorwerte normieren
            float bl = e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft - _firstState.SensorValuesKg.BottomLeft;
            float br = e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight - _firstState.SensorValuesKg.BottomRight;
            float tl = e.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft - _firstState.SensorValuesKg.TopLeft;
            float tr = e.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight - _firstState.SensorValuesKg.TopRight;
            //float wkg = e.WiimoteState.BalanceBoardState.WeightKg;

            //NEuberechnug des Gewichts und des SChwerpunktes
            float wkg = (tl + tr + bl + br) / 4.0f;

            float x = 0, y = 0;
            if (tr != 0 && br != 0 && bl != 0 && tl != 0)
            {
                float Kx = (tl + bl) / (tr + br);
                float Ky = (tl + tr) / (bl + br);

                x = ((float)(Kx - 1) / (float)(Kx + 1)) * (float)(-BSL / 2);
                y = ((float)(Ky - 1) / (float)(Ky + 1)) * (float)(-BSW / 2);
            }

            //float x = e.WiimoteState.BalanceBoardState.CenterOfGravity.X;
            //float y = e.WiimoteState.BalanceBoardState.CenterOfGravity.Y;

            SensorData data = new SensorData(bl, br, tl, tr, wkg, new SensorData.CenterOfGravity(x, y));
            SendSensorData(data);

            float battery = e.WiimoteState.Battery;
            SendBatteryStat(battery);
        }
Beispiel #9
0
        void innerWiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            WiimoteState ws = innerWiimote.WiimoteState;

            if (float.IsInfinity(ws.AccelState.Values.Y))
                return;

            if (double.IsInfinity(lastY))
            {
                lastY = ws.AccelState.Values.Y;
                return;
            }

            OnWiimoteChanged(e);

            lastY = ws.AccelState.Values.Y;
        }
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            int joyXConverted = 0;
            int joyYConverted = 0;

            # region Joystick/Driving Motor control

            // Check to make sure the nunchuck is connected.
            if (wm.WiimoteState.ExtensionType == ExtensionType.Nunchuk)
            {
                //if (timeElapsed % 10 == 0)
                {
                    // Get the joystick values from the nunchuck
                    joyXConverted = ((wm.WiimoteState.NunchukState.RawJoystick.X * 180/255) - 94)/4;
                    joyYConverted = ((wm.WiimoteState.NunchukState.RawJoystick.Y * 180/255) - 91)/4;

                    //if ((JoyXOld != joyXConverted) || (JoyYOld != joyYConverted))
                    //if (timeElapsed % 10 == 0)
                    {
                        // Enter turning mode if the 'C' button is held down.
                        if (wm.WiimoteState.NunchukState.C)
                        {
                            sendMotorParams(joyXConverted, joyXConverted, joyXConverted, joyXConverted);
                            //sendMotorParams(0, 0, 0, 0);
                        }
                        // Otherwise default to translating mode.
                        else
                        {
                            // See page 4 of Designing Omni-Directional Mobile Robot with Mecanum Wheel
                            // in the mecanum_wheel directory for more information on how the wheels should
                            // be actuated properly.
                            sendMotorParams(joyYConverted + joyXConverted, -(joyYConverted - joyXConverted),
                                joyYConverted - joyXConverted, -(joyYConverted + joyXConverted));
                            //sendMotorParams(0, 0, 0, 0);
                        }
                    }
                }
                timeElapsed++;
                JoyXOld = joyXConverted;
                JoyYOld = joyYConverted;
            }

            # endregion

            # region Wiimote buttons/gripper and cutter control

            // Use the B button to toggle the state of the gripper. btnBFlag
            // must be false so that only one button press will be processed
            // at a time. (i.e. holding down the button will have no effect
            // beyond the initial press).
            if (wm.WiimoteState.ButtonState.B && !btnBFlag)
            {
                toggleGripper();
                btnBFlag = true;
            }

            // When the B button is released, set the btnBFlag flag to false
            // so that a new button press will be recognized.
            if (!wm.WiimoteState.ButtonState.B)
                btnBFlag = false;

            // Use the Home button to toggle the state of the cutter.  Works
            // the same way as the B button (above).
            if (wm.WiimoteState.ButtonState.Home && !btnHomeFlag)
            {
                toggleCutter();
                btnHomeFlag = true;
            }

            // set btnHomeFlag flag to false when the Home button is released.
            if (!wm.WiimoteState.ButtonState.Home)
                btnHomeFlag = false;

            # endregion

            # region Arm control

            // TODO: Forward and Inverse Kinematics of the arm once we get
            //       it back from the machine shop and get all the measurements.
            //       We also need to figure out how we're going to map accelerometer
            //       movement to movement of the arm.
            if (wm.WiimoteState.ButtonState.A)
            {
                //MoveArm(wm.WiimoteState.AccelState.RawValues.X, wm.WiimoteState.AccelState.RawValues.Y, 1);
                MoveArm(5, 5, 5);
            }

            # endregion
        }
        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;
        }
Beispiel #12
0
 protected virtual void OnWiimoteChanged(WiimoteChangedEventArgs e)
 {
     if (WiimoteChanged != null)
         WiimoteChanged(this, e);
 }
Beispiel #13
0
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            var ws = args.WiimoteState;

            for (int i = 0; i < 4; i++)
            {
                if (ws.IRState.IRSensors[i].Found)
                {
                    // Check for spell action
                    trigger = wandTracker.addPosition(ws.IRState.IRSensors[i].RawPosition, DateTime.Now);
                    break;
                }
            }

            if (trigger != null) // && trigger.casting())
            {
                spellAction();
            }

            drawWandMovement();
        }
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            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);

            lblAccel.Text = ws.AccelState.Values.ToString();

            chkLED1.Checked = ws.LEDState.LED1;
            chkLED2.Checked = ws.LEDState.LED2;
            chkLED3.Checked = ws.LEDState.LED3;
            chkLED4.Checked = ws.LEDState.LED4;

            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.ClassicController:
                    clbCCButtons.SetItemChecked(0, ws.ClassicControllerState.ButtonState.A);
                    clbCCButtons.SetItemChecked(1, ws.ClassicControllerState.ButtonState.B);
                    clbCCButtons.SetItemChecked(2, ws.ClassicControllerState.ButtonState.X);
                    clbCCButtons.SetItemChecked(3, ws.ClassicControllerState.ButtonState.Y);
                    clbCCButtons.SetItemChecked(4, ws.ClassicControllerState.ButtonState.Minus);
                    clbCCButtons.SetItemChecked(5, ws.ClassicControllerState.ButtonState.Home);
                    clbCCButtons.SetItemChecked(6, ws.ClassicControllerState.ButtonState.Plus);
                    clbCCButtons.SetItemChecked(7, ws.ClassicControllerState.ButtonState.Up);
                    clbCCButtons.SetItemChecked(8, ws.ClassicControllerState.ButtonState.Down);
                    clbCCButtons.SetItemChecked(9, ws.ClassicControllerState.ButtonState.Left);
                    clbCCButtons.SetItemChecked(10, ws.ClassicControllerState.ButtonState.Right);
                    clbCCButtons.SetItemChecked(11, ws.ClassicControllerState.ButtonState.ZL);
                    clbCCButtons.SetItemChecked(12, ws.ClassicControllerState.ButtonState.ZR);
                    clbCCButtons.SetItemChecked(13, ws.ClassicControllerState.ButtonState.TriggerL);
                    clbCCButtons.SetItemChecked(14, ws.ClassicControllerState.ButtonState.TriggerR);

                    lblCCJoy1.Text = ws.ClassicControllerState.JoystickL.ToString();
                    lblCCJoy2.Text = ws.ClassicControllerState.JoystickR.ToString();

                    lblTriggerL.Text = ws.ClassicControllerState.TriggerL.ToString();
                    lblTriggerR.Text = ws.ClassicControllerState.TriggerR.ToString();
                    break;

                case ExtensionType.Guitar:
                    clbGuitarButtons.SetItemChecked(0, ws.GuitarState.ButtonState.Green);
                    clbGuitarButtons.SetItemChecked(1, ws.GuitarState.ButtonState.Red);
                    clbGuitarButtons.SetItemChecked(2, ws.GuitarState.ButtonState.Yellow);
                    clbGuitarButtons.SetItemChecked(3, ws.GuitarState.ButtonState.Blue);
                    clbGuitarButtons.SetItemChecked(4, ws.GuitarState.ButtonState.Orange);
                    clbGuitarButtons.SetItemChecked(5, ws.GuitarState.ButtonState.Minus);
                    clbGuitarButtons.SetItemChecked(6, ws.GuitarState.ButtonState.Plus);
                    clbGuitarButtons.SetItemChecked(7, ws.GuitarState.ButtonState.StrumUp);
                    clbGuitarButtons.SetItemChecked(8, ws.GuitarState.ButtonState.StrumDown);

                    lblGuitarJoy.Text = ws.GuitarState.Joystick.ToString();
                    lblGuitarWhammy.Text = ws.GuitarState.WhammyBar.ToString();
                    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);

            UpdateIR(ws.IRState.IRSensors[0], lblIR1, lblIR1Raw, chkFound1, Color.Red);
            UpdateIR(ws.IRState.IRSensors[1], lblIR2, lblIR2Raw, chkFound2, Color.Blue);
            UpdateIR(ws.IRState.IRSensors[2], lblIR3, lblIR3Raw, chkFound3, Color.Yellow);
            UpdateIR(ws.IRState.IRSensors[3], lblIR4, lblIR4Raw, chkFound4, Color.Orange);

            if(ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
                g.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidpoint.X / 4), (int)(ws.IRState.RawMidpoint.Y / 4), 2, 2);

            pbIR.Image = b;

            pbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);
            lblBattery.Text = ws.Battery.ToString();
            lblDevicePath.Text = "Device Path: " + mWiimote.HIDDevicePath;
        }
Beispiel #15
0
        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            if(args.WiimoteState.ButtonState.A)
                _translation = new Vector3(_translation.X + 0.1f, _translation.Y, _translation.Z);
            if (args.WiimoteState.ButtonState.B)
                _translation = new Vector3(_translation.X - 0.1f, _translation.Y, _translation.Z);

            if(args.WiimoteState.AccelState.Values.X > 0.5)
                _rotationz = _rotationz - 0.1f;

            if (args.WiimoteState.AccelState.Values.X < -0.5)
                _rotationz = _rotationz + 0.1f;
        }
 private void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
 {
     HeadTracking(e.WiimoteState.IRState);
 }
Beispiel #17
0
 private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     BeginInvoke(new UpdateWiimoteStateDelegate(UpdateWiimoteState), args);
 }
Beispiel #18
0
        /*
         * This event handler is called any time the wiimote's state changes. This
         * includes acceleration data (waggle).
         */
        void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            x = (int)(args.WiimoteState.AccelState.X * 100) + 100;
            y = (int)(args.WiimoteState.AccelState.Y * 100) + 100;
            z = (int)(args.WiimoteState.AccelState.Z * 100) + 100;

            if (x <= 0) {
                x = 1;
            }

            if (y <= 0) {
                y = 1;
            }

            if (z <= 0) {
                z = 1;
            }

            if (x > 90 && x < 110) {
                x = 0;
            }

            if (y > 90 && y < 110) {
                y = 0;
            }

            if (z > 90 && z < 110) {
                z = 0;
            }

            // NOTE: Disabled to keep from accidentally dis-/reconnecting while testing
            //if (args.WiimoteState.ButtonState.A && m_bConnected) {
            //    reconnect();
            //}

            //if (args.WiimoteState.ButtonState.B && m_bConnected) {
            //    disconnect();

            //    bRunning = false;
            //}
        }
Beispiel #19
0
 void WiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     gamePanel.WiimoteChanged(sender, args);
 }
Beispiel #20
0
        private void UpdateWiimoteState(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            // Check the IR1 state
            if (ws.IRState.Found1)
            {
                this.WiiMote_CameraY = ws.IRState.Y1;
                lblIR1.Text = ws.IRState.X1.ToString() + ", " + ws.IRState.Y1.ToString() + ", " + ws.IRState.Size1;
                lblIR1Raw.Text = ws.IRState.RawX1.ToString() + ", " + ws.IRState.RawY1.ToString();

                if (cbRun.Checked)
                {
                    NoteOn( ws.IRState.RawX1, ws.IRState.RawY1 );
                }
            }
            else
            {
                if (cbRun.Checked)
                {
                    NoteOff();
                    LastNoteNo = 255; //Clear
                }
            }

            // Update the tracking status - only if the IR state changes
            if ((bLED1 != ws.IRState.Found1) ||
                (bLED2 != ws.IRState.Found2) ||
                (bLED3 != ws.IRState.Found3) ||
                (bLED4 != ws.IRState.Found4))
            {
                wm.SetLEDs(ws.IRState.Found1, ws.IRState.Found2, ws.IRState.Found3, ws.IRState.Found4);
                bLED1 = ws.IRState.Found1;
                bLED2 = ws.IRState.Found2;
                bLED3 = ws.IRState.Found3;
                bLED4 = ws.IRState.Found4;
            }

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

            g.Clear(Color.Black);
            if(ws.IRState.Found1)
                g.DrawEllipse(new Pen(Color.Red), (int)(ws.IRState.RawX1 / 4), (int)(ws.IRState.RawY1 / 4), ws.IRState.Size1+1, ws.IRState.Size1+1);
            if(ws.IRState.Found2)
                g.DrawEllipse(new Pen(Color.Blue), (int)(ws.IRState.RawX2 / 4), (int)(ws.IRState.RawY2 / 4), ws.IRState.Size2+1, ws.IRState.Size2+1);
            if(ws.IRState.Found3)
                g.DrawEllipse(new Pen(Color.Yellow), (int)(ws.IRState.RawX3 / 4), (int)(ws.IRState.RawY3 / 4), ws.IRState.Size3+1, ws.IRState.Size3+1);
            if(ws.IRState.Found4)
                g.DrawEllipse(new Pen(Color.Orange), (int)(ws.IRState.RawX4 / 4), (int)(ws.IRState.RawY4 / 4), ws.IRState.Size4+1, ws.IRState.Size4+1);
            if(ws.IRState.Found1 && ws.IRState.Found2)
                g.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidX / 4), (int)(ws.IRState.RawMidY / 4), 2, 2);
            pbIR.Image = b;
        }
 void wm_OnWiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     // when we get an update from the lib, post a msg to our internal update port
     _internalStateChangedPort.Post(new WiimoteChanged(args.WiimoteState));
 }
        void _wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            _buttonA.State = _wiimote.WiimoteState.ButtonState.A ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonB.State = _wiimote.WiimoteState.ButtonState.B ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonMinus.State = _wiimote.WiimoteState.ButtonState.Minus ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonPlus.State = _wiimote.WiimoteState.ButtonState.Plus ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonUp.State = _wiimote.WiimoteState.ButtonState.Up ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonDown.State = _wiimote.WiimoteState.ButtonState.Down ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonLeft.State = _wiimote.WiimoteState.ButtonState.Left ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonRight.State = _wiimote.WiimoteState.ButtonState.Right ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _button1.State = _wiimote.WiimoteState.ButtonState.One ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _button2.State = _wiimote.WiimoteState.ButtonState.Two ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _buttonHome.State = _wiimote.WiimoteState.ButtonState.Home ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;

            _classicUp.State = _wiimote.WiimoteState.ClassicControllerState.ButtonState.Up ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _classicDown.State = _wiimote.WiimoteState.ClassicControllerState.ButtonState.Down ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _classicRight.State = _wiimote.WiimoteState.ClassicControllerState.ButtonState.Left ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;
            _classicLeft.State = _wiimote.WiimoteState.ClassicControllerState.ButtonState.Right ? UxbTransform.DeviceComponents.ButtonState.Down : UxbTransform.DeviceComponents.ButtonState.Up;

            _irComponent.X = 1.0F - _wiimote.WiimoteState.IRState.Midpoint.X;
            _irComponent.Y = _wiimote.WiimoteState.IRState.Midpoint.Y;

            _accelerometer.XAxis = _wiimote.WiimoteState.AccelState.Values.X;
            _accelerometer.YAxis = _wiimote.WiimoteState.AccelState.Values.Y;
            _accelerometer.ZAxis = _wiimote.WiimoteState.AccelState.Values.Z;

            OnDeviceStateChanged();
        }
Beispiel #23
0
        //-----------------------------------------------------------------------
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            if (Motes == null)
            return;

             Wiimote wii = (Wiimote)sender;
             for (int i=0; i<Motes.Count; i++) {
            // Find which Wiimote the data originated from and update the button state
            if (wii == Motes.ElementAt(i)) {
               lock (Buttons) {
                  Buttons[i] = args.WiimoteState.ButtonState;
               }
            }
             }
        }
Beispiel #24
0
        private void WiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            // Toggle states
            if (e.WiimoteState.ButtonState.One && !buttonOne)
            {
                enableModelPositioning = !enableModelPositioning;
                if (!enableModelPositioning)
                {
                    Heel = 0;
                    Trim = 0;
                    Heave = 0;
                }
            }

            if (e.WiimoteState.ButtonState.Two && !buttonTwo)
                enableMouseSimulation = !enableMouseSimulation;

            if (e.WiimoteState.ButtonState.Up && !buttonUp)
            {
                if (UpAction != null)
                    UpAction();
            }

            if (enableModelPositioning)
            {
                if (e.WiimoteState.ButtonState.Home)
                {
                    // changing UI properties must be invoked on the UI thread
                    dispatcher.BeginInvoke(new Action(() => view.ZoomExtents()));
                }

                //dispatcher.BeginInvoke(new Action(() => HullBrush = new SolidColorBrush(colors[r.Next(colors.Length)])));

                if (e.WiimoteState.ButtonState.Plus)
                {
                    dispatcher.BeginInvoke(new Action(() => view.CameraController.Zoom(-0.01)));
                }
                if (e.WiimoteState.ButtonState.Minus)
                {
                    dispatcher.BeginInvoke(new Action(() => view.CameraController.Zoom(0.01)));
                }

                double deltaTime = timer.ElapsedMilliseconds*0.001;
                timer.Restart();

                double newHeel = -90 + 180.0*(e.WiimoteState.AccelState.RawValues.X - 94)/(143 - 94);
                double newTrim = -90 + 180.0*(e.WiimoteState.AccelState.RawValues.Y - 94)/(143 - 94);
                Heel = Heel + (newHeel - Heel)*damping;
                Trim = Trim + (newTrim - Trim)*damping;

                double verticalAcceleration = 100.0*(e.WiimoteState.AccelState.RawValues.Z - 143);
                vspeed += verticalAcceleration*deltaTime;
                vspeed *= vspeedDamping;
                Heave = (Heave + vspeed*deltaTime)*0.95;

                // Console.WriteLine(e.WiimoteState.AccelState.Values.Z + " -> " + verticalAcceleration + " => " + vspeed);
            }
            if (enableMouseSimulation)
            {
                Point? pos = GetPosition(e.WiimoteState);
                if (pos.HasValue)
                {
                    MouseHelper.SetCursorPos((int) pos.Value.X, (int) pos.Value.Y);
                    if (e.WiimoteState.ButtonState.A && !buttonA)
                        MouseHelper.SimulateMouseEvent(MouseButton.Left, MouseButtonState.Pressed);
                    else if (!e.WiimoteState.ButtonState.A && buttonA)
                        MouseHelper.SimulateMouseEvent(MouseButton.Left, MouseButtonState.Released);
                    if (e.WiimoteState.ButtonState.B && !buttonB)
                        MouseHelper.SimulateMouseEvent(MouseButton.Right, MouseButtonState.Pressed);
                    else if (!e.WiimoteState.ButtonState.B && buttonB)
                        MouseHelper.SimulateMouseEvent(MouseButton.Right, MouseButtonState.Released);

                    if (e.WiimoteState.ButtonState.A && e.WiimoteState.ButtonState.B && !middleDown)
                    {
                        MouseHelper.SimulateMouseEvent(MouseButton.Left, MouseButtonState.Released);
                        MouseHelper.SimulateMouseEvent(MouseButton.Right, MouseButtonState.Released);
                        MouseHelper.SimulateMouseEvent(MouseButton.Middle, MouseButtonState.Pressed);
                        middleDown = true;
                    }
                    else if (!e.WiimoteState.ButtonState.A && !e.WiimoteState.ButtonState.B && middleDown)
                    {
                        MouseHelper.SimulateMouseEvent(MouseButton.Middle, MouseButtonState.Released);
                        middleDown = false;
                    }
                }
            }

            buttonUp = e.WiimoteState.ButtonState.Up;

            buttonOne = e.WiimoteState.ButtonState.One;
            buttonTwo = e.WiimoteState.ButtonState.Two;
            buttonA = e.WiimoteState.ButtonState.A;
            buttonB = e.WiimoteState.ButtonState.B;
        }
 void _wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
 {
     // when we get an update from the lib, post a msg to our internal update port
     _internalStateChangedPort.Post(new WiimoteChanged(args.WiimoteState));
 }
        public void WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            if(current >= 0)
            {
                games[current].WiimoteChanged(args.WiimoteState);
            }

            if (big)
            {
                bigGame.WiimoteChanged(args.WiimoteState);
            }
        }
Beispiel #27
0
        private void UpdateWiimoteChanged(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            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);

            lblAccel.Text = ws.AccelState.Values.ToString();

            /*
            chkLED1.Checked = ws.LEDState.LED1;
            chkLED2.Checked = ws.LEDState.LED2;
            chkLED3.Checked = ws.LEDState.LED3;
            chkLED4.Checked = ws.LEDState.LED4;
            */

            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.ClassicController:
                    /*
                    clbCCButtons.SetItemChecked(0, ws.ClassicControllerState.ButtonState.A);
                    clbCCButtons.SetItemChecked(1, ws.ClassicControllerState.ButtonState.B);
                    clbCCButtons.SetItemChecked(2, ws.ClassicControllerState.ButtonState.X);
                    clbCCButtons.SetItemChecked(3, ws.ClassicControllerState.ButtonState.Y);
                    clbCCButtons.SetItemChecked(4, ws.ClassicControllerState.ButtonState.Minus);
                    clbCCButtons.SetItemChecked(5, ws.ClassicControllerState.ButtonState.Home);
                    clbCCButtons.SetItemChecked(6, ws.ClassicControllerState.ButtonState.Plus);
                    clbCCButtons.SetItemChecked(7, ws.ClassicControllerState.ButtonState.Up);
                    clbCCButtons.SetItemChecked(8, ws.ClassicControllerState.ButtonState.Down);
                    clbCCButtons.SetItemChecked(9, ws.ClassicControllerState.ButtonState.Left);
                    clbCCButtons.SetItemChecked(10, ws.ClassicControllerState.ButtonState.Right);
                    clbCCButtons.SetItemChecked(11, ws.ClassicControllerState.ButtonState.ZL);
                    clbCCButtons.SetItemChecked(12, ws.ClassicControllerState.ButtonState.ZR);
                    clbCCButtons.SetItemChecked(13, ws.ClassicControllerState.ButtonState.TriggerL);
                    clbCCButtons.SetItemChecked(14, ws.ClassicControllerState.ButtonState.TriggerR);

                    lblCCJoy1.Text = ws.ClassicControllerState.JoystickL.ToString();
                    lblCCJoy2.Text = ws.ClassicControllerState.JoystickR.ToString();

                    lblTriggerL.Text = ws.ClassicControllerState.TriggerL.ToString();
                    lblTriggerR.Text = ws.ClassicControllerState.TriggerR.ToString();
                     */
                    break;

                case ExtensionType.Guitar:
                    /*
                    clbGuitarButtons.SetItemChecked(0, ws.GuitarState.FretButtonState.Green);
                    clbGuitarButtons.SetItemChecked(1, ws.GuitarState.FretButtonState.Red);
                    clbGuitarButtons.SetItemChecked(2, ws.GuitarState.FretButtonState.Yellow);
                    clbGuitarButtons.SetItemChecked(3, ws.GuitarState.FretButtonState.Blue);
                    clbGuitarButtons.SetItemChecked(4, ws.GuitarState.FretButtonState.Orange);
                    clbGuitarButtons.SetItemChecked(5, ws.GuitarState.ButtonState.Minus);
                    clbGuitarButtons.SetItemChecked(6, ws.GuitarState.ButtonState.Plus);
                    clbGuitarButtons.SetItemChecked(7, ws.GuitarState.ButtonState.StrumUp);
                    clbGuitarButtons.SetItemChecked(8, ws.GuitarState.ButtonState.StrumDown);

                    clbTouchbar.SetItemChecked(0, ws.GuitarState.TouchbarState.Green);
                    clbTouchbar.SetItemChecked(1, ws.GuitarState.TouchbarState.Red);
                    clbTouchbar.SetItemChecked(2, ws.GuitarState.TouchbarState.Yellow);
                    clbTouchbar.SetItemChecked(3, ws.GuitarState.TouchbarState.Blue);
                    clbTouchbar.SetItemChecked(4, ws.GuitarState.TouchbarState.Orange);

                    lblGuitarJoy.Text = ws.GuitarState.Joystick.ToString();
                    lblGuitarWhammy.Text = ws.GuitarState.WhammyBar.ToString();
                    lblGuitarType.Text = ws.GuitarState.GuitarType.ToString();
                     */
                    break;

                case ExtensionType.Drums:
                    /*
                    clbDrums.SetItemChecked(0, ws.DrumsState.Red);
                    clbDrums.SetItemChecked(1, ws.DrumsState.Blue);
                    clbDrums.SetItemChecked(2, ws.DrumsState.Green);
                    clbDrums.SetItemChecked(3, ws.DrumsState.Yellow);
                    clbDrums.SetItemChecked(4, ws.DrumsState.Orange);
                    clbDrums.SetItemChecked(5, ws.DrumsState.Pedal);
                    clbDrums.SetItemChecked(6, ws.DrumsState.Minus);
                    clbDrums.SetItemChecked(7, ws.DrumsState.Plus);

                    lbDrumVelocity.Items.Clear();
                    lbDrumVelocity.Items.Add(ws.DrumsState.RedVelocity);
                    lbDrumVelocity.Items.Add(ws.DrumsState.BlueVelocity);
                    lbDrumVelocity.Items.Add(ws.DrumsState.GreenVelocity);
                    lbDrumVelocity.Items.Add(ws.DrumsState.YellowVelocity);
                    lbDrumVelocity.Items.Add(ws.DrumsState.OrangeVelocity);
                    lbDrumVelocity.Items.Add(ws.DrumsState.PedalVelocity);

                    lblDrumJoy.Text = ws.DrumsState.Joystick.ToString();
                     */
                    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;
            }

            irGraphics.Clear(Color.Black);
            strokesGraphics.Clear(Color.Black);

            UpdateIR(ws.IRState.IRSensors[0], lblIR1, lblIR1Raw, chkFound1, Color.Red);
            UpdateIR(ws.IRState.IRSensors[1], lblIR2, lblIR2Raw, chkFound2, Color.Blue);
            UpdateIR(ws.IRState.IRSensors[2], lblIR3, lblIR3Raw, chkFound3, Color.Yellow);
            UpdateIR(ws.IRState.IRSensors[3], lblIR4, lblIR4Raw, chkFound4, Color.Orange);

            if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
            {
                irGraphics.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidpoint.X / 4), (int)(ws.IRState.RawMidpoint.Y / 4), 2, 2);
            }

            for (int i = 0; i < 4; i++)
            {
                if (ws.IRState.IRSensors[i].Found)
                {
                    // Check for spell action
                    trigger = wandTracker.addPosition(ws.IRState.IRSensors[i].RawPosition, DateTime.Now);
                    break;
                }
            }

            if (trigger != null) // && trigger.casting())
            {
                if (trigger.getConfidence() > maxConfidence)
                {
                    maxConfidence = trigger.getConfidence();
                }
                if (trigger.getConfidence() < minConfidence)
                {
                    minConfidence = trigger.getConfidence();
                }
                lblSpellName.Text = trigger.GetType().Name + " - " + DateTime.Now.Subtract(wandTracker.startSpell).Seconds + " seconds";
                lblMaxConfidence.Text = maxConfidence.ToString();
                lblMinConfidence.Text = minConfidence.ToString();
                lblCurrentConfidence.Text = trigger.getConfidence().ToString();
            }
            else
            {
                lblSpellName.Text = "No spell";
            }

            Position previous = null;
            foreach (Position p in wandTracker.positions)
            {
                if (previous == null)
                {
                    previous = p;
                    continue;
                }
                System.Drawing.Point pointA = new System.Drawing.Point();
                System.Drawing.Point pointB = new System.Drawing.Point();
                pointA.X = (PositionStatistics.MAX_X - previous.point.X)/4;
                pointA.Y = (PositionStatistics.MAX_Y - previous.point.Y)/4;
                pointB.X = (PositionStatistics.MAX_X - p.point.X) / 4;
                pointB.Y = (PositionStatistics.MAX_Y - p.point.Y) / 4;
                strokesGraphics.DrawLine(new Pen(Color.Yellow), pointA, pointB);

                previous = p;
            }

            if (wandTracker.strokes != null)
            {
                foreach (Stroke stroke in wandTracker.strokes)
                {
                    /*
                    switch (stroke.direction)
                    {
                        case StrokeDirection.Bumbled:
                            strokesGraphics.DrawEllipse(
                                new Pen(Color.Purple),
                                (stroke.start.SystemPoint().X + stroke.end.SystemPoint().X) / 2,
                                (stroke.start.SystemPoint().Y + stroke.end.SystemPoint().Y) / 2,
                                10, 5);
                            strokesGraphics.DrawLine(
                                new Pen(Color.Red),
                                stroke.start.SystemPoint(),
                                stroke.end.SystemPoint());
                            break;
                        default:
                            strokesGraphics.DrawLine(
                                new Pen(Color.Green),
                                stroke.start.SystemPoint(),
                                stroke.end.SystemPoint());
                            break;
                    }
                     */
                    /*
                    strokesGraphics.DrawString(
                        stroke.direction.ToString(),
                        new Font(FontFamily.GenericMonospace, 12.0f, FontStyle.Bold),
                        new SolidBrush(Color.Orange),
                        (stroke.start.SystemPoint().X + stroke.end.SystemPoint().X) / 2,
                        (stroke.start.SystemPoint().Y + stroke.end.SystemPoint().Y) / 2);
                    */
                }

            }

            pbIR.Image = irBitmap;
            pbStrokes.Image = strokesBitmap;

            pbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery);
            lblBattery.Text = ws.Battery.ToString();
            lblDevicePath.Text = "Device Path: " + mWiimote.HIDDevicePath;
        }
Beispiel #28
0
 void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
 {
     WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];
     wi.UpdateState(e);
 }
Beispiel #29
0
        private void UpdateWiimoteState(WiimoteChangedEventArgs args)
        {
            WiimoteState ws = args.WiimoteState;

            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);

            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.ClassicController:
                    clbCCButtons.SetItemChecked(0, ws.ClassicControllerState.ButtonState.A);
                    clbCCButtons.SetItemChecked(1, ws.ClassicControllerState.ButtonState.B);
                    clbCCButtons.SetItemChecked(2, ws.ClassicControllerState.ButtonState.X);
                    clbCCButtons.SetItemChecked(3, ws.ClassicControllerState.ButtonState.Y);
                    clbCCButtons.SetItemChecked(4, ws.ClassicControllerState.ButtonState.Minus);
                    clbCCButtons.SetItemChecked(5, ws.ClassicControllerState.ButtonState.Home);
                    clbCCButtons.SetItemChecked(6, ws.ClassicControllerState.ButtonState.Plus);
                    clbCCButtons.SetItemChecked(7, ws.ClassicControllerState.ButtonState.Up);
                    clbCCButtons.SetItemChecked(8, ws.ClassicControllerState.ButtonState.Down);
                    clbCCButtons.SetItemChecked(9, ws.ClassicControllerState.ButtonState.Left);
                    clbCCButtons.SetItemChecked(10, ws.ClassicControllerState.ButtonState.Right);
                    clbCCButtons.SetItemChecked(11, ws.ClassicControllerState.ButtonState.ZL);
                    clbCCButtons.SetItemChecked(12, ws.ClassicControllerState.ButtonState.ZR);
                    clbCCButtons.SetItemChecked(13, ws.ClassicControllerState.ButtonState.TriggerL);
                    clbCCButtons.SetItemChecked(14, ws.ClassicControllerState.ButtonState.TriggerR);

                    lblCCJoy1.Text = ws.ClassicControllerState.JoystickL.ToString();
                    lblCCJoy2.Text = ws.ClassicControllerState.JoystickR.ToString();

                    lblTriggerL.Text = ws.ClassicControllerState.TriggerL.ToString();
                    lblTriggerR.Text = ws.ClassicControllerState.TriggerR.ToString();
                    break;

                case ExtensionType.Guitar:
                    clbGuitarButtons.SetItemChecked(0, ws.GuitarState.ButtonState.Green);
                    clbGuitarButtons.SetItemChecked(1, ws.GuitarState.ButtonState.Red);
                    clbGuitarButtons.SetItemChecked(2, ws.GuitarState.ButtonState.Yellow);
                    clbGuitarButtons.SetItemChecked(3, ws.GuitarState.ButtonState.Blue);
                    clbGuitarButtons.SetItemChecked(4, ws.GuitarState.ButtonState.Orange);
                    clbGuitarButtons.SetItemChecked(5, ws.GuitarState.ButtonState.Minus);
                    clbGuitarButtons.SetItemChecked(6, ws.GuitarState.ButtonState.Plus);
                    clbGuitarButtons.SetItemChecked(7, ws.GuitarState.ButtonState.StrumUp);
                    clbGuitarButtons.SetItemChecked(8, ws.GuitarState.ButtonState.StrumDown);

                    lblGuitarJoy.Text = ws.GuitarState.Joystick.ToString();
                    lblGuitarWhammy.Text = ws.GuitarState.WhammyBar.ToString();
                    break;
            }

            g.Clear(Color.Black);

            if(ws.IRState.IRSensors[0].Found)
            {
                lblIR1.Text = ws.IRState.IRSensors[0].Position + ", " + ws.IRState.IRSensors[0].Size;
                lblIR1Raw.Text = ws.IRState.IRSensors[0].RawPosition.ToString();
                g.DrawEllipse(new Pen(Color.Red), (int)(ws.IRState.IRSensors[0].RawPosition.X / 4), (int)(ws.IRState.IRSensors[0].RawPosition.Y / 4),
                             ws.IRState.IRSensors[0].Size+1, ws.IRState.IRSensors[0].Size+1);
            }
            if(ws.IRState.IRSensors[1].Found)
            {
                lblIR2.Text = ws.IRState.IRSensors[1].Position + ", " + ws.IRState.IRSensors[1].Size;
                lblIR2Raw.Text = ws.IRState.IRSensors[1].RawPosition.ToString();
                g.DrawEllipse(new Pen(Color.Blue), (int)(ws.IRState.IRSensors[1].RawPosition.X / 4), (int)(ws.IRState.IRSensors[1].RawPosition.Y / 4),
                             ws.IRState.IRSensors[1].Size+1, ws.IRState.IRSensors[1].Size+1);
            }
            if(ws.IRState.IRSensors[2].Found)
            {
                lblIR3.Text = ws.IRState.IRSensors[2].Position + ", " + ws.IRState.IRSensors[2].Size;
                lblIR3Raw.Text = ws.IRState.IRSensors[2].RawPosition.ToString();
                g.DrawEllipse(new Pen(Color.Yellow), (int)(ws.IRState.IRSensors[2].RawPosition.X / 4), (int)(ws.IRState.IRSensors[2].RawPosition.Y / 4),
                             ws.IRState.IRSensors[2].Size+1, ws.IRState.IRSensors[2].Size+1);
            }
            if(ws.IRState.IRSensors[3].Found)
            {
                lblIR4.Text = ws.IRState.IRSensors[3].Position + ", " + ws.IRState.IRSensors[3].Size;
                lblIR4Raw.Text = ws.IRState.IRSensors[3].RawPosition.ToString();
                g.DrawEllipse(new Pen(Color.Orange), (int)(ws.IRState.IRSensors[3].RawPosition.X / 4), (int)(ws.IRState.IRSensors[3].RawPosition.Y / 4),
                             ws.IRState.IRSensors[3].Size+1, ws.IRState.IRSensors[3].Size+1);
            }

            if(ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found)
                g.DrawEllipse(new Pen(Color.Green), (int)(ws.IRState.RawMidpoint.X / 4), (int)(ws.IRState.RawMidpoint.Y / 4), 2, 2);

            pbIR.Image = b;

            chkFound1.Checked = ws.IRState.IRSensors[0].Found;
            chkFound2.Checked = ws.IRState.IRSensors[1].Found;
            chkFound3.Checked = ws.IRState.IRSensors[2].Found;
            chkFound4.Checked = ws.IRState.IRSensors[3].Found;

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

            // add stuff listview for XYZ data
            if (ws.ButtonState.One)
            {
                tcpClient.Send("CLEAR      \n");
            }else if (ws.ButtonState.A) {
                lv_xyz.Items.Insert(0, new ListViewItem(new string[] { ws.AccelState.Values.X.ToString(), ws.AccelState.Values.Y.ToString(), ws.AccelState.Values.Z.ToString() }));
                // sending accelerometer over TCP
                int msgLen = 9;

                try{
                    tcpClient.Send("AX" + ws.AccelState.Values.X.ToString().Substring(0, msgLen) + "\n");
                    tcpClient.Send("AY" + ws.AccelState.Values.Y.ToString().Substring(0, msgLen) + "\n");
                    tcpClient.Send("AZ" + ws.AccelState.Values.Z.ToString().Substring(0, msgLen) + "\n");
                    tcpClient.Send("GX" + "999999999" + "\n");
                    tcpClient.Send("GY" + "999999999" + "\n");
                    tcpClient.Send("GZ" + "999999999" + "\n");
                }catch (Exception e){
                    Console.WriteLine(e.ToString());
                }
            }
        }
 public void UpdateState(WiimoteChangedEventArgs args)
 {
     BeginInvoke(new UpdateWiimoteStateDelegate(UpdateWiimoteChanged), args);
 }
        void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
		{
            WiimoteState state = e.WiimoteState;

            Dictionary<String, float> axisValues = new Dictionary<String, float>();

            axisValues[Axis.Axis_X.ToString()] = state.AccelState.Values.X;
            axisValues[Axis.Axis_Y.ToString()] = state.AccelState.Values.Y;
            axisValues[Axis.Axis_Z.ToString()] = state.AccelState.Values.Z;

            axisValues[Axis.Axis_Nunchuk_X.ToString()] = state.NunchukState.Joystick.X;
            axisValues[Axis.Axis_Nunchuk_Y.ToString()] = state.NunchukState.Joystick.Y;

            List<String> buttonsPressed = new List<String>();

            if (state.ButtonState.A) { buttonsPressed.Add(Button.Button_A.ToString()); }
            if (state.ButtonState.B) { buttonsPressed.Add(Button.Button_B.ToString()); }
            if (state.ButtonState.One) { buttonsPressed.Add(Button.Button_One.ToString()); }
            if (state.ButtonState.Two) { buttonsPressed.Add(Button.Button_Two.ToString()); }
            if (state.ButtonState.Minus) { buttonsPressed.Add(Button.Button_Minus.ToString()); }
            if (state.ButtonState.Plus) { buttonsPressed.Add(Button.Button_Plus.ToString()); }
            if (state.ButtonState.Home) { buttonsPressed.Add(Button.Button_Home.ToString()); }

            if (state.NunchukState.C ) { buttonsPressed.Add(Button.Button_Nunchuk_C.ToString()); }

            if (state.ClassicControllerState.ButtonState.A) { buttonsPressed.Add(Button.Button_Classic_A.ToString()); }
            if (state.ClassicControllerState.ButtonState.B) { buttonsPressed.Add(Button.Button_Classic_B.ToString()); }
            if (state.ClassicControllerState.ButtonState.X) { buttonsPressed.Add(Button.Button_Classic_X.ToString()); }
            if (state.ClassicControllerState.ButtonState.Y) { buttonsPressed.Add(Button.Button_Classic_Y.ToString()); }
            if (state.ClassicControllerState.ButtonState.ZL) { buttonsPressed.Add(Button.Button_Classic_L.ToString()); }
            if (state.ClassicControllerState.ButtonState.ZR) { buttonsPressed.Add(Button.Button_Classic_R.ToString()); }
            if (state.ClassicControllerState.ButtonState.Left) { buttonsPressed.Add(Button.Button_Classic_Left.ToString()); }
            if (state.ClassicControllerState.ButtonState.Up) { buttonsPressed.Add(Button.Button_Classic_Up.ToString()); }
            if (state.ClassicControllerState.ButtonState.Right) { buttonsPressed.Add(Button.Button_Classic_Right.ToString()); }
            if (state.ClassicControllerState.ButtonState.Down) { buttonsPressed.Add(Button.Button_Classic_Down.ToString()); }
            if (state.ClassicControllerState.ButtonState.Minus) { buttonsPressed.Add(Button.Button_Classic_Minus.ToString()); }
            if (state.ClassicControllerState.ButtonState.Plus) { buttonsPressed.Add(Button.Button_Classic_Plus.ToString()); }
            if (state.ClassicControllerState.ButtonState.Home) { buttonsPressed.Add(Button.Button_Classic_Home.ToString()); }

            currentAxisValues = axisValues;
            currentButtonsPressed = buttonsPressed;
		}