public LcdConnection(IGpioConnectionDriver driver) { log.Debug(m => m("Init LCD connection")); var lcdSettings = new Hd44780LcdConnectionSettings { ScreenWidth = Columns, ScreenHeight = Rows, //Encoding = Encoding.ASCII }; var dataPins = new[] { ConnectorPin.P1Pin31, ConnectorPin.P1Pin33, ConnectorPin.P1Pin35, ConnectorPin.P1Pin37 } .Select(p => (IOutputBinaryPin)driver.Out(p)) .ToArray(); var lcdPins = new Hd44780Pins( driver.Out(ConnectorPin.P1Pin40), driver.Out(ConnectorPin.P1Pin38), dataPins); _lcdConnection = new Hd44780LcdConnection(lcdSettings, lcdPins); // init additonal characters _lcdConnection.SetCustomCharacter(0x0, new byte[] { 0x8, 0xc, 0xe, 0xf, 0xe, 0xc, 0x8 }); // play _lcdConnection.SetCustomCharacter(0x1, new byte[] { 0x0, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0 }); // pause _lcdConnection.SetCustomCharacter(0x2, new byte[] { 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0 }); // stop }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, IEnumerable<ProcessorPin> dataPins) { settings = settings ?? new Hd44780LcdConnectionSettings(); this.registerSelectPin = registerSelectPin; this.clockPin = clockPin; this.dataPins = dataPins.ToArray(); if (this.dataPins.Length != 4 && this.dataPins.Length != 8) throw new ArgumentOutOfRangeException("dataPins", this.dataPins.Length, "There must be either 4 or 8 data pins"); width = settings.ScreenWidth; height = settings.ScreenHeight; if (height < 1 || height > 2) throw new ArgumentOutOfRangeException("ScreenHeight", height, "Screen must have either 1 or 2 rows"); if (width * height > 80) throw new ArgumentException("At most 80 characters are allowed"); if (settings.PatternWidth != 5) throw new ArgumentOutOfRangeException("PatternWidth", settings.PatternWidth, "Pattern must be 5 pixels width"); if (settings.PatternHeight != 8 && settings.PatternHeight != 10) throw new ArgumentOutOfRangeException("PatternHeight", settings.PatternWidth, "Pattern must be either 7 or 10 pixels height"); if (settings.PatternHeight == 10 && height == 2) throw new ArgumentException("10 pixels height pattern cannot be used with 2 rows"); functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10) | (height == 1 ? Functions.OneLine : Functions.TwoLines) | (this.dataPins.Length == 4 ? Functions.Data4bits : Functions.Data8bits); entryModeFlags = /*settings.RightToLeft ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement :*/ EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement; encoding = settings.Encoding; connectionDriver = new MemoryGpioConnectionDriver(); connectionDriver.Allocate(registerSelectPin, PinDirection.Output); connectionDriver.Write(registerSelectPin, false); connectionDriver.Allocate(clockPin, PinDirection.Output); connectionDriver.Write(clockPin, false); foreach (var dataPin in this.dataPins) { connectionDriver.Allocate(dataPin, PinDirection.Output); connectionDriver.Write(dataPin, false); } WriteByte(0x33, false); // Initialize WriteByte(0x32, false); WriteCommand(Command.SetFunctions, (int) functions); WriteCommand(Command.SetDisplayFlags, (int) displayFlags); WriteCommand(Command.SetEntryModeFlags, (int) entryModeFlags); Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection" /> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="pins">The pins.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// dataPins;There must be either 4 or 8 data pins /// or /// settings;ScreenHeight must be between 1 and 4 rows /// or /// settings;PatternWidth must be 5 pixels /// or /// settings;PatternWidth must be either 7 or 10 pixels height /// </exception> /// <exception cref="System.ArgumentException"> /// At most 80 characters are allowed /// or /// 10 pixels height pattern cannot be used with 2 rows /// </exception> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, Hd44780Pins pins) { settings = settings ?? new Hd44780LcdConnectionSettings(); this.pins = pins; if (pins.Data.Length != 4 && pins.Data.Length != 8) throw new ArgumentOutOfRangeException("pins", pins.Data.Length, "There must be either 4 or 8 data pins"); width = settings.ScreenWidth; height = settings.ScreenHeight; if (height < 1 || height > MAX_HEIGHT) throw new ArgumentOutOfRangeException("settings", height, "ScreenHeight must be between 1 and 4 rows"); if (width * height > MAX_CHAR) throw new ArgumentException("At most 80 characters are allowed"); if (settings.PatternWidth != 5) throw new ArgumentOutOfRangeException("settings", settings.PatternWidth, "PatternWidth must be 5 pixels"); if (settings.PatternHeight != 8 && settings.PatternHeight != 10) throw new ArgumentOutOfRangeException("settings", settings.PatternWidth, "PatternWidth must be either 7 or 10 pixels height"); if (settings.PatternHeight == 10 && (height % 2) == 0) throw new ArgumentException("10 pixels height pattern cannot be used with an even number of rows"); functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10) | (height == 1 ? Functions.OneLine : Functions.TwoLines) | (pins.Data.Length == 4 ? Functions.Data4bits : Functions.Data8bits); entryModeFlags = /*settings.RightToLeft ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement :*/ EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement; encoding = settings.Encoding; BacklightEnabled = false; if (pins.ReadWrite != null) pins.ReadWrite.Write(false); pins.RegisterSelect.Write(false); pins.Clock.Write(false); foreach (var dataPin in pins.Data) dataPin.Write(false); WriteByte(0x33, false); // Initialize WriteByte(0x32, false); WriteCommand(Command.SetFunctions, (int) functions); WriteCommand(Command.SetDisplayFlags, (int) displayFlags); WriteCommand(Command.SetEntryModeFlags, (int) entryModeFlags); Clear(); BacklightEnabled = true; }
public RaspSharpView() { const ConnectorPin registerSelectPin = ConnectorPin.P1Pin22; const ConnectorPin clockPin = ConnectorPin.P1Pin18; var dataPins = new[] { ConnectorPin.P1Pin16, ConnectorPin.P1Pin15, ConnectorPin.P1Pin13, ConnectorPin.P1Pin11 }; var driver = GpioConnectionSettings.DefaultDriver; var pins = new Hd44780Pins( driver.Out(registerSelectPin), driver.Out(clockPin), dataPins.Select(p => (IOutputBinaryPin) driver.Out(p))); var settings = new Hd44780LcdConnectionSettings(); _lcd = new Hd44780LcdConnection(settings, pins); }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection" /> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="pins">The pins.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// dataPins;There must be either 4 or 8 data pins /// or /// settings;ScreenHeight must be between 1 and 4 rows /// or /// settings;PatternWidth must be 5 pixels /// or /// settings;PatternWidth must be either 7 or 10 pixels height /// </exception> /// <exception cref="System.ArgumentException"> /// At most 80 characters are allowed /// or /// 10 pixels height pattern cannot be used with 2 rows /// </exception> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, Hd44780Pins pins) { settings = settings ?? new Hd44780LcdConnectionSettings(); this.pins = pins; if (pins.Data.Length != 4 && pins.Data.Length != 8) { throw new ArgumentOutOfRangeException("pins", pins.Data.Length, "There must be either 4 or 8 data pins"); } width = settings.ScreenWidth; height = settings.ScreenHeight; if (height < 1 || height > MAX_HEIGHT) { throw new ArgumentOutOfRangeException("settings", height, "ScreenHeight must be between 1 and 4 rows"); } if (width * height > MAX_CHAR) { throw new ArgumentException("At most 80 characters are allowed"); } if (settings.PatternWidth != 5) { throw new ArgumentOutOfRangeException("settings", settings.PatternWidth, "PatternWidth must be 5 pixels"); } if (settings.PatternHeight != 8 && settings.PatternHeight != 10) { throw new ArgumentOutOfRangeException("settings", settings.PatternWidth, "PatternWidth must be either 7 or 10 pixels height"); } if (settings.PatternHeight == 10 && (height % 2) == 0) { throw new ArgumentException("10 pixels height pattern cannot be used with an even number of rows"); } functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10) | (height == 1 ? Functions.OneLine : Functions.TwoLines) | (pins.Data.Length == 4 ? Functions.Data4bits : Functions.Data8bits); entryModeFlags = /*settings.RightToLeft * ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement * :*/EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement; encoding = settings.Encoding; BacklightEnabled = false; if (pins.ReadWrite != null) { pins.ReadWrite.Write(false); } pins.RegisterSelect.Write(false); pins.Clock.Write(false); foreach (var dataPin in pins.Data) { dataPin.Write(false); } WriteByte(0x33, false); // Initialize WriteByte(0x32, false); WriteCommand(Command.SetFunctions, (int)functions); WriteCommand(Command.SetDisplayFlags, (int)displayFlags); WriteCommand(Command.SetEntryModeFlags, (int)entryModeFlags); Clear(); BacklightEnabled = true; }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, IEnumerable <ProcessorPin> dataPins) { settings = settings ?? new Hd44780LcdConnectionSettings(); this.registerSelectPin = registerSelectPin; this.clockPin = clockPin; this.dataPins = dataPins.ToArray(); if (this.dataPins.Length != 4 && this.dataPins.Length != 8) { throw new ArgumentOutOfRangeException("dataPins", this.dataPins.Length, "There must be either 4 or 8 data pins"); } width = settings.ScreenWidth; height = settings.ScreenHeight; if (height < 1 || height > 2) { throw new ArgumentOutOfRangeException("ScreenHeight", height, "Screen must have either 1 or 2 rows"); } if (width * height > 80) { throw new ArgumentException("At most 80 characters are allowed"); } if (settings.PatternWidth != 5) { throw new ArgumentOutOfRangeException("PatternWidth", settings.PatternWidth, "Pattern must be 5 pixels width"); } if (settings.PatternHeight != 8 && settings.PatternHeight != 10) { throw new ArgumentOutOfRangeException("PatternHeight", settings.PatternWidth, "Pattern must be either 7 or 10 pixels height"); } if (settings.PatternHeight == 10 && height == 2) { throw new ArgumentException("10 pixels height pattern cannot be used with 2 rows"); } functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10) | (height == 1 ? Functions.OneLine : Functions.TwoLines) | (this.dataPins.Length == 4 ? Functions.Data4bits : Functions.Data8bits); entryModeFlags = /*settings.RightToLeft * ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement * :*/EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement; encoding = settings.Encoding; connectionDriver = new MemoryGpioConnectionDriver(); connectionDriver.Allocate(registerSelectPin, PinDirection.Output); connectionDriver.Write(registerSelectPin, false); connectionDriver.Allocate(clockPin, PinDirection.Output); connectionDriver.Write(clockPin, false); foreach (var dataPin in this.dataPins) { connectionDriver.Allocate(dataPin, PinDirection.Output); connectionDriver.Write(dataPin, false); } WriteByte(0x33, false); // Initialize WriteByte(0x32, false); WriteCommand(Command.SetFunctions, (int)functions); WriteCommand(Command.SetDisplayFlags, (int)displayFlags); WriteCommand(Command.SetEntryModeFlags, (int)entryModeFlags); Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, params ProcessorPin[] dataPins) : this(settings, registerSelectPin, clockPin, (IEnumerable <ProcessorPin>)dataPins) { }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, IOutputPin registerSelectPin, IOutputPin clockPin, params IOutputPin[] dataPins) : this(settings, registerSelectPin, clockPin, (IEnumerable <IOutputPin>)dataPins) { }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, IOutputPin registerSelectPin, IOutputPin clockPin, params IOutputPin[] dataPins) : this(settings, registerSelectPin, clockPin, (IEnumerable<IOutputPin>)dataPins) { }
static void Main(string[] args) { Console.WriteLine("HD-44780 Sample: Display IP configuration on LCD screen"); var settings = new Hd44780LcdConnectionSettings { ScreenWidth = 20, ScreenHeight = 2, }; using (var configuration = ConfigurationLoader.FromArguments(args)) using (var connection = new Hd44780LcdConnection(settings, configuration.Pins)) { connection.SetCustomCharacter(1, new byte[] {0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0}); connection.SetCustomCharacter(2, new byte[] {0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0}); if (args.Contains("viewMap", StringComparer.InvariantCultureIgnoreCase)) { connection.Clear(); DisplayCharMap(connection); } connection.Clear(); connection.WriteLine("R# IP Config"); connection.WriteLine(Environment.OSVersion); Thread.Sleep(TimeSpan.FromSeconds(2)); var delay = 0m; while (true) { foreach (var t in NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback) .SelectMany(i => new[] { string.Format("{0}: {1}", i.Name, i.OperationalStatus) + Environment.NewLine + string.Format("\u0002{0} \u0001{1}", FormatByteCount(i.GetIPv4Statistics().BytesReceived), FormatByteCount(i.GetIPv4Statistics().BytesSent)), "IP " + (i.GetIPProperties().UnicastAddresses.Select(a => a.Address.ToString()).FirstOrDefault() ?? "(unassigned)") + Environment.NewLine + "MAC " + i.GetPhysicalAddress().ToString() })) { connection.Clear(); connection.Write(t, delay); for (var i = 0; i < 20; i++) { if (Console.KeyAvailable) { var c = Console.ReadKey(true).Key; switch (c) { case ConsoleKey.F5: connection.Clear(); break; case ConsoleKey.F6: connection.CursorBlinking = !connection.CursorBlinking; break; case ConsoleKey.F7: connection.CursorEnabled = !connection.CursorEnabled; break; case ConsoleKey.F8: connection.DisplayEnabled = !connection.DisplayEnabled; break; case ConsoleKey.F9: connection.Move(-1); break; case ConsoleKey.F10: connection.Move(1); break; case ConsoleKey.F11: delay = 50.0m - delay; break; default: connection.BacklightEnabled = false; return; } } Thread.Sleep(TimeSpan.FromSeconds(2d /20)); } } } } }
static void Main(string[] args) { var settings = new Hd44780LcdConnectionSettings { ScreenWidth = 20, ScreenHeight = 2, }; var registerSelectPin = ConnectorPin.P1Pin22.ToProcessor(); var clockPin = ConnectorPin.P1Pin18.ToProcessor(); var dataPins = (IEnumerable<ProcessorPin>)new[] { ConnectorPin.P1Pin16.ToProcessor(), ConnectorPin.P1Pin15.ToProcessor(), ConnectorPin.P1Pin13.ToProcessor(), ConnectorPin.P1Pin11.ToProcessor() }; using (var connection = new Hd44780LcdConnection( settings, registerSelectPin, clockPin, dataPins)) { connection.SetCustomCharacter(1, new byte[] {0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0}); connection.SetCustomCharacter(2, new byte[] {0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0}); connection.Clear(); connection.WriteLine("R# IP Config"); connection.WriteLine(Environment.OSVersion); Thread.Sleep(2000); // DisplayCharMap(connection); var delay = 0m; while (true) { foreach (var t in NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback) .SelectMany(i => new[] { string.Format("{0}: {1}", i.Name, i.OperationalStatus) + Environment.NewLine + (i.GetIPProperties().UnicastAddresses.Select(a => a.Address.ToString()).FirstOrDefault() ?? "(unassigned)"), i.GetPhysicalAddress().ToString() + Environment.NewLine + string.Format("\u0001{0} \u0002{1}", FormatByteCount(i.GetIPv4Statistics().BytesReceived), FormatByteCount(i.GetIPv4Statistics().BytesSent)) })) { connection.Clear(); connection.Write(t, delay); for (var i = 0; i < 20; i++) { if (Console.KeyAvailable) { var c = Console.ReadKey(true).Key; switch (c) { case ConsoleKey.F5: connection.Clear(); break; case ConsoleKey.F6: connection.CursorBlinking = !connection.CursorBlinking; break; case ConsoleKey.F7: connection.CursorEnabled = !connection.CursorEnabled; break; case ConsoleKey.F8: connection.DisplayEnabled = !connection.DisplayEnabled; break; case ConsoleKey.F9: connection.Move(-1); break; case ConsoleKey.F10: connection.Move(1); break; case ConsoleKey.F11: delay = 50.0m - delay; break; default: return; } } Thread.Sleep(100); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="registerSelectPin">The register select pin.</param> /// <param name="clockPin">The clock pin.</param> /// <param name="dataPins">The data pins.</param> public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, params ProcessorPin[] dataPins) : this(settings, registerSelectPin, clockPin, (IEnumerable<ProcessorPin>)dataPins) { }