using MrEModuleSdk.Devices.Mre3;
using MrEModuleSdk.Dto;
using System;

namespace Mre3Example
{
    public partial class Mre3Example
    {
        private static void RunStaticInputExample(IMrE3SdkComDeviceController controller)
        {
            Console.WriteLine("Static input example");
            Console.WriteLine("Switches both axes to static current input and writes small demonstration currents.");
            Console.WriteLine();

            controller.SignalFlowManager.InputStage.ChangeActiveSystem(EAxis.X, EmrEInputStageSystems.StaticValue);
            controller.SignalFlowManager.InputStage.ChangeActiveSystem(EAxis.Y, EmrEInputStageSystems.StaticValue);

            controller.SignalFlowManager.InputStage.StaticValue.WriteCurrent(EAxis.X, 0.1f);
            controller.SignalFlowManager.InputStage.StaticValue.WriteCurrent(EAxis.Y, -0.1f);
            controller.SignalFlowManager.InputConditioningStage.OffsetAndScale.WriteScale(EAxis.X, 0.5f);
            controller.SignalFlowManager.InputConditioningStage.OffsetAndScale.WriteScale(EAxis.Y, 0.5f);

            Console.WriteLine($"Axis X current setpoint: {controller.SignalFlowManager.InputStage.StaticValue.ReadCurrent(EAxis.X):F3} A");
            Console.WriteLine($"Axis Y current setpoint: {controller.SignalFlowManager.InputStage.StaticValue.ReadCurrent(EAxis.Y):F3} A");

            WaitForEnter("Static current values applied. Press Enter to reset both axes to 0 A.");

            controller.SignalFlowManager.InputStage.StaticValue.WriteCurrent(EAxis.X, 0.0f);
            controller.SignalFlowManager.InputStage.StaticValue.WriteCurrent(EAxis.Y, 0.0f);
            Console.WriteLine("Static currents reset to 0 A.");
        }
    }
}
