Example #1
0
 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);
 }
Example #2
0
 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());
 }
Example #3
0
        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}");
                    }
                }
            }
        }
Example #4
0
 public static void CleanAll(PinManager manager)
 {
     manager.CleanAll();
 }
Example #5
0
 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);
 }