Esempio n. 1
0
        private static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: led-matrix-weather <openweathermap.org API key>");
                Console.WriteLine();
                Console.WriteLine("If wrong key is used or there is no network connection");
                Console.WriteLine("example data will be displayed.");
                Console.WriteLine();
                Console.WriteLine("For the first 30 seconds of execution");
                Console.WriteLine("IP addresses will be displayed instead of data.");
                return;
            }

            s_client = new Weather(args[0]);

            UpdateWeather();
            Task.Run(WeatherUpdater);
            Task.Run(IpsGetter);

            PinMapping   mapping = PinMapping.MatrixBonnetMapping32;
            RGBLedMatrix matrix  = new RGBLedMatrix(mapping, 64, 64, 2, 2);

            Task drawing = Task.Run(() =>
            {
                matrix.StartRendering();

                while (s_scenario is object)
                {
                    Action <RGBLedMatrix> scenario = s_scenario;

                    Stopwatch sw = Stopwatch.StartNew();
                    scenario(matrix);

                    if (sw.ElapsedMilliseconds < 100)
                    {
                        Debug.WriteLine("Scenario execution finished in less than 100ms. This is likely due to bug.");
                    }
                }
            });

            try
            {
                if (!Console.IsOutputRedirected)
                {
                    while (s_scenario is object && Console.ReadKey(intercept: true).Key != ConsoleKey.Q)
                    {
                        Thread.Sleep(10);
                    }

                    s_scenario = null;
                }

                drawing.Wait();
            }
            finally
            {
                matrix.Dispose();
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            Console.WriteLine($"Hello Matrix World!");

            // If using 64x64 with Bonnet (https://www.adafruit.com/product/3211), you can just do
            // PinMapping mapping = PinMapping.MatrixBonnetMapping64;

            // If using 32x32 with Bonnet (https://www.adafruit.com/product/3211), you can just do
            PinMapping mapping = PinMapping.MatrixBonnetMapping32;

            // If not using Bonnet, will need to provide the manual GPIO mapping using PinMapping

            // To create RGBLedMatrix for 32x32 panel, do the following
            RGBLedMatrix matrix = new RGBLedMatrix(mapping, 32, 32);

            // To create RGBLedMatrix for 64x64 panel, do the following
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64);

            // PinMapping mapping = PinMapping.MatrixBonnetMapping64;
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64);

            // If you chain 4 32x32 panels serially, you can do
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 128, 32);

            // If you chain 4 32x32 panels having 2 rows chaining (2 panels in first row an d2 panels in second row).
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64, 2, 2);

            Task.Run(() =>
            {
                matrix.StartRendering();

                while (scenario != 0)
                {
                    switch (scenario)
                    {
                    case 1: Demo1(matrix); break;

                    case 2: Demo2(matrix); break;

                    case 3: Demo3(matrix); break;

                    case 4: Demo4(matrix); break;

                    case 5: Demo5(matrix); break;

                    case 6: Demo6(matrix); break;

                    case 7: Demo7(matrix); break;

                    case 8: Demo8(matrix); break;

                    default:
                        scenario = 2;
                        break;
                    }
                }
            });

            ConsoleKeyInfo cki;

            Console.WriteLine($"Press q to exit.");
            System.Interop.ThreadHelper.SetCurrentThreadHighPriority();

            do
            {
                cki = Console.ReadKey();

                if (cki.KeyChar == '+')
                {
                    matrix.PWMDuration = matrix.PWMDuration + 100;
                    Console.WriteLine($"     ({matrix.PWMDuration})");
                }

                if (cki.KeyChar == '-')
                {
                    matrix.PWMDuration = matrix.PWMDuration - 100;
                    Console.WriteLine($"     ({matrix.PWMDuration})");
                }

                if (cki.KeyChar == 'f')
                {
                    Console.WriteLine($"Frame Time: {matrix.FrameTime} \u00B5s");
                    Console.WriteLine($"Duration : { matrix.PWMDuration }");
                }

                if (cki.KeyChar >= '1' && cki.KeyChar <= '9')
                {
                    play     = false;
                    scenario = cki.KeyChar - '0';
                    Thread.Sleep(1000);
                }
            } while (cki.KeyChar != 'q');

            play     = false;
            scenario = 0;
            Thread.Sleep(1000);
            matrix.Dispose();
        }