private static bool GetIoControlType(object sender, out IoControl control, out IoControlType ioControlType) { control = sender as IoControl; ioControlType = IoControlType.Unknown; var ioControlTypeStr = control != null && control.Tag != null?control.Tag.ToString() : null; return(!String.IsNullOrEmpty(ioControlTypeStr) && Enum.TryParse(ioControlTypeStr, true, out ioControlType)); }
private bool GetRawValue(IoControl control, IoControlType ioControlType, out byte rawValue) { rawValue = 0; var value = control.GetCurrentvalue(); if (!value.Item1) { return(false); } var phisvalue = value.Item3; switch (ioControlType) { case IoControlType.RxxStep: rawValue = (byte)Math.Round(phisvalue, MidpointRounding.AwayFromZero); break; case IoControlType.XxRpm: rawValue = (byte)Math.Round(phisvalue / 10, MidpointRounding.AwayFromZero); break; case IoControlType.Alf: rawValue = (byte)Math.Round(phisvalue * 256 / 14.7 - 128, MidpointRounding.AwayFromZero); break; case IoControlType.Uoz: rawValue = (byte)Math.Round(phisvalue * 2, MidpointRounding.AwayFromZero); break; case IoControlType.Duoz: rawValue = (byte)Math.Round(phisvalue, MidpointRounding.AwayFromZero); break; case IoControlType.Faza: rawValue = (byte)Math.Round(phisvalue / 6, MidpointRounding.AwayFromZero); break; case IoControlType.InjCoeff: rawValue = (byte)Math.Round(phisvalue * 256 - 128, MidpointRounding.AwayFromZero); break; case IoControlType.Twat: rawValue = (byte)Math.Round(phisvalue + 60, MidpointRounding.AwayFromZero); break; } return(true); }