using Nonemm.Keying; namespace Nonemm.Digital; /// The digital engine as something that sends a message, so a macro goes out /// through the same expander, the same `{END}` handling and the same ESM as a /// CW message does. public sealed class DigitalEngineSender : MessageSender { private readonly DigitalEngine engine; public DigitalEngineSender(DigitalEngine engine) { this.engine = engine; engine.TransmitChanged += WhenTransmitChanged; } public bool IsReady => engine.IsConnected; /// The engine says when it has stopped transmitting, which is the same /// thing a keyer reports. public bool ReportsCompletion => true; public event EventHandler? Finished; public Task SendAsync(string text, CancellationToken cancellation = default) => engine.SendAsync(text, cancellation); public Task AbortAsync(CancellationToken cancellation = default) => engine.AbortAsync(cancellation); /// RTTY runs at the speed the engine is set to, so there is nothing to set /// per message. public Task SetSpeedAsync(int wordsPerMinute, CancellationToken cancellation = default) => Task.CompletedTask; public void Dispose() => engine.TransmitChanged -= WhenTransmitChanged; private void WhenTransmitChanged(object? sender, bool transmitting) { if (!transmitting) { Finished?.Invoke(this, EventArgs.Empty); } } }