namespace Nonemm.Keying; /// Reads the bytes a WinKeyer sends back in host mode and works out when it has /// stopped sending. /// /// A byte from 0xC0 to 0xDF is a status byte; the low six bits are the flags, /// and 0x04 is set while the keyer is sending. Bytes from 0x80 to 0xBF are the /// speed pot, and printable bytes are the keyer echoing what it has sent. /// Neither says anything about the buffer, so both are passed over. /// /// Where the bit meanings come from: `docs/keying.md`. public sealed class WinkeyerStatus { private const byte StatusLow = 0xC0; private const byte StatusHigh = 0xDF; private const byte BusyFlag = 0x04; public bool IsSending { get; private set; } /// True on the byte that says the keyer has finished: it was sending and /// now is not. Every other byte returns false, including a second status /// byte that repeats what the last one said. public bool Read(byte value) { if (value is < StatusLow or > StatusHigh) { return false; } bool wasSending = IsSending; IsSending = (value & BusyFlag) != 0; return wasSending && !IsSending; } }