/// <summary>
        /// Get the board name
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public static string HardwareName(this IPiGPIO client)
        {
            int hwver = client.HardwareRevision();

            // http://elinux.org/RPi_HardwareHistory

            if ((hwver >= 2 && hwver <= 6) || (hwver >= 0x000D && hwver <= 0x000F))
            {
                return("Raspberry pi 1B");
            }
            if (hwver >= 7 && hwver <= 9)
            {
                return("Raspberry pi 1A");
            }
            if (hwver == 0x0010 || hwver == 0x0013)
            {
                return("Raspberry pi 1B+");
            }
            if (hwver == 0x0011 || hwver == 0x0014)
            {
                return("Compute module 1");
            }
            if (hwver == 0x0012 || hwver == 0x0015)
            {
                return("Raspberry pi 1A+");
            }

            if (hwver == 0xa01040 || hwver == 0xa01041 || hwver == 0xa21041 || hwver == 0xa22042)
            {
                return("Raspberry pi 2B");
            }
            if (hwver == 0x900021)
            {
                return("Raspberry pi 1A+");
            }
            if (hwver == 0x900032)
            {
                return("Raspberry pi 1B+");
            }
            if (hwver == 0x900092 || hwver == 0x900093)
            {
                return("Raspberry pi Zero");
            }
            if (hwver == 0x9000c1)
            {
                return("Raspberry pi Zero W");
            }
            if (hwver == 0xa02082 || hwver == 0xa22082 || hwver == 0xa32082)
            {
                return("Raspberry pi 3B");
            }
            if (hwver == 0xa020a0)
            {
                return("Compute module 3");
            }
            return(null);
        }
Beispiel #2
0
        private static int Run(IPiGPIO gpio)
        {
            FontFamily fontFamily;

            if (!SystemFonts.TryFind("Arial", out fontFamily))
            {
                Console.WriteLine("Arial not found, taking first");
                fontFamily = SystemFonts.Families.FirstOrDefault();
            }
            Font font = new Font(fontFamily, 14);

            Console.WriteLine($"Board : {gpio.HardwareName()} (rev {gpio.HardwareRevision()})");
            Console.WriteLine($"PiGPIO version {gpio.PigpioVersion()}");

            DMDPinLayout layout = new DMDPinLayout(gpioData, gpioA, gpioB, gpioClock, gpioStrobe, gpioOE);
            string       str    = "";

            try
            {
                using (FreetronicsDMDSurface dmd2 = new FreetronicsDMDSurface(gpio, layout))
                {
                    dmd2.Init();

                    bool run = true;
                    Console.CancelKeyPress += (s, e) =>
                    {
                        if (run)
                        {
                            e.Cancel = true;
                            run      = false;
                            Console.WriteLine("Soft exiting...");
                        }
                        else
                        {
                            Console.WriteLine("Hard exiting...");
                        }
                    };
                    int    offset = 0;
                    Action Save   = () =>
                    {
                        Console.Write("Filename=>");
                        string filename;
                        do
                        {
                            filename = $"img{offset.ToString("00000")}.png";
                            offset++;
                        }while (File.Exists(filename));
                        Console.WriteLine($"Saving {filename}");
                        dmd2.SavePNG(filename);
                    };

                    while (run)
                    {
                        if (Console.KeyAvailable)
                        {
                            var key = Console.ReadKey();
                            if (key.Key == ConsoleKey.S)
                            {
                                Save();
                            }
                        }
                        Thread.Sleep(10);
                        string str2 = DateTime.Now.ToLongTimeString();
                        if (str != str2)
                        {
                            str = str2;
                            dmd2.UpdateSurface(img =>
                            {
                                img.Fill(BitPixel.Off);
                                img.DrawText(str, font, BitPixel.On, new PointF(0, 0));
                            });
                            Console.WriteLine(str);
                        }
                    }

                    dmd2.UpdateSurface(u =>
                    {
                        u.Fill(BitPixel.Off);
                    });

                    Thread.Sleep(100);
                }
                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.GetType().FullName + ": " + ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(-1);
            }
        }