示例#1
0
        private void KeyHandle(bool IsDown, KeyEventArgs e)
        {
            UI.Element elementByName = null;
            if (!IsDown)
            {
                this.Action        = false;
                this.CurrentAction = Form_Fidget.STATUS.IDLE;
                if (!this.Firing && !this.nFire && !this.ReSet && !this.Calibrate)
                {
                    switch (e.KeyCode)
                    {
                    case Keys.Left:
                    {
                        elementByName = this.myUI.GetElementByName("Left");
                        break;
                    }

                    case Keys.Up:
                    {
                        this.UpPress  = false;
                        elementByName = this.myUI.GetElementByName("Up");
                        break;
                    }

                    case Keys.Right:
                    {
                        elementByName = this.myUI.GetElementByName("Right");
                        break;
                    }

                    case Keys.Down:
                    {
                        this.DownPress = false;
                        elementByName  = this.myUI.GetElementByName("Down");
                        break;
                    }
                    }
                    if (elementByName != null)
                    {
                        if (this.SoundOn)
                        {
                            this.Wavplayer.Stop();
                        }
                        elementByName.isDisplayFore = false;
                        this.myUI.myPictureBox.Invalidate();
                    }
                    this.SendUSBData(this.STOP);
                    DateTime now = DateTime.Now;
                    this.TestTime[this.TestTimeCnt] = now.Subtract(this.start);
                    Form_Fidget testTimeCnt = this;
                    testTimeCnt.TestTimeCnt = testTimeCnt.TestTimeCnt + 1;
                    if (this.TestTimeCnt >= 10)
                    {
                        this.TestTimeCnt = 0;
                    }
                }
            }
            else
            {
                Keys keyCode = e.KeyCode;
                if (keyCode != Keys.Return)
                {
                    switch (keyCode)
                    {
                    case Keys.Space:
                    {
                        if (!this.Firing && !this.Fired && !this.nFire && !this.ReSet && this.DevicePresent)
                        {
                            if (this.SoundOn)
                            {
                                this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "firing.wav");
                                this.Wavplayer.PlayLooping();
                            }
                            elementByName    = this.myUI.GetElementByName("Fire");
                            this.Firing      = true;
                            this.FireCheck   = false;
                            this.FireTimeout = 0;
                            this.SendUSBData(this.FIRE);
                            this.FireCnt   = 0;
                            this.FireAniEn = true;
                            this.SpeedCnt  = 2;
                        }
                        this.Action = true;
                        break;
                    }

                    case Keys.Left:
                    {
                        if ((this.Current_Status & 4) != 4 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent)
                        {
                            Thread.Sleep(100);
                            this.Action   = true;
                            elementByName = this.myUI.GetElementByName("Left");
                            if (this.SoundOn)
                            {
                                this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                                this.Wavplayer.PlayLooping();
                            }
                            this.SendUSBData(this.LEFT);
                            this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT;
                        }
                        this.Action = true;
                        break;
                    }

                    case Keys.Up:
                    {
                        if ((this.Current_Status & 2) != 2 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent)
                        {
                            this.UpPress  = true;
                            this.UpCnt    = 0;
                            this.Action   = true;
                            elementByName = this.myUI.GetElementByName("Up");
                            if (this.SoundOn)
                            {
                                this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                                this.Wavplayer.PlayLooping();
                            }
                            this.SendUSBData(this.UP);
                            Thread.Sleep(40);
                            this.SendUSBData(this.STOP);
                            this.start         = DateTime.Now;
                            this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT;
                        }
                        this.Action = true;
                        break;
                    }

                    case Keys.Right:
                    {
                        if ((this.Current_Status & 8) != 8 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent)
                        {
                            Thread.Sleep(100);
                            this.Action   = true;
                            elementByName = this.myUI.GetElementByName("Right");
                            if (this.SoundOn)
                            {
                                this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                                this.Wavplayer.PlayLooping();
                            }
                            this.SendUSBData(this.RIGHT);
                            this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT;
                        }
                        this.Action = true;
                        break;
                    }

                    case Keys.Down:
                    {
                        if ((this.Current_Status & 1) != 1 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent)
                        {
                            this.DownPress = true;
                            this.DownCnt   = 0;
                            this.Action    = true;
                            elementByName  = this.myUI.GetElementByName("Down");
                            if (this.SoundOn)
                            {
                                this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                                this.Wavplayer.PlayLooping();
                            }
                            this.SendUSBData(this.DOWN);
                            Thread.Sleep(40);
                            this.SendUSBData(this.STOP);
                            this.start         = DateTime.Now;
                            this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT;
                        }
                        this.Action = true;
                        break;
                    }
                    }
                }
                if (elementByName != null)
                {
                    elementByName.isDisplayFore = true;
                    this.myUI.myPictureBox.Invalidate();
                    return;
                }
            }
        }
示例#2
0
        private void CMDHandle(byte[] Data)
        {
            byte num;

            num = (this.VersionProfile != 1 ? Data[1] : Data[2]);
            this.Current_Status = num;
            if (this.Firing && (num & 16) == 16)
            {
                this.DelayStop = true;
                this.timerCnt  = 0;
            }
            if (this.Fired && (num & 16) == 0)
            {
                Form_Fidget fireTimeCnt = this;
                fireTimeCnt.FireTimeCnt = fireTimeCnt.FireTimeCnt + 1;
                if (this.FireTimeCnt > 25)
                {
                    this.myUI.GetElementByName("Fire").isDisplayFore = false;
                    this.myUI.myPictureBox.Invalidate();
                    this.Fired = false;
                }
            }
            if (this.ReSet)
            {
                if (this.ReSet_Status == 0)
                {
                    if ((num & 1) == 1)
                    {
                        this.ReSet_Status = 2;
                    }
                    else
                    {
                        this.SendUSBData(this.DOWN);
                        this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT;
                        this.ReSet_Status  = 1;
                        this.ResetTimeout  = 0;
                    }
                }
                if (this.ReSet_Status == 1 && (num & 1) == 1)
                {
                    this.ReSet_Status = 2;
                    this.ResetTimeout = 0;
                }
                if (this.ReSet_Status == 2)
                {
                    if ((num & 4) == 4)
                    {
                        this.ReSet_Status = 4;
                    }
                    else
                    {
                        this.SendUSBData(this.LEFT);
                        this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT;
                        this.ReSet_Status  = 3;
                        this.ResetTimeout  = 0;
                    }
                }
                if (this.ReSet_Status == 3 && (num & 4) == 4)
                {
                    this.ReSet_Status = 4;
                    this.ResetTimeout = 0;
                }
                if (this.ReSet_Status == 4)
                {
                    this.ReSet_Status = 5;
                    this.SendUSBData(this.RIGHT);
                    this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT;
                    this.start         = DateTime.Now;
                    this.ResetTimeout  = 0;
                }
                if (this.ReSet_Status == 5 && (num & 8) == 8)
                {
                    this.ReSet_Status = 6;
                    this.Horizon      = DateTime.Now.Subtract(this.start);
                    this.Horizon      = TimeSpan.FromMilliseconds(this.Horizon.TotalMilliseconds / 2 * 0.9);
                    this.ResetTimeout = 0;
                }
                if (this.ReSet_Status == 6)
                {
                    this.ReSet_Status = 7;
                    this.SendUSBData(this.LEFT);
                    this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT;
                    this.ResetTimeout  = 0;
                }
                if (this.ReSet_Status == 7 && (num & 4) == 4)
                {
                    this.ReSet_Status = 8;
                    this.start        = DateTime.Now;
                    this.SendUSBData(this.RIGHT);
                    this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT;
                    this.ResetTimeout  = 0;
                }
                if (this.ReSet_Status == 8)
                {
                    this.stop = DateTime.Now.Subtract(this.start);
                    if (this.stop > this.Horizon)
                    {
                        this.ReSet_Status = 9;
                        this.SendUSBData(this.UP);
                        this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT;
                        this.start         = DateTime.Now;
                        this.ResetTimeout  = 0;
                    }
                }
                if (this.ReSet_Status == 9 && (num & 2) == 2)
                {
                    this.ReSet_Status = 10;
                    this.Vertical     = DateTime.Now.Subtract(this.start);
                    this.Vertical     = TimeSpan.FromMilliseconds(this.Vertical.TotalMilliseconds / 2);
                    this.ResetTimeout = 0;
                }
                if (this.ReSet_Status == 10)
                {
                    this.ReSet_Status = 11;
                    this.SendUSBData(this.DOWN);
                    this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT;
                    this.ResetTimeout  = 0;
                }
                if (this.ReSet_Status == 11 && (num & 1) == 1)
                {
                    this.ReSet_Status = 12;
                    this.start        = DateTime.Now;
                    this.SendUSBData(this.UP);
                    this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT;
                    this.ResetTimeout  = 0;
                }
                if (this.ReSet_Status == 12)
                {
                    this.stop = DateTime.Now.Subtract(this.start);
                    if (this.stop > this.Vertical)
                    {
                        this.SendUSBData(this.STOP);
                        this.CurrentAction = Form_Fidget.STATUS.FIRED;
                        this.ResetTimeout  = 0;
                        this.ReSet         = false;
                        this.ReSeted       = true;
                    }
                }
            }
        }
示例#3
0
 private void KeyHandle(string sender, string type)
 {
     if (this.ReSet || !this.DevicePresent)
     {
         if (sender == "Fire")
         {
             this.myUI.GetElementByName("Fire").isDisplayFore = false;
             this.myUI.myPictureBox.Invalidate();
         }
         return;
     }
     if (type == "MouseDown")
     {
         string str  = sender;
         string str1 = str;
         if (str != null)
         {
             if (str1 == "Up")
             {
                 if ((this.Current_Status & 2) != 2 && !this.Firing && !this.Fired)
                 {
                     Thread.Sleep(150);
                     if (this.SoundOn)
                     {
                         this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                         this.Wavplayer.PlayLooping();
                     }
                     this.SendUSBData(this.UP);
                     this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT;
                 }
                 this.Action = true;
                 return;
             }
             if (str1 == "Down")
             {
                 if ((this.Current_Status & 1) != 1 && !this.Firing && !this.Fired)
                 {
                     Thread.Sleep(150);
                     if (this.SoundOn)
                     {
                         this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                         this.Wavplayer.PlayLooping();
                     }
                     this.SendUSBData(this.DOWN);
                     this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT;
                 }
                 this.Action = true;
                 return;
             }
             if (str1 == "Left")
             {
                 if ((this.Current_Status & 4) != 4 && !this.Firing && !this.Fired)
                 {
                     Thread.Sleep(150);
                     if (this.SoundOn)
                     {
                         this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                         this.Wavplayer.PlayLooping();
                     }
                     this.SendUSBData(this.LEFT);
                     this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT;
                 }
                 this.Action = true;
                 return;
             }
             if (str1 != "Right")
             {
                 return;
             }
             if ((this.Current_Status & 8) != 8 && !this.Firing && !this.Fired)
             {
                 Thread.Sleep(150);
                 if (this.SoundOn)
                 {
                     this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav");
                     this.Wavplayer.PlayLooping();
                 }
                 this.SendUSBData(this.RIGHT);
                 this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT;
             }
             this.Action = true;
             return;
         }
     }
     else if (type == "MouseUp")
     {
         this.Action = false;
         if (sender == "Fire" && !this.Firing && !this.Fired && !this.nFire)
         {
             if (this.SoundOn)
             {
                 this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "firing.wav");
                 this.Wavplayer.PlayLooping();
             }
             this.Firing      = true;
             this.FireCheck   = false;
             this.FireTimeout = 0;
             this.SendUSBData(this.FIRE);
             this.FireCnt   = 0;
             this.FireAniEn = true;
             this.SpeedCnt  = 2;
             this.myUI.GetElementByName("Fire").isDisplayFore = true;
             this.myUI.myPictureBox.Invalidate();
         }
         if (!this.Firing && !this.nFire && !this.ReSet && !this.Calibrate)
         {
             if (this.SoundOn)
             {
                 this.Wavplayer.Stop();
             }
             this.SendUSBData(this.STOP);
             this.CurrentAction = Form_Fidget.STATUS.IDLE;
             return;
         }
     }
     else if (type == "MouseEnter" && sender == "Fire")
     {
         if (!this.Firing)
         {
             this.FireAniEn = true;
             this.SpeedCnt  = 5;
             return;
         }
     }
     else if (type == "MouseLeave" && sender == "Fire" && !this.Firing)
     {
         this.FireAniEn     = false;
         this.FireButtonCnt = 1000;
         this.SpeedCnt      = 5;
     }
 }
示例#4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Point position = Cursor.Position;

            position.X = position.X - base.Left;
            position.Y = position.Y - (base.Top - 20);
            this.myUI.ShowToolTip(position);
            Form_Fidget formFidget = this;

            formFidget.timerCnt = formFidget.timerCnt + 1;
            if (this.timerCnt > 1)
            {
                this.timerCnt = 0;
                if (this.DelayStop)
                {
                    this.DelayStop = false;
                    this.SendUSBData(this.STOP);
                    this.FireTimeCnt = 0;
                    this.Firing      = false;
                    this.Fired       = true;
                    this.FireCheck   = false;
                    if (this.VersionProfile == 0)
                    {
                        if (this.SoundOn)
                        {
                            this.Wavplayer.Stop();
                            this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "fired.wav");
                            this.Wavplayer.Play();
                        }
                        this.FireAniEn     = false;
                        this.FireButtonCnt = 1000;
                    }
                    else if (this.VersionProfile == 1 && this.SoundOn && (this.FireTimeout < 30 || this.FireTimeout > 125))
                    {
                        this.Wavplayer.Stop();
                    }
                }
                if (this.Firing)
                {
                    Form_Fidget fireTimeout = this;
                    fireTimeout.FireTimeout = fireTimeout.FireTimeout + 1;
                    if (this.FireTimeout < 15 && this.FireTimeout % 2 == 0)
                    {
                        this.SendUSBData(this.FIRE);
                    }
                    if (this.FireTimeout == 33 && this.VersionProfile == 1)
                    {
                        if (this.SoundOn)
                        {
                            this.Wavplayer.Stop();
                            this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "fired.wav");
                            this.Wavplayer.Play();
                        }
                        this.FireAniEn     = false;
                        this.FireButtonCnt = 1000;
                    }
                    if (this.FireTimeout > 125)
                    {
                        this.DelayStop = true;
                    }
                }
                if (this.ReSet)
                {
                    Form_Fidget resetTimeout = this;
                    resetTimeout.ResetTimeout = resetTimeout.ResetTimeout + 1;
                    if (this.ResetTimeout > 1500)
                    {
                        this.CurrentAction = Form_Fidget.STATUS.FIRED;
                        this.ReSet         = false;
                        this.ReSeted       = true;
                    }
                }
                if (this.ReSeted)
                {
                    this.ReSeted = false;
                    this.myUI.GetElementByName("Reset").isDisplayFore = false;
                    this.myUI.myPictureBox.Invalidate();
                }
                if (this.Firing || this.Fired || this.Action || this.ReSet)
                {
                    this.SendUSBData(this.GET_STATUS);
                }
            }
            if (!this.Action)
            {
                bool reSet = this.ReSet;
            }
            bool firing = this.Firing;

            if (this.UpPress)
            {
                Form_Fidget upCnt = this;
                upCnt.UpCnt = upCnt.UpCnt + 1;
                if (this.UpCnt == 8)
                {
                    this.SendUSBData(this.UP);
                }
            }
            if (this.DownPress)
            {
                Form_Fidget downCnt = this;
                downCnt.DownCnt = downCnt.DownCnt + 1;
                if (this.DownCnt == 8)
                {
                    this.SendUSBData(this.DOWN);
                }
            }
            this.ThunderAnimation();
        }