/// <summary> /// This methods runs everytime some data is received in serial port. /// Based on the packet's leading string, it controls mouse or shows error message. /// </summary> /// <param name="sender"> Event sender </param> /// <param name="e"> Event argument </param> private void SPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { str = SPort.ReadLine(); if (str[0] == 'G') { GetV = str.Split(' '); X = (int)(((Convert.ToDouble(GetV[1]) + X_MAX_DEGREE) / (2 * X_MAX_DEGREE)) * MAP_VAL); Y = (int)(((Convert.ToDouble(GetV[2]) * YInversionMultiplier + Y_MAX_DEGREE) / (2 * Y_MAX_DEGREE)) * MAP_VAL); if (SafetyMechanism && X == 0 && Y == 0) { End(); } BufferX[counter] = X; BufferY[counter] = Y; counter = (counter + 1) % FILTER_RESOLUTION; X = (int)BufferX.Average(); Y = (int)BufferY.Average(); BufferX2[counter2] = X; BufferY2[counter2] = Y; counter2 = (counter2 + 1) % FILTER2_RESOLUTION; X = (int)BufferX2.Average(); Y = (int)BufferY2.Average(); VirtualMouse.MoveTo(X, Y); } else if (str[0] == 'L') { GetV = str.Split(' '); int LMB = Convert.ToInt32(GetV[1]); if (LMB == 1) { VirtualMouse.LeftDown(); } else { VirtualMouse.LeftUp(); } } else if (str[0] == 'R') { GetV = str.Split(' '); int RMB = Convert.ToInt32(GetV[1]); if (RMB == 1) { VirtualMouse.RightDown(); } else { VirtualMouse.RightUp(); } } else if (str[0] == 'M') { //str.TrimStart('M', ' '); //str = str.Trim(); //Console.WriteLine(str); } }
/// <summary> /// This methods runs everytime some data is received in serial port. /// Based on the packet's leading string, it controls mouse or shows error message. /// </summary> /// <param name="sender"> Event sender </param> /// <param name="e"> Event argument </param> private void SPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { str = SPort.ReadLine(); if (str[0] == 'G') { GetV = str.Split(' '); X = (int)(Convert.ToDouble(GetV[1])); Y = YInversionVal + YInversionMultiplier * (int)(Convert.ToDouble(GetV[2])); LMB = Convert.ToInt32(GetV[3]); RMB = Convert.ToInt32(GetV[4]); if (SafetyMechanism && X == 0 && Y == 0) { End(); } VirtualMouse.MoveTo(X, Y); if (LMB <= ClickFloor && !LMBDown) { if (ClickMode) { VirtualMouse.LeftClick(); } else { VirtualMouse.LeftDown(); } LMBDown = true; } else if (LMB > ClickFloor && LMBDown) { if (!ClickMode) { VirtualMouse.LeftUp(); } LMBDown = false; } if (RMB <= ClickFloor && !RMBDown) { VirtualMouse.RightDown(); RMBDown = true; } else if (RMB > ClickFloor && RMBDown) { VirtualMouse.RightUp(); RMBDown = false; } } else if (str[0] == 'M') { //str.TrimStart('M', ' '); //str = str.Trim(); //Console.WriteLine(str); } }