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

namespace Mre3Example
{
    public partial class Mre3Example
    {
        private static void RunSignalGeneratorExample(IMrE3SdkComDeviceController controller)
        {
            Console.WriteLine("Signal generator example");
            Console.WriteLine("Drives axis X with a triangle waveform for five seconds.");
            Console.WriteLine();

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

            const float amplitude = 0.2f;
            const float frequency = 2.0f;
            const float offset = 0.0f;
            const float phaseDelay = 90.0f;
            const bool isRunning = true;
            var shape = EWaveformShape.Triangle;
            var sgValues = new SignalGeneratorValuesDto(amplitude, frequency, offset, phaseDelay, (int)shape, isRunning);

            controller.SignalFlowManager.InputStage.SignalGenerator.WriteSignalGeneratorValues(sgValues, EAxis.X);
            Console.WriteLine($"Waveform: {shape}");
            Console.WriteLine($"Amplitude: {amplitude}");
            Console.WriteLine($"Frequency: {frequency} Hz");
            Console.WriteLine($"Phase delay: {phaseDelay} deg");
            Console.WriteLine("Signal generator running...");

            Thread.Sleep(5000);
            controller.SignalFlowManager.InputStage.SignalGenerator.SwitchRunning(EAxis.X, false);

            Console.WriteLine("Signal generator stopped.");
            WaitForEnter();
        }
    }
}
