public static void ExportPin(PinManager manager, string command) { var split = command.Split(); if (split.Count() != 2) return; var pinnum = split[1]; PinType pintype; if (!Enum.TryParse<PinType>("GPIO" + pinnum, out pintype)) return; manager.Export(pintype); }
public static void Read(PinManager manager, string command) { var split = command.Split(); if (split.Count() != 2) return; var pinnum = split[1]; PinType pintype; if (!Enum.TryParse<PinType>("GPIO" + pinnum, out pintype)) return; var result = manager.Read(pintype); System.Console.WriteLine("{0}:{1}", pintype.ToString(), result.ToString()); }
public static void Main(string[] args) { using (var manager = new PinManager()) { System.Console.WriteLine("Press 'h' for help."); while (true) { try { var command = System.Console.ReadLine(); var commandsplit = command.Split(); if (!commandsplit.Any()) continue; var commandtype = commandsplit[0]; if (commandtype == "h") WriteHelp(); else if (commandtype == "e") ExportPin(manager, command); else if (commandtype == "u") UnExportPin(manager, command); else if (commandtype == "w") WritePin(manager, command); else if (commandtype == "c") CleanAll(manager); else if (commandtype == "p") Pause(command); else if (commandtype == "r") Read(manager, command); } catch (Exception ex) { System.Console.WriteLine($"Error: {ex.Message}"); } } } }
public static void CleanAll(PinManager manager) { manager.CleanAll(); }
public static void WritePin(PinManager manager, string command) { var split = command.Split(); if (split.Count() != 3) return; var pinnum = split[1]; PinType pintype; if (!Enum.TryParse<PinType>("GPIO" + pinnum, out pintype)) return; int val; if (!int.TryParse(split[2], out val)) return; var bval = val == 1 ? true : false; manager.Write(pintype, bval); }