public FreetronicsDMDSurface(IPiGPIO gpio, DMDPinLayout layout, int panelsWide, int panelsTall) : base(gpio, layout) { if (panelsWide <= 0) { throw new ArgumentOutOfRangeException(nameof(panelsWide)); } this.m_panWide = panelsWide; if (panelsTall <= 0) { throw new ArgumentOutOfRangeException(nameof(panelsTall)); } this.m_panTall = panelsTall; this.m_panTotal = this.m_panWide * this.m_panTall; this.m_rowsize = this.m_panTotal << 2; this.m_img = new Image <BitPixel>(this.m_panWide * DMD_PIXELS_ACROSS, this.m_panTall * DMD_PIXELS_DOWN); this.m_semaphore = new SemaphoreSlim(1); this.m_th = new Thread(this.RefreshDisplay); this.m_th.Name = this.GetType().Name; this.m_row1 = this.m_panTotal << 4; this.m_row2 = this.m_panTotal << 5; this.m_row3 = ((this.m_panTotal << 2) * 3) << 2; this.m_pixelTotal = this.m_img.Width * this.m_img.Height; }
internal ClientFileStream(IPiGPIO client, int handle, bool canRead, bool canSeek, bool canWrite) { this.m_pigs = client; this.m_handle = handle; this.CanRead = canRead; this.CanSeek = canSeek; this.CanWrite = canWrite; }
/// <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); }
public static Stream OpenFileStream(this IPiGPIO client, string file, FileOpenMode mode) { int handle = client.FileOpen(file, mode); if (handle < 0) { throw new PiGPIOException(handle); } return(new ClientFileStream(client, handle, mode.HasFlag(FileOpenMode.Read), true, mode.HasFlag(FileOpenMode.Write))); }
public static int FileOpen(this IPiGPIO client, string file, FileOpenMode mode) { int iMode = (int)mode; if ((iMode & (int)FileOpenMode.ReadWrite) == 0) { throw new InvalidOperationException("Must specify read and/or write"); } return(client.FileOpen(file, iMode)); }
public SI4703(IPiGPIO pigpio, int gpioReset, int gpioSDIO, bool inEurope) { if (pigpio == null) { throw new ArgumentNullException(nameof(pigpio)); } this.registers = new ushort[16]; this.m_pigpio = pigpio; this.m_reset = gpioReset; this.m_sdio = gpioSDIO; this.m_inEurope = inEurope; }
public static void BitBangSend(this IPiGPIO gpio, int gpioData, int gpioClock, byte[] data) { for (int i = 0; i < data.Length; i++) { for (int o = 7; o >= 0; o--) { gpio.Write(gpioData, (data[i] & o) != 0); gpio.Write(gpioClock, true); gpio.Write(gpioClock, false); } } }
private static int Run(IPiGPIO gpio) { Console.WriteLine("Starting application..."); using (gpio) { var tlc = new TLC5947(gpio, 1, gpioClock, gpioData, gpioLatch, gpioOE); { Console.WriteLine("Starting TLC5947 driver..."); tlc.Init(); bool run = true; Console.CancelKeyPress += (s, e) => { if (run) { e.Cancel = true; run = false; Console.WriteLine("Soft exiting..."); } else { Console.WriteLine("Hard exiting..."); } }; System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); while (run) { double h = Math.Sin(sw.Elapsed.TotalSeconds) / 2 + .5; Conversions.hsv2rgb(h, 1, 1, out byte r, out byte g, out byte b); tlc.SetLED(0, Color.FromArgb(r, g, b)); tlc.Write(); Thread.Sleep(1); if (Console.KeyAvailable) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Spacebar && key.Modifiers == (ConsoleModifiers)0) { tlc.SetOutputEnabled(!tlc.OutputEnabled); Console.Write(tlc.OutputEnabled ? "/" : "\\"); } } Console.Write("."); } } } Console.WriteLine("Exiting application..."); return(0); }
public TLC5947(IPiGPIO pigpio, int numdrivers, int gpioClock, int gpioData, int gpioLatch, int gpioOutputEnabled = int.MinValue) : base(pigpio) { if (numdrivers <= 0) { throw new ArgumentOutOfRangeException(nameof(numdrivers)); } this.m_pwmbuffer = new ushort[24 * numdrivers]; this.m_numdrivers = numdrivers; this.m_gpioClock = gpioClock; this.m_gpioData = gpioData; this.m_gpioLatch = gpioLatch; this.m_gpioOutputEnabled = gpioOutputEnabled; }
public TLC5947(IPiGPIO pigpio, int numdrivers, int clock, int data, int latch, int oe = int.MinValue) { if (pigpio == null) { throw new ArgumentNullException(nameof(pigpio)); } if (numdrivers <= 0) { throw new ArgumentOutOfRangeException(nameof(numdrivers)); } this.pwmbuffer = new int[2 * 24 * numdrivers]; this.m_pigpio = pigpio; this.numdrivers = numdrivers; this.clock = clock; this.data = data; this.latch = latch; this.oe = oe; }
public DMD(IPiGPIO gpio, DMDPinLayout layout, int panelsWide, int panelsHigh) : base(gpio, layout) { if (panelsWide < 1) { throw new ArgumentOutOfRangeException(nameof(panelsWide)); } if (panelsHigh < 1) { throw new ArgumentOutOfRangeException(nameof(panelsHigh)); } this.m_displaysWide = panelsWide; this.m_displaysHigh = panelsHigh; this.m_displaysTotal = this.m_displaysWide * this.m_displaysHigh; this.row1 = this.m_displaysTotal << 4; this.row2 = this.m_displaysTotal << 5; this.row3 = ((this.m_displaysTotal << 2) * 3) << 2; this.bDMDScreenRAM = new byte[this.m_displaysTotal * DMD_RAM_SIZE_BYTES]; }
internal SpiHelper(IPiGPIO pigs, int handle) : base(pigs, handle) { }
public FreetronicsDMDSurface(IPiGPIO gpio, DMDPinLayout layout) : this(gpio, layout, 1, 1) { }
public CoremanHub75LedMatrix(IPiGPIO gpio, Hub75PinLayout pinLayout) : base(gpio) { this.m_pins = pinLayout ?? throw new ArgumentNullException(nameof(pinLayout)); }
public DMDBase(IPiGPIO gpio, DMDPinLayout layout) : base(gpio) { this.m_layout = layout ?? throw new ArgumentNullException(nameof(layout)); }
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); } }
public static ISpiHelper OpenSpi(this IPiGPIO client, int channel, int bauds, int flags) { int handle = client.SpiOpen(channel, bauds, flags); return(new SpiHelper(client, handle)); }
public static int FileSeek(this IPiGPIO client, int handle, int offset, SeekOrigin from) { return(client.FileSeek(handle, offset, (int)from)); }
internal Waveform(IPiGPIO pigpio, int id) { this.m_pigpio = pigpio; this.m_id = id; }
internal I2CHelper(IPiGPIO pigs) { this.m_pigs = pigs; }
private static int Run(IPiGPIO gpio) { Console.WriteLine("Starting application..."); using (gpio) { g = gpio; Console.WriteLine("Starting driver..."); drv = new CoremanHub75LedMatrix(gpio, Hub75PinLayout.Regular); //Set all to 0 drv.Init(); Console.WriteLine("Looping..."); Console.CancelKeyPress += (s, e) => { if (run) { e.Cancel = true; run = false; Console.WriteLine("Soft exiting..."); } else { Console.WriteLine("Hard exiting..."); } }; KeyHelp(false); bool a = false; bool b = false; bool o = false; bool c = false; bool l = false; g.Write(drv.Layout.A, a); g.Write(drv.Layout.B, b); g.Write(drv.Layout.OE, o); g.Write(drv.Layout.Strobe, l); g.Write(drv.Layout.Clock, c); int pos = 0; while (run) { if (!Console.KeyAvailable) { Thread.Sleep(10); continue; } var key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.F1: KeyHelp(); break; case ConsoleKey.D: TransmitRowPixel(pos, false, false, true); Console.Write("d"); break; case ConsoleKey.A: a = !a; gpio.Write(drv.Layout.A, a); Console.Write(a ? "A" : "a"); break; case ConsoleKey.B: b = !b; gpio.Write(drv.Layout.B, b); Console.Write(b ? "B" : "b"); break; case ConsoleKey.C: c = !c; gpio.Write(drv.Layout.C, c); Console.Write(c ? "C" : "c"); break; case ConsoleKey.O: o = !o; gpio.Write(drv.Layout.OE, o); Console.Write(o ? "O" : "o"); break; case ConsoleKey.L: l = !l; gpio.Write(drv.Layout.Strobe, l); Console.Write(l ? "L" : "l"); break; case ConsoleKey.Add: pos = Math.Min(63, pos + 1); Console.Write("+{0:X2}", pos); break; case ConsoleKey.Subtract: pos = Math.Max(0, pos - 1); Console.Write("-{0:X2}", pos); break; case ConsoleKey.I: Interleaved(); Console.Write("i"); break; case ConsoleKey.U: Interleaved2(); Console.Write("u"); break; case ConsoleKey.X: ChessBoardScan(); break; } } } return(0); }
public static void SpiWrite(this IPiGPIO client, int handle, byte[] buffer, int offset, int count) { byte[] data = new byte[count]; Array.Copy(buffer, offset, data, 0, count); client.SpiWrite(handle, data); }
public static ISpiHelper OpenBitBangSpi(this IPiGPIO client, int gpioCS, int gpioMiso, int gpioMosi, int gpioClk, int bauds, int flags) { client.BSpiOpen(gpioCS, gpioMiso, gpioMosi, gpioClk, bauds, flags); return(new BitBangSpiHelper(client, gpioCS)); }
public static WaveformBuilder BuildWaveform(this IPiGPIO client) { return(new WaveformBuilder(client)); }
internal WaveformBuilder(IPiGPIO gpio) { this.m_gpio = gpio; this.m_lst = new List <Pulse>(); }
internal BaseHelper(IPiGPIO pigs, int handle) { this.m_pigs = pigs; this.m_handle = handle; }
public BaseDriver(IPiGPIO gpio) { this.m_gpio = gpio ?? throw new ArgumentNullException(nameof(gpio)); this.m_usedGpio = new List <int>(); }