Esempio n. 1
0
 /// <summary>
 /// 完成手势控制操作
 /// </summary>
 /// <param name="zbData"></param>
 private void OnDoGesture(ZigBeeData zbData)
 {
     WriteLine("doGesture");
     try
     {
         if (zbData.m_byData[2] >= 0 && zbData.m_byData[2] <= 2)
         {
             (CurtainControl[(int)zbData.m_byData[2]])();
         }
         if (zbData.m_byData[3] >=0 && zbData.m_byData[3] <= 1)
         {
             (LightControl[(int)zbData.m_byData[3]])();
         }
     }
     catch (Exception ex)
     {
         WriteLine(ex.Message);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 完成空中鼠标操作
        /// </summary>
        /// <param name="zbData"></param>
        private void OnDoAMouse(ZigBeeData zbData)
        {
            switch (zbData.BendSensor)
            {
                case (byte)AMouseAction.Move:
                    {
                        // 若为两弯曲传感器恢复原状
                        if (m_bLeftDown)
                        {
                            m_bLeftDown = false;
                            MouseControl.LeftUp();
                        }

                        // 若为无名指弯曲传感器恢复原状
                        if (m_bRightDown)
                        {
                            m_bRightDown = false;
                            MouseControl.RightUp();
                        }

                        // 移动鼠标
                        MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
                    } break;
                case (byte)AMouseAction.Click:
                    {
                        // 若两弯曲传感器未弯曲
                        if (!m_bLeftDown)
                            m_bLeftDown = true;

                        // 鼠标左键按下
                        MouseControl.LeftDown();

                        // 移动鼠标
                        MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
                    } break;
                case (byte)AMouseAction.Gesture:
                    {
                        // 若无名指弯曲传感器未弯曲
                        if (!m_bRightDown)
                            m_bRightDown = true;
                        else
                        {
                            // 若为两弯曲传感器恢复原状
                            if (m_bLeftDown)
                            {
                                m_bLeftDown = false;
                                MouseControl.LeftUp();
                            }
                        } // end of else

                        // 鼠标右键按下
                        MouseControl.RightDown();

                        // 移动鼠标
                        MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
                    } break;
            } // end of switch
        }
Esempio n. 3
0
 /// <summary>
 /// 完成游戏控制操作
 /// </summary>
 /// <param name="zbData"></param>
 private void OnDoGameCtrl(ZigBeeData zbData)
 {
     #region switch方式
     //        	switch (zbData.BendSensor)
     //        	{
     //        		case (byte)AMouseAction.Move:
     //        		{ // 收到 AMouseAction.Move 指令
     //        			switch (m_byLastGesture)
     //        			{
     //        				case (byte)AMouseAction.Move:
     //        				{
     //
     //        				}break;
     //        				case (byte)AMouseAction.Gesture:
     //        				{
     //        					m_myIoSys.KeyPress(WinIoSys.Key.VK_ESCAPE);
     //        					tmrGame.Start();
     //        					tmrGame.Tag = "2";
     //        				}break;
     //        				case (byte)AMouseAction.Click: break;
     //        			} // end of switch
     //        		}break;
     //        		case (byte)AMouseAction.Gesture:
     //        		{ // 收到 AMouseAction.Gesture 指令
     //        			switch (m_byLastGesture)
     //        			{
     //        				case (byte)AMouseAction.Move:
     //        				{
     //        					// 退出游戏模式
     //        					m_bGameMode = false;
     //        					if ("2" == (string)tmrGame.Tag)
     //        					{
     //        						tmrGame.Stop();
     //        						tmrGame.Tag = "1";
     //        					}
     //        				}break;
     //        				case (byte)AMouseAction.Gesture:
     //        				{ // 移动鼠标
     //        					MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
     //        				}break;
     //        				case (byte)AMouseAction.Click: break;
     //        			} // end of switch
     //        		}break;
     //        		case (byte)AMouseAction.Click:
     //        		{ // 收到 AMouseAction.Click 指令
     //
     //        		}break;
     //        		default: m_byLastGesture = (byte)AMouseAction.Init; return;
     //        	} // end of switch
     #endregion
     try
     {
         m_mreExiting.WaitOne();
         if (zbData.BendSensor == 0x02) return;
         // 执行状态转换函数
         (GameControl[(int)zbData.BendSensor, m_byLastGesture])(zbData);
         m_byLastGesture = zbData.BendSensor;
         m_byLastDirection = zbData.GameContral;
     }
     catch (Exception ex)
     {
         WriteLine(ex.Message);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 初始状态->单击状态状态
        /// </summary>
        /// <param name="zbData"></param>
        private void GameStatusChange_3_4(ZigBeeData zbData)
        {
            WriteLine("4 -> 3");
            if (m_bGameMode)
            { // 游戏模式下,停止计时
                StopTimer();
            } // end of if
            else
            { // 控制模式下, 按一次 esc键 ,开始计时
                // 按 esc键
                m_myIoSys.KeyPressEx(WinIoSys.Key.VK_ESCAPE, 100);

                StartTimer();
            } // end of else
        }
Esempio n. 5
0
 /// <summary>
 /// 处理手套数据包
 /// </summary>
 /// <param name="zbData"></param>
 private void GloveDataRecived(ZigBeeData zbData)
 {
     if (zbData.m_byData.Length == zbData.nDataLength)
     {
         WriteLine(
             string.Format("light[{0}], curtain[{1}]", zbData.m_byData[3].ToString(), zbData.m_byData[2].ToString()));
         switch (zbData.GloveMode)
         {
             case (byte)GloveFunction.AMouse:
                 _DoAMouse(zbData);
                 break;
             case (byte)GloveFunction.GestureCtrl:
                 _DoGesture(zbData);
                 break;
             default:
                 break;
         } // end of switch
     } // end of if
     else
     {
         WriteLine(
             String.Format(
                 "数据包接受错误(标识长度[{0}],实际长度[{1}])",
                 zbData.nDataLength,
                 zbData.m_byData.Length));
     } // end of else
 }
Esempio n. 6
0
 /// <summary>
 /// 手势状态->单击状态
 /// </summary>
 /// <param name="zbData"></param>
 private void GameStatusChange_3_1(ZigBeeData zbData)
 {
     WriteLine("1 -> 3");
     if (m_bGameMode)
     { // 游戏模式下,停止计时
         StopTimer();
     } // end of if
     else
     { // 控制模式下,单击左键,开始计时
         MouseControl.LeftClick();
         WriteLine("left click");
         StartTimer();
     } // end of else
 }
Esempio n. 7
0
        /// <summary>
        /// 单击状态->单击状态
        /// </summary>
        /// <param name="str"></param>
        private void GameStatusChange_3_3(ZigBeeData zbData)
        {
            // 若在控制模式下, 则什么也不做~
            WriteLine("3 -> 3");
            if (m_bGameMode)
            {
                // 弹起上次的按键
                if (zbData.GameContral != m_byLastDirection &&
                    (byte)GameCtrl.Forward != m_byLastDirection &&
                    (byte)GameCtrl.Init != m_byLastDirection)
                {
                    m_myIoSys.KeyUpEx(DirectionKeyMap[(int)m_byLastDirection], 1);
                }

                // 前进
                m_myIoSys.KeyDownEx(WinIoSys.Key.VK_UP, 1);

                // 根据当前状态转向
                if (zbData.GameContral != (byte)GameCtrl.Forward)
                {
                    m_myIoSys.KeyDownEx(DirectionKeyMap[(int)zbData.GameContral], 1);
                    WriteLine("^ + " + debugKeyMap[(int)zbData.GameContral]);
                }
            } // end of if
        }
Esempio n. 8
0
 /// <summary>
 /// 2 状态暂时无用
 /// </summary>
 /// <param name="str"></param>
 private void GameStatusChange_2_1(ZigBeeData zbData)
 {
 }
Esempio n. 9
0
        /// <summary>
        /// 移动状态->单击状态
        /// </summary>
        /// <param name="zbData"></param>
        private void GameStatusChange_3_0(ZigBeeData zbData)
        {
            // 若未进入游戏状态,则什么也不做~
            WriteLine("0 -> 3");
            if (m_bGameMode)
            {
                // 弹起上次的按键
                if (zbData.GameContral != m_byLastDirection &&
                    (byte)GameCtrl.Forward != m_byLastDirection &&
                    (byte)GameCtrl.Init != m_byLastDirection)
                {
                    m_myIoSys.KeyUpEx(DirectionKeyMap[(int)m_byLastDirection], 1);
                }

                // 弹起后退键
                m_myIoSys.KeyUpEx(WinIoSys.Key.VK_DOWN, 1);

                // 前进
                m_myIoSys.KeyDownEx(WinIoSys.Key.VK_UP, 1);

                // 根据当前状态转向
                if (zbData.GameContral != (byte)GameCtrl.Forward)
                    m_myIoSys.KeyDownEx(DirectionKeyMap[(int)zbData.GameContral], 1);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 初始状态->手势状态
 /// </summary>
 /// <param name="zbData"></param>
 private void GameStatusChange_1_4(ZigBeeData zbData)
 {
     WriteLine("4 -> 1");
     if (m_bGameMode)
     { // 游戏模式下,开始计时
         StartTimer();
     } // end of if
     else
     { // 控制模式下,单击左键,停止计时
         StopTimer();
     } // end of else
     MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
 }
Esempio n. 11
0
 /// <summary>
 /// 单击状态->手势状态
 /// </summary>
 /// <param name="zbData"></param>
 private void GameStatusChange_1_3(ZigBeeData zbData)
 {
     WriteLine("3 -> 1");
     if (!m_bGameMode)
     { // 若未进入游戏模式,停止计时
         StopTimer();
     } // end of if
     else
     { // 若已进入游戏模式
         StartTimer();
     } // end of else
 }
Esempio n. 12
0
 /// <summary>
 /// 手势状态->手势状态
 /// </summary>
 /// <param name="zbData"></param>
 private void GameStatusChange_1_1(ZigBeeData zbData)
 {
     // 若在游戏模式下,则什么也不做~
     WriteLine("1 -> 1");
     if (!m_bGameMode)
     { // 移动鼠标
         MouseControl.MoveCursor(zbData.XMovement, zbData.YMovement);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// 移动状态->移动状态
        /// </summary>
        private void GameStatusChange_0_0(ZigBeeData zbData)
        {
            // 如果没进入游戏模式就什么也不做~
            WriteLine("0 -> 0, gameMode[" + m_bGameMode.ToString() + "]");
            if (m_bGameMode)
            { // 若已经进入游戏模式
                // 弹起上次的按键
                if (zbData.GameContral != m_byLastDirection &&
                    (byte)GameCtrl.Forward != m_byLastDirection &&
                    (byte)GameCtrl.Init != m_byLastDirection)
                {
                    m_myIoSys.KeyUpEx(DirectionKeyMap[(int)m_byLastDirection], 1);
                }

                // 后退
                //m_myIoSys.KeyDown(WinIoSys.Key.VK_DOWN);
                m_myIoSys.KeyDownEx(WinIoSys.Key.VK_DOWN, 1);

                // 根据当前状态转向
                if (zbData.GameContral != (byte)GameCtrl.Forward)
                {
                    //m_myIoSys.KeyDown(DirectionKeyMap[(int)zbData.GameContral]);
                    m_myIoSys.KeyDownEx(DirectionKeyMap[(int)zbData.GameContral],1);
                    WriteLine("v + " + debugKeyMap[(int)zbData.GameContral]);
                }
            } // end of if
        }
Esempio n. 14
0
        private void spGlove_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                if (!m_bRecivingData)
                {
                    byte[] bysTemp = new byte[10];
                    spGlove.Read(bysTemp, 0, 1);

                    m_bRecivingData = true;

                    #region 检验包头
                    while (true)
                    { // 向后寻找直到找到 头部为 “0x02 0x00 0x18”的包
                        if (bysTemp[0] == 0x02)
                        {
                            spGlove.Read(bysTemp, 1, 1);
                            if (bysTemp[1] == 0x00)
                            {
                                spGlove.Read(bysTemp, 2, 1);
                                if (bysTemp[2] == 0x18)
                                    break;
                                else
                                {
                                    bysTemp[0] = bysTemp[2];
                                }
                            }
                            else
                            {
                                bysTemp[0] = bysTemp[1];
                                WriteLine("wrong follow message[" + bysTemp[1].ToString() + "]");
                            }
                        } // end of if
                        else
                        {
                            WriteLine("wrong message[" + bysTemp[0].ToString() + "]");
                            spGlove.Read(bysTemp, 0, 1);
                        }
                    } // end of while
                    #endregion
                    int i = spGlove.Read(bysTemp, 3, ((int)HEAD_LEN.ZIGBEE_HEAD_LEN - 3));
                    while (i < ((int)HEAD_LEN.ZIGBEE_HEAD_LEN - 3))
                    {
                        i += spGlove.Read(bysTemp, 3 + i, ((int)HEAD_LEN.ZIGBEE_HEAD_LEN - 3 - i));
                        //WriteLine("reading");
                    }
                    if (bysTemp[3] <= 0)
                    {
                        return;
                    }
                    m_zbAMouse = new ZigBeeData(bysTemp);
                    if (m_zbAMouse.DataHead.CLUST == 0)
                    {
                        //Thread.Sleep(200);
                    }
                } // end of if
                int nRecived = 0;
                while (nRecived < m_zbAMouse.DataHead.DATA_LEN - 2)
                { // 继续访问缓冲区直到读取全部数据包
                    nRecived += spGlove.Read(m_zbAMouse.m_byData
                                              , nRecived
                                              , m_zbAMouse.nDataLength - nRecived);
                } // end of while
                // 读取校验位
                m_zbAMouse.m_byFSC = (byte)spGlove.ReadByte();
                //WriteLine("fsc[" + m_RcvData.m_byFSC.ToString() + "]");

                // 调整标记准备接受下个数据包
                m_bRecivingData = false;
                //zigbeeDataRecived(this);
                GloveDataRecived(m_zbAMouse);
            } // end of try
            catch (Exception ex)
            {
                WriteLine(ex.Message);
            }
        }