/// <summary> /// 串口消息数据处理 /// </summary> private void SerialDataProcessing() { while (true) { if (serialDataQueue.Count > 0) { DataPackage tempDP = globalDecoder.Decode(serialDataQueue.Dequeue().ToArray()); if (tempDP.Command == CommandClass._FINISHED_) { //继续 GetFinishMsgEvent.Set(); } } } }
/// <summary> /// 按键控制 /// </summary> private void PositonControl(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints) { ModeLable.Content = "按键控制"; double ax = jointPoints[JointType.HandLeft].X; double ay = jointPoints[JointType.HandLeft].Y; if (ay > 424 || ay < 0 || ax < 0 || ax > 512) { _controlHand.Opacity = 0; } else { _controlHand.Opacity = 100; } if (pt == PositonType.None) { if (ax > 50 && ax < 100 && ay > 120 && ay < 200)//左 { pt = PositonType.Left; } else if (ax > 240 && ax < 290 && ay > 120 && ay < 200)//右 { pt = PositonType.Right; } else if (ax > 120 && ax < 220 && ay > 50 && ay < 100)//前 { pt = PositonType.Forward; } else if (ax > 120 && ax < 220 && ay > 240 && ay < 290)//后 { pt = PositonType.Back; } else if (ax > 120 && ax < 220 && ay > 120 && ay < 160)//上 { pt = PositonType.Up; } else if (ax > 120 && ax < 220 && ay > 180 && ay < 220)//下 { pt = PositonType.Down; } } if (pt == PositonType.Left) //左 { if (ax > 50 && ax < 100 && ay > 120 && ay < 200) //左 { if (TimeLeft == false && StartLeft == false) { TimeLeft = true; _controlHand.StartTimer(); } else if (TimeLeft == true && StartLeft == true) { test.Content = "ok!!"; if (LeftSet == false) { LeftSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeLeft = false; StartLeft = false; LeftSet = false; _controlHand.EndTimer(); test.Content = "no"; } } else if (pt == PositonType.Right)//右 { if (ax > 240 && ax < 290 && ay > 120 && ay < 200) { if (TimeRight == false && StartRight == false) { TimeRight = true; _controlHand.StartTimer(); } else if (TimeRight == true && StartRight == true) { test.Content = "ok!!"; if (RightSet == false) { RightSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeRight = false; StartRight = false; RightSet = false; _controlHand.EndTimer(); test.Content = "no"; } } else if (pt == PositonType.Forward)//前 { if (ax > 120 && ax < 220 && ay > 50 && ay < 100) { if (TimeForward == false && StartForward == false) { TimeForward = true; _controlHand.StartTimer(); } else if (TimeForward == true && StartForward == true) { test.Content = "ok!!"; if (ForwardSet == false) { ForwardSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeForward = false; StartForward = false; ForwardSet = false; _controlHand.EndTimer(); test.Content = "no"; } } else if (pt == PositonType.Back)//后 { if (ax > 120 && ax < 220 && ay > 240 && ay < 290) { if (TimeBack == false && StartBack == false) { TimeBack = true; _controlHand.StartTimer(); } else if (TimeBack == true && StartBack == true) { test.Content = "ok!!"; if (BackSet == false) { BackSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeBack = false; StartBack = false; BackSet = false; _controlHand.EndTimer(); test.Content = "no"; } } else if (pt == PositonType.Up)//上 { if (ax > 120 && ax < 220 && ay > 120 && ay < 160) { if (TimeUp == false && StartUp == false) { TimeUp = true; _controlHand.StartTimer(); } else if (TimeUp == true && StartUp == true) { test.Content = "ok!!"; if (UpSet == false) { UpSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeUp = false; StartUp = false; UpSet = false; _controlHand.EndTimer(); test.Content = "no"; } } else if (pt == PositonType.Down)//下 { if (ax > 120 && ax < 220 && ay > 180 && ay < 220) { if (TimeDown == false && StartDown == false) { TimeDown = true; _controlHand.StartTimer(); } else if (TimeDown == true && StartDown == true) { test.Content = "ok!!"; if (DownSet == false) { DownSet = true; //操作串口 GetFinishMsgEvent.Set(); } } } else { pt = PositonType.None; TimeDown = false; StartDown = false; DownSet = false; _controlHand.EndTimer(); test.Content = "no"; } } }