private PoKeysStepperPoint DefaultMinPoint() { PoKeysStepperPoint point = new PoKeysStepperPoint() { FalconValue = DefaultFalconMinValue, StepperValue = 0 }; point.PropertyChanged += OnPointChanged; return(point); }
private void executeAddAdditionalPoint(object o) { PoKeysStepperPoint previousPoint = AdditionalPointList.LastOrDefault() ?? MinPoint; PoKeysStepperPoint nextPoint = MaxPoint; PoKeysStepperPoint additionalPoint = new PoKeysStepperPoint() { FalconValue = (previousPoint.FalconValue + nextPoint.FalconValue) / 2, StepperValue = ((previousPoint.StepperValue + nextPoint.StepperValue) / 2) }; AdditionalPointList.Add(additionalPoint); }
private PoKeysStepperPoint DefaultMaxPoint() { float falconMaxValue = DefaultFalconMaxValue; if (falconGauge != null) { falconMaxValue = falconGauge.MaxValue; } PoKeysStepperPoint point = new PoKeysStepperPoint() { FalconValue = falconMaxValue, StepperValue = 4320 }; point.PropertyChanged += OnPointChanged; return(point); }
private int FalconValueToStepperValue(float?falconValue) { if (!falconValue.HasValue) { return(0); } if (!ContinuousRotation) { // 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 PoKeysStepperPoint previousPoint = MinPoint; PoKeysStepperPoint nextPoint = null; foreach (PoKeysStepperPoint 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((int)(normalizedValue * (nextPoint.StepperValue - previousPoint.StepperValue) + previousPoint.StepperValue)); } else // Working with Cont. Rotation stepper { int currentStepperPos = stepperPosition; //int currentStepperPos = owner.ReadStepper(StepperId.GetValueOrDefault() - 1); int stepsPerRotation = MaxPoint.StepperValue; int newStepPosition = (int)(falconValue.Value * (stepsPerRotation / (float)fullTurnValue)); // Convert desired position in degrees to steps // // Convert current step position (which could be quite large) to a Modulo 4320 step value. // This is step value equivilant to 0-360 (Modulo 360) in degrees. // int modulo4320CurrStepPosition = currentStepperPos % stepsPerRotation; int modulo4320NewStepPosition = newStepPosition % stepsPerRotation; if ((modulo4320CurrStepPosition < (stepsPerRotation / 2) + modulo4320CurrStepPosition) && // Current value between 0 & 2160 steps (0 & 180 deg)? (modulo4320NewStepPosition > (stepsPerRotation / 2) + modulo4320CurrStepPosition)) // New position is between 2160 and 4320 (180 & 360 deg)? { // // Turning Left past 0 degrees. Do Negative Step Math. (I need to figure this out) // // so if new pos is 4200 and current pos is 120 then // 4200 - 4310 = -120 // -120 - 120 = -240 modulo4320NewStepPosition = modulo4320NewStepPosition - stepsPerRotation; // find the negativ value from 0 back to new position modulo4320NewStepPosition = modulo4320NewStepPosition - modulo4320CurrStepPosition; // add the minus current value to this currentStepperPos += modulo4320NewStepPosition; } else { // Otherwise do Positive Step Math int difference = newStepPosition - modulo4320CurrStepPosition; if (difference < -stepsPerRotation / 2) { difference += stepsPerRotation; } if (difference > stepsPerRotation) { difference -= stepsPerRotation; } currentStepperPos += difference; } return(currentStepperPos); } }
private bool canExecuteRemoveAdditionalPoint(object o) { PoKeysStepperPoint additionalPoint = (PoKeysStepperPoint)o; return(AdditionalPointList.Contains(additionalPoint)); }
private void executeRemoveAdditionalPoint(object o) { PoKeysStepperPoint additionalPoint = (PoKeysStepperPoint)o; AdditionalPointList.Remove(additionalPoint); }