Esempio n. 1
0
        //void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        void _Timer_Elapsed(object whatever)
        {
            //_Timer.Stop();

            DPad[] oDirection = new DPad[4];
            Button oBtn = new Button();
            HatPosition[] oHatDirection = new HatPosition[4];

            try
            {
                for (int i = 0; i < 4; i++)
                {
                    var cap = OpenTK.Input.Joystick.GetCapabilities(i);
                    var state = OpenTK.Input.Joystick.GetState(i);
                    if (!state.IsConnected || (cap.ButtonCount == 16))
                        continue;
                    System.Diagnostics.Debug.Print(state.ToString());

                    oBtn.A = state.IsButtonDown(JoystickButton.Button1);
                    oBtn.B = state.IsButtonDown(JoystickButton.Button2);
                    oBtn.X = state.IsButtonDown(JoystickButton.Button3);
                    oBtn.Y = state.IsButtonDown(JoystickButton.Button0);
                    oBtn.L = state.IsButtonDown(JoystickButton.Button6);
                    oBtn.R = state.IsButtonDown(JoystickButton.Button7);
                    oBtn.LB = false;
                    oBtn.RB = false;
                    oBtn.Select = state.IsButtonDown(JoystickButton.Button8);
                    oBtn.Start = state.IsButtonDown(JoystickButton.Button9);

                    JoystickHatState jhs = state.GetHat(JoystickHat.Hat0);
                    oHatDirection[i] = jhs.Position;

                    int nXAxis = (int)Math.Round(state.GetAxis(JoystickAxis.Axis0), 0);
                    int nYAxis = (int)Math.Round(state.GetAxis(JoystickAxis.Axis1), 0);

                    // 左邊磨菇頭...
                    if ((nXAxis == 0 && nYAxis == 0))
                    {
                        oDirection[i] = DPad.None;
                    }

                    if (nYAxis > 0)
                        oDirection[i] = DPad.Up;
                    if (nYAxis < 0)
                        oDirection[i] = DPad.Down;

                    if (oBtn.A || oBtn.B || oBtn.X || oBtn.Y || oBtn.L || oBtn.R || oBtn.LB || oBtn.RB || oBtn.Select || oBtn.Start || oDirection[i] != DPad.None || jhs.Position != HatPosition.Centered)
                    {
                        JoystickPressedEventHandler handler = JoystickPressed;
                        if (handler != null)
                        {
                            JoystickPressedEventArgs evt = new JoystickPressedEventArgs();

                            evt.DPadDirection = oDirection[i];
                            evt.Buttons = oBtn;
                            evt.HatDirection = oHatDirection[i];
                            evt.TraceMessage = "Joystick[" + i + "]:   " + state.ToString();
                            handler(evt);
                        }
                    }
                    else
                    {

                        JoystickTraceEventHandler hander2 = JoystickTrace;
                        if (hander2 != null)
                        {
                            JoystickTraceEventArgs evt2 = new JoystickTraceEventArgs();
                            evt2.TraceMessage = "Joystick[" + i + "]:   " + state.ToString();
                            hander2(evt2);
                        }
                    }
                }

            }
            catch (Exception ex){ }

            //_Timer.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// Joystick Pressed event
        /// </summary>
        /// <param name="e">Buttons, DPad, DirectionHat</param>
        void Joystick_JoystickPressed(JoystickPressedEventArgs e)
        {
            if (osdChannelList1.InvokeRequired)
            {
                JoystickPressedCallback d = new JoystickPressedCallback(Joystick_JoystickPressed);
                this.Invoke(d, new object[] { e });
            }
            else
            {
                label1.Text = e.TraceMessage;
                if (e.Buttons.Start)
                //if (e.Buttons.L)
                {
                    //_Timer.Stop();
                    this.Close();
                }
                if (e.Buttons.L)
                {
                    int nVolume = axVLCPlugin21.volume - 5;
                    if (nVolume < 0)
                        nVolume = 0;
                    axVLCPlugin21.volume = nVolume;

                }
                if (e.Buttons.R)
                {
                    int nVolume = axVLCPlugin21.volume + 5;
                    if (nVolume > 100)
                        nVolume = 100;
                    axVLCPlugin21.volume = nVolume;

                }
                if (_IsMenuShown)
                {
                    if (e.DPadDirection == DPad.Up || e.HatDirection == HatPosition.Up)
                    {
                        osdChannelList1.channelUp();
                    }
                    else if (e.DPadDirection == DPad.Down || e.HatDirection == HatPosition.Down)
                    {
                        osdChannelList1.channelDown();
                    }
                    else if (e.Buttons.A)
                    {
                        if (_IsMenuShown)
                        {
                            showOSD(!_IsMenuShown);
                            Application.DoEvents();
                            if (_CurrentPlaying != osdChannelList1.ChannelAddress)
                            {
                                axVLCPlugin21.playlist.clear();
                                axVLCPlugin21.playlist.add(osdChannelList1.ChannelAddress, null, null);
                                axVLCPlugin21.playlist.playItem(0);
                                _CurrentPlaying = osdChannelList1.ChannelAddress;
                            }
                        }
                    }
                    else if (e.Buttons.B)
                    {
                        showOSD(false);
                    }
                }
                else
                {
                    if (e.Buttons.A || e.Buttons.B || e.DPadDirection == DPad.Up || e.DPadDirection == DPad.Down || e.HatDirection == HatPosition.Up || e.HatDirection == HatPosition.Down )
                        showOSD(!_IsMenuShown || !e.Buttons.B);
                }
            }
        }
Esempio n. 3
0
 protected virtual void OnJoystickPressed(JoystickPressedEventArgs e)
 {
     JoystickPressedEventHandler handler = JoystickPressed;
     if (handler != null)
         handler(e);
 }
Esempio n. 4
0
 /// <summary>
 /// Joystick Pressed event
 /// </summary>
 /// <param name="e">Buttons, DPad, DirectionHat</param>
 void j_JoystickPressed(JoystickPressedEventArgs e)
 {
     if (osdChannelList1.InvokeRequired)
     {
         JoystickPressedCallback d = new JoystickPressedCallback(j_JoystickPressed);
         this.Invoke(d, new object[] { e });
     }
     else
     {
         if (e.Buttons.L)
         {
             _Timer.Stop();
             this.Close();
         }
         if (_IsMenuShown)
         {
             if (e.DPadDirection == DPad.Up || e.HatDirection == HatPosition.Up)
             {
                 osdChannelList1.channelUp();
             }
             else if (e.DPadDirection == DPad.Down || e.HatDirection == HatPosition.Down)
             {
                 osdChannelList1.channelDown();
             }
             else if (e.Buttons.A)
             {
                 if (_IsMenuShown)
                 {
                     //axVLCPlugin21.playlist.clear();
                     //axVLCPlugin21.playlist.add(osdChannelList1.ChannelAddress, null, null);
                     //axVLCPlugin21.playlist.playItem(0);
                     showOSD(!_IsMenuShown);
                 }
             }
             if (e.Buttons.B)
             {
                 showOSD(false);
             }
         }
         else
         {
             showOSD(!_IsMenuShown && !e.Buttons.B);
         }
     }
 }