예제 #1
0
        private void HandleMovement()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                RightPressed?.Invoke(this, null);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                LeftPressed?.Invoke(this, null);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                UpPressed?.Invoke(this, null);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                DownPressed?.Invoke(this, null);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.PageUp))
            {
                StrafeUpPressed?.Invoke(this, null);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.PageDown))
            {
                StrafeDownPressed?.Invoke(this, null);
            }
        }
예제 #2
0
        /// <summary>
        /// Waits for user's actions.
        /// </summary>
        public void Run()
        {
            while (true)
            {
                var keyPressed = Console.ReadKey(true);

                switch (keyPressed.Key)
                {
                case ConsoleKey.LeftArrow:
                    LeftPressed?.Invoke(this, EventArgs.Empty);
                    break;

                case ConsoleKey.RightArrow:
                    RightPressed?.Invoke(this, EventArgs.Empty);
                    break;

                case ConsoleKey.UpArrow:
                    UpPressed?.Invoke(this, EventArgs.Empty);
                    break;

                case ConsoleKey.DownArrow:
                    DownPressed?.Invoke(this, EventArgs.Empty);
                    break;
                }
            }
        }
예제 #3
0
        private void HandleLook()
        {
            if (Mouse.GetState().RightButton == ButtonState.Released)
            {
                if (Mouse.GetState().Position.X > center.X)
                {
                    RightPressed?.Invoke(this, null);
                }
                else if (Mouse.GetState().Position.X < center.X)
                {
                    LeftPressed?.Invoke(this, null);
                }

                if (Mouse.GetState().Position.Y > center.Y)
                {
                    UpPressed?.Invoke(this, null);
                }
                else if (Mouse.GetState().Position.Y < center.Y)
                {
                    DownPressed?.Invoke(this, null);
                }
            }
            else
            {
                if (Mouse.GetState().Position.X > center.X)
                {
                    RotateCWPressed?.Invoke(this, null);
                }
                else if (Mouse.GetState().Position.X < center.X)
                {
                    RotateCCWPressed?.Invoke(this, null);
                }
            }
        }
예제 #4
0
 public static void OnMovedUp(float thumbstickY)
 {
     UpPressed?.Invoke(null, new MoveInputEventArgs()
     {
         InputValue = thumbstickY
     });
 }
예제 #5
0
        public void Start()
        {
            Task.Run(async() =>
            {
                ISenseHat senseHat = await SenseHatFactory.GetSenseHat();

                while (true)
                {
                    if (senseHat.Joystick.Update())
                    {
                        if (senseHat.Joystick.LeftKey == KeyState.Pressed)
                        {
                            LeftPressed?.Invoke(this, EventArgs.Empty);
                        }
                        else if (senseHat.Joystick.RightKey == KeyState.Pressed)
                        {
                            RightPressed?.Invoke(this, EventArgs.Empty);
                        }
                        else if (senseHat.Joystick.UpKey == KeyState.Pressed)
                        {
                            UpPressed?.Invoke(this, EventArgs.Empty);
                        }
                        else if (senseHat.Joystick.DownKey == KeyState.Pressed)
                        {
                            DownPressed?.Invoke(this, EventArgs.Empty);
                        }
                        else if (senseHat.Joystick.EnterKey == KeyState.Pressed)
                        {
                            EnterPressed?.Invoke(this, EventArgs.Empty);
                        }
                    }

                    await Task.Delay(TimeSpan.FromMilliseconds(2));
                }
            });
        }
예제 #6
0
 void onUpPressed()
 {
     UpPressed?.Invoke();
 }
예제 #7
0
        /// <summary>
        /// Establish connection with specified gateways. Returns -1 if failed, 1 if ok.
        /// </summary>
        /// <returns></returns>
        public int Connect()
        {
            if (!connected)
            {
                int retu = -1;

                try
                {
                    retu = CapsAPI.AB_API_Open();
                }
                catch { }

                if (retu < 0)
                {
                    return(-1);
                }

                for (int i = 0; i < Gateway_N.Length; i++)
                {
                    CapsAPI.AB_GW_Open(Gateway_N[i]);
                }

                bgwork = new BackgroundWorker();
                bgwork.WorkerReportsProgress      = true;
                bgwork.WorkerSupportsCancellation = true;
                bgwork.DoWork += (se, ev) =>
                {
                    while (true)
                    {
                        if (bgwork.CancellationPending)
                        {
                            break;
                        }

                        int[] status = new int[Gateway_N.Length];
                        for (int i = 0; i < Gateway_N.Length; i++)
                        {
                            status[i] = CapsAPI.AB_GW_Status(Gateway_N[i]);
                        }

                        byte[] ccbdata = new byte[255];
                        int    ccblen  = 0;

                        int   ret = 0;
                        int   nGwId, nNode;
                        short TagCommand, nMsg_type;
                        nGwId      = 0;
                        nNode      = 0;
                        TagCommand = -1;
                        nMsg_type  = -1;
                        if (status[0] == 7)
                        {
                            ret = CapsAPI.AB_Tag_RcvMsg(ref nGwId, ref nNode, ref TagCommand, ref nMsg_type, ref ccbdata[0], ref ccblen);
                        }

                        bgwork.ReportProgress(0, new PTLMessage()
                        {
                            ret        = ret,
                            nGwId      = nGwId,
                            nMsgType   = nMsg_type,
                            nNode      = nNode,
                            TagCommand = TagCommand,
                            status     = status,
                            ccbdata    = ccbdata,
                            ccblen     = ccblen
                        });
                        System.Threading.Thread.Sleep(10);
                    }
                };

                bgwork.ProgressChanged += (se, ev) =>
                {
                    int ret = (ev.UserState as PTLMessage).ret;
                    if (ret > 0)
                    {
                        switch ((ev.UserState as PTLMessage).TagCommand)
                        {
                        case 6:
                        {
                            string    m_RcvTagData = Bin2Str((ev.UserState as PTLMessage).ccbdata, 0, (ev.UserState as PTLMessage).ccblen);
                            Direction dir          = Direction.None;
                            if (m_RcvTagData[0] != '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.None;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.Up;
                            }
                            else if (m_RcvTagData[0] != '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Down;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Both;
                            }
                            ConfirmOccured?.Invoke(this, new ConfirmButtonArgs()
                                {
                                    Gateway   = (ev.UserState as PTLMessage).nGwId,
                                    Node      = -(ev.UserState as PTLMessage).nNode,
                                    Message   = m_RcvTagData.Substring(3, 5),
                                    direction = dir
                                });
                            break;
                        }

                        case 7:
                        {
                            string    m_RcvTagData = Bin2Str((ev.UserState as PTLMessage).ccbdata, 0, (ev.UserState as PTLMessage).ccblen);
                            Direction dir          = Direction.None;
                            if (m_RcvTagData[0] != '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.None;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.Up;
                            }
                            else if (m_RcvTagData[0] != '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Down;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Both;
                            }
                            ShortageOccured?.Invoke(this, new ConfirmButtonArgs()
                                {
                                    Gateway   = (ev.UserState as PTLMessage).nGwId,
                                    Node      = -(ev.UserState as PTLMessage).nNode,
                                    Message   = m_RcvTagData.Substring(3, 5),
                                    direction = dir
                                });
                            break;
                        }

                        case 15:
                        {
                            string    m_RcvTagData = Bin2Str((ev.UserState as PTLMessage).ccbdata, 0, (ev.UserState as PTLMessage).ccblen);
                            Direction dir          = Direction.None;
                            if (m_RcvTagData[0] != '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.None;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] != '8')
                            {
                                dir = Direction.Up;
                            }
                            else if (m_RcvTagData[0] != '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Down;
                            }
                            else if (m_RcvTagData[0] == '8' && m_RcvTagData[1] == '8')
                            {
                                dir = Direction.Both;
                            }
                            StockConfirmationOccured?.Invoke(this, new ConfirmButtonArgs()
                                {
                                    Gateway   = (ev.UserState as PTLMessage).nGwId,
                                    Node      = -(ev.UserState as PTLMessage).nNode,
                                    Message   = m_RcvTagData.Substring(3, 5),
                                    direction = dir
                                });
                            break;
                        }

                        case 100:
                            if ((ev.UserState as PTLMessage).nMsgType == 0)
                            {
                                byte[] ccbdata = (ev.UserState as PTLMessage).ccbdata;
                                int    ccblen  = (ev.UserState as PTLMessage).ccblen;
                                int    nRcvbun = CapsAPI.AB_GW_RcvButton(ref ccbdata[0], ref ccblen);
                                switch (nRcvbun)
                                {
                                case 1:
                                    ConfirmPressed?.Invoke(this, new PressedArgs()
                                    {
                                        Gateway = (ev.UserState as PTLMessage).nGwId,
                                        Node    = -(ev.UserState as PTLMessage).nNode
                                    });
                                    break;

                                case 2:
                                    UpPressed?.Invoke(this, new PressedArgs()
                                    {
                                        Gateway = (ev.UserState as PTLMessage).nGwId,
                                        Node    = -(ev.UserState as PTLMessage).nNode
                                    });
                                    break;

                                case 3:
                                    DownPressed?.Invoke(this, new PressedArgs()
                                    {
                                        Gateway = (ev.UserState as PTLMessage).nGwId,
                                        Node    = -(ev.UserState as PTLMessage).nNode
                                    });
                                    break;
                                }
                            }
                            break;
                        }
                    }

                    int[]  status = (ev.UserState as PTLMessage).status;
                    bool[] sta    = new bool[status.Length];

                    bool changed = false;
                    for (int i = 0; i < status.Length; i++)
                    {
                        if ((curr_status[i] != 7 && status[i] == 7) || (curr_status[i] == 7 && status[i] != 7))
                        {
                            changed = true;
                        }
                        sta[i]         = (status[i] == 7);
                        curr_status[i] = status[i];
                    }
                    if (changed)
                    {
                        connectionStatesChanged?.Invoke(this, new ConnStateArgs()
                        {
                            status = sta
                        });
                    }
                };
                bgwork.RunWorkerAsync();
                connected = true;
                return(1);
            }
            else
            {
                return(-1);
            }
        }