namespace Tinkerforge
{
    public static class ESilentStepper
    {
        public static (int Acceleration, int Deacceleration) GetSpeedRamping(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetSpeedRamping(out int acceleration, out int deacceleration);
            return (acceleration, deacceleration);
        }

        public static (int StandstillCurrent, int MotorRunCurrent, int StandstillDelayTime, int PowerDownTime, int
            StealthThreshold, int CoolstepThreshold, int ClassicThreshold, bool HighVelocityChopperMode)
            GetBasicConfiguration(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetBasicConfiguration(out int standstillCurrent, out int motorRunCurrent,
                out int standstillDelayTime, out int powerDownTime, out int stealthThreshold, out int coolstepThreshold,
                out int classicThreshold, out bool highVelocityChopperMode);
            return (standstillCurrent, motorRunCurrent, standstillDelayTime, powerDownTime, stealthThreshold,
                coolstepThreshold, classicThreshold, highVelocityChopperMode);
        }

        public static (byte StepResolution, bool Interpolation) GetStepConfiguration(
            this BrickSilentStepper silentStepper)
        {
            silentStepper.GetStepConfiguration(out byte stepResolution, out bool interpolation);
            return (stepResolution, interpolation);
        }

        public static (byte SlowDecayDuration, bool EnableRandomSlowDecay, byte FastDecayDuration, byte
            HysteresisStartValue, short HysteresisEndValue, short SineWaveOffset, byte ChopperMode, byte
            ComparatorBlankTime, bool FastDecayWithoutComparator) GetSpreadcycleConfiguration(
                this BrickSilentStepper silentStepper)
        {
            silentStepper.GetSpreadcycleConfiguration(out byte slowDecayDuration, out bool enableRandomSlowDecay,
                out byte fastDecayDuration, out byte hysteresisStartValue, out short hysteresisEndValue,
                out short sineWaveOffset, out byte chopperMode, out byte comparatorBlankTime,
                out bool fastDecayWithoutComparator);
            return (slowDecayDuration, enableRandomSlowDecay, fastDecayDuration, hysteresisStartValue,
                hysteresisEndValue, sineWaveOffset, chopperMode, comparatorBlankTime, fastDecayWithoutComparator);
        }

        public static (bool EnableStealth, byte Amplitude, byte Gradient, bool EnableAutoscale, bool ForceSymmetric,
            byte FreewheelMode) GetStealthConfiguration(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetStealthConfiguration(out bool enableStealth, out byte amplitude, out byte gradient,
                out bool enableAutoscale, out bool forceSymmetric, out byte freewheelMode);
            return (enableStealth, amplitude, gradient, enableAutoscale, forceSymmetric, freewheelMode);
        }

        public static (byte MinimumStallguardValue, byte MaximumStallguardValue, byte CurrentUpStepWidth, byte
            CurrentDownStepWidth, byte MinimumCurrent, short StallguardThresholdValue, byte StallguardMode)
            GetCoolstepConfiguration(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetCoolstepConfiguration(out byte minimumStallguardValue, out byte maximumStallguardValue,
                out byte currentUpStepWidth, out byte currentDownStepWidth, out byte minimumCurrent,
                out short stallguardThresholdValue, out byte stallguardMode);
            return (minimumStallguardValue, maximumStallguardValue, currentUpStepWidth, currentDownStepWidth,
                minimumCurrent, stallguardThresholdValue, stallguardMode);
        }

        public static (bool DisableShortToGroundProtection, byte SynchronizePhaseFrequency) GetMiscConfiguration(
            this BrickSilentStepper silentStepper)
        {
            silentStepper.GetMiscConfiguration(out bool disableShortToGroundProtection,
                out byte synchronizePhaseFrequency);
            return (disableShortToGroundProtection, synchronizePhaseFrequency);
        }

        public static (byte OpenLoad, byte ShortToGround, byte OverTemperature, bool MotorStalled, byte
            ActualMotorCurrent, bool FullStepActive, byte StallguardResult, byte StealthVoltageAmplitude)
            GetDriverStatus(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetDriverStatus(out byte openLoad, out byte shortToGround, out byte overTemperature,
                out bool motorStalled, out byte actualMotorCurrent, out bool fullStepActive, out byte stallguardResult,
                out byte stealthVoltageAmplitude);
            return (openLoad, shortToGround, overTemperature, motorStalled, actualMotorCurrent, fullStepActive,
                stallguardResult, stealthVoltageAmplitude);
        }

        public static (int CurrentVelocity, int CurrentPosition, int RemainingSteps, int StackVoltage, int
            ExternalVoltage, int CurrentConsumption) GetAllData(this BrickSilentStepper silentStepper)
        {
            silentStepper.GetAllData(out int currentVelocity, out int currentPosition, out int remainingSteps,
                out int stackVoltage, out int externalVoltage, out int currentConsumption);
            return (currentVelocity, currentPosition, remainingSteps, stackVoltage, externalVoltage, currentConsumption);
        }

        public static (char Port, byte ProtocolVersion, byte[] FirmwareVersion, string Name) GetProtocol1BrickletName(
            this BrickSilentStepper silentStepper, char port)
        {
            silentStepper.GetProtocol1BrickletName(port, out byte protocolVersion, out byte[] firmwareVersion, out string name);
            return (port, protocolVersion, firmwareVersion, name);
        }
    }
}
