private async Task <int> Run(Options options) { try { using (var ledDriver = LedDriver.Create()) { var displayDriver = new DisplayDriver(ledDriver); Task task; if (options.StringValue != null) { if (options.ForceScroll || DisplayFrame.GetDisplayedStringLength(options.StringValue) > 3) { task = displayDriver.ScrollString(options.StringValue, options.Duration); } else { displayDriver.WriteString(options.StringValue); task = Task.Delay(options.Duration); } } else if (options.DecimalValue != null) { displayDriver.WriteFrame(DisplayFrame.FromDecimal(options.DecimalValue.Value, StatusLed.Blue)); task = Task.Delay(options.Duration); } else if (options.BusyDelay != null) { task = displayDriver.BusyLoop(options.BusyDelay.Value, options.Duration); } else if (options.RawValue != null) { for (int i = 0; i < 32; i++) { bool bit = ((options.RawValue.Value << i) & 0x80000000u) != 0u; ledDriver.WriteBit(bit); } ledDriver.Latch(); task = Task.Delay(options.Duration); } else { Console.WriteLine("No option selected."); return(-1); } await task; displayDriver.Clear(); } return(0); } catch (Exception ex) { Console.WriteLine($"Error: {ex}"); return(-1); } }
private static DisplayFrame CreateFrameDecimal(decimal value) => DisplayFrame.FromDecimal(value, StatusLed.Blue);