public void DMDSurface_should_SPI_same_bits(int panelsWidth, int panelsHeight) { PigsGenerator gpioRef = new PigsGenerator(Environment.NewLine); DMDPinLayout layout = new DMDPinLayout(1, 2, 3, 4, 5, 6); DMD dmdRef = new DMD(gpioRef, layout, panelsWidth, panelsHeight); dmdRef.Init(); this.DrawPattern(dmdRef); dmdRef.ScanFull(); PigsGenerator gpioTest = new PigsGenerator(); FreetronicsDMDSurface dmdTest = new FreetronicsDMDSurface(gpioTest, layout, panelsWidth, panelsHeight); dmdTest.Init(false); this.DrawPattern(dmdTest); ((IDMDInternals)dmdTest).ScanFull(); Assert.Equal(gpioRef.ToString(), gpioTest.ToString()); }
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); } }