using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; namespace DTS.Common.Converters { public class InitialOffsetToIEPESensorOffsetConverter : IValueConverter { /// /// Used to convert millivolt offset to IEPE sensor offset in volts /// /// /// /// /// /// public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is double milliUnit) { return ConvertDouble(milliUnit); } else { return 0D; } } const double IEPE_MIDPOINT = 12.25D; public static double ConvertDouble(double milliUnit) { if (double.IsNaN(milliUnit)) { return 0D; } return (milliUnit / 1000.0D) + IEPE_MIDPOINT; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is double unit) { if (double.IsNaN(unit)) { return 0D; } return (unit - IEPE_MIDPOINT) * 1000.0D; } else { return 0D; } } } }