Beispiel #1
0
        static async Task <int> Main(string[] args)
        {
            var a = new AbsArguments(args);

            if (!a.IsValid())
            {
                Console.WriteLine($"Usage: {Process.GetCurrentProcess().ProcessName} <args>");
                Console.WriteLine($"Possible args: {string.Join(", ", AbsArguments.GetPossibleArgs())}");
                return(-1);
            }
            using (var source = new CancellationTokenSource())
            {
                Console.CancelKeyPress += (s, e) => source.Cancel();
                try
                {
                    Pi.Init <BootstrapWiringPi>();
                    if (a.Calibrate)
                    {
                        await CalibrateAsync(source.Token);
                    }
                    else
                    {
                        await RunAsync(a, source.Token);
                    }
                    return(0);
                }
                catch (TaskCanceledException)
                {
                    Console.WriteLine("Bye!");
                    return(0);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.GetType().FullName);
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return(-1);
                }
            }
        }