private ArduinoGaugePoint DefaultMaxPoint() { ArduinoGaugePoint point = new ArduinoGaugePoint() { FalconValue = DefaultFalconMaxValue, StepperValue = (315 * 3) }; point.PropertyChanged += OnPointChanged; return(point); }
private void ExecuteAddAdditionalPoint(object o) { ArduinoGaugePoint previousPoint = AdditionalPointList.LastOrDefault() ?? MinPoint; ArduinoGaugePoint nextPoint = MaxPoint; ArduinoGaugePoint additionalPoint = new ArduinoGaugePoint() { FalconValue = (previousPoint.FalconValue + nextPoint.FalconValue) / 2, StepperValue = (ushort)((previousPoint.StepperValue + nextPoint.StepperValue) / 2) }; }
private ushort FalconValueToStepperValue(float?falconValue) { if (!falconValue.HasValue) { return(-0); } // Clamp value to [min, max] if (falconValue.Value <= MinPoint.FalconValue) { return(MinPoint.StepperValue); } if (falconValue.Value >= MaxPoint.FalconValue) { return(MaxPoint.StepperValue); } // Find the segment that contains falconValue ArduinoGaugePoint previousPoint = MinPoint; ArduinoGaugePoint nextPoint = null; foreach (ArduinoGaugePoint additionalPoint in AdditionalPointList) { if (falconValue.Value >= additionalPoint.FalconValue) { previousPoint = additionalPoint; } else { nextPoint = additionalPoint; break; } } if (nextPoint == null) { nextPoint = MaxPoint; } // Interpolate in segment float normalizedValue = 0.5F; if (previousPoint.FalconValue != nextPoint.FalconValue) { normalizedValue = (falconValue.Value - previousPoint.FalconValue) / (nextPoint.FalconValue - previousPoint.FalconValue); } return((ushort)(normalizedValue * (nextPoint.StepperValue - previousPoint.StepperValue) + previousPoint.StepperValue)); }
private bool CanExecuteRemoveAdditionalPoint(object o) { ArduinoGaugePoint additionalPoint = (ArduinoGaugePoint)o; return(AdditionalPointList.Contains(additionalPoint)); }
private void ExecuteRemoveAdditionalPoint(object o) { ArduinoGaugePoint additionalPoint = (ArduinoGaugePoint)o; AdditionalPointList.Remove(additionalPoint); }