private static void SetLed(RevPiLeds leds, int led, string color) { LedColor ledColor; switch (color.Substring(0, 1).ToLower()) { case "r": ledColor = LedColor.Red; break; case "g": ledColor = LedColor.Green; break; case "o": ledColor = LedColor.Orange; break; default: ledColor = LedColor.Off; break; } if (led == 1) { leds.SystemLedA1 = ledColor; } else { leds.SystemLedA2 = ledColor; } }
private static void BlinkLeds(RevPiLeds leds) { var pattern = new [] { new [] { LedColor.Red, LedColor.Off }, new [] { LedColor.Off, LedColor.Red }, new [] { LedColor.Green, LedColor.Off }, new [] { LedColor.Off, LedColor.Green }, new [] { LedColor.Orange, LedColor.Off }, new [] { LedColor.Off, LedColor.Orange } }; for (var ix = 0; ix < 10; ix++) { foreach (var ledColors in pattern) { leds.SystemLedA1 = ledColors[0]; leds.SystemLedA2 = ledColors[1]; Thread.Sleep(500); } } leds.SystemLedA1 = LedColor.Off; leds.SystemLedA2 = LedColor.Off; }
private static void Main(string[] args) { Trace.Listeners.Add(new ConsoleTraceListener(false)); if (args.Length == 0 || args.Any(a => new Regex(@"^-[\?hH]$").IsMatch(a))) { // ReSharper disable once AssignNullToNotNullAttribute var fileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); Console.WriteLine($"PiTest V{fileVersionInfo.FileVersion}"); Console.WriteLine(" -s Display system state"); Console.WriteLine(" -d Get device list"); Console.WriteLine(" -v <varName> Get variable info"); Console.WriteLine(" -r <varName> Read variable"); Console.WriteLine(" -y <led> <color> Set system LED (1/2) to color"); Console.WriteLine(" r - red, g - green, o - orange, x - off"); Environment.Exit(0); } var control = new PiControl(); if (!control.Open()) { Console.WriteLine("Could not open PiControl."); Environment.Exit(1); } var config = new PiConfiguration(); if (!config.Open()) { Console.WriteLine("Could not open PiConfiguration."); Environment.Exit(2); } var leds = new RevPiLeds(control, config); string name = (args.Length >= 2) ? args[1] : string.Empty; switch (args[0]) { case "-x": Console.WriteLine("Resetting driver"); control.Reset(); break; case "-d": ListDevices(config); break; case "-s": ShowSystemState(config, control); break; case "-v": if (string.IsNullOrEmpty(name)) { Console.WriteLine("Missing parameter <varName>."); Environment.Exit(3); } ShowVarInfo(config, name); break; case "-r": if (string.IsNullOrEmpty(name)) { Console.WriteLine("Missing parameter <varName>."); Environment.Exit(3); } ReadVarValue(config, control, name); break; case "-y": int.TryParse((args.Length >= 2) ? args[1] : string.Empty, out var led); var color = (args.Length >= 3) ? args[2] : string.Empty; if ((led < 1) || (led > 2) || string.IsNullOrEmpty(color)) { Console.WriteLine("Missing parameter(s) <led> <color>."); Environment.Exit(3); } SetLed(leds, led, color); break; } control.Close(); Environment.Exit(0); }