private void pinValueChanged(object sender, GpioValueChangedEventArgs e) { ticksSinceLastStep = 0; if (Direction == MoveDirection.Stopped) { System.Diagnostics.Debug.WriteLine($"{Axis} motor moved when in Stopped State!"); } }
private void realPinValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e) { GpioValueChangedEventArgs edgeArgs = new GpioValueChangedEventArgs(GpioEdge.FallingEdge); if (e.Edge == GpioPinEdge.RisingEdge) { edgeArgs = new GpioValueChangedEventArgs(GpioEdge.RisingEdge); } ValueChanged?.Invoke(this, edgeArgs); }
private void pinValueChanged(object sender, GpioValueChangedEventArgs e) { if (e.Edge == GpioEdge.FallingEdge) { // If motor hasn't move and latestActiveMoveDirection is still Stopped, this will not impact anything because the Stopped value is 0. var pos = 0; var direction = motorInfo.Direction; lock (lockObject) { lastMoveDirection = direction; position += (int)direction; pos = position; } onStepCounted(pos, direction); } }
private void bottomInterruptDetected(object sender, GpioValueChangedEventArgs e) { var pos = locator.Position; switch (State) { case CalibrationState.PreparingToCalibrate: // Check if can enter the Calibrating state if (e.Edge == GpioEdge.FallingEdge) { if (motorInfo.Direction == MoveDirection.Forward) { State = CalibrationState.Calibrating; lowerBottomPos = pos; } } else { if (motorInfo.Direction == MoveDirection.Backward) { mover.CancelMove(); } } break; case CalibrationState.Calibrating: // Update nullable positions if (e.Edge == GpioEdge.FallingEdge) { if (motorInfo.Direction == MoveDirection.Forward) { lowerBottomPos = pos; } else { upperBottomPos = pos; } } else { if (motorInfo.Direction == MoveDirection.Backward) { lowerBottomPos = pos; mover.CancelMove(); } else { upperBottomPos = pos; } } break; case CalibrationState.Ready: // Check we're still calibrated var offset = Math.Abs(pos - bottom.StepPosition); var tolerance = (upperBottomPos.Value - lowerBottomPos.Value) / 2 + 0.25 * StepsPerGridUnit; if (offset > tolerance) { System.Diagnostics.Debug.WriteLine($"Need to calibrate {motorInfo.Axis} motor."); State = CalibrationState.NeedsCalibrating; } break; } }