Table of Contents

Class LcdConsole

Namespace
Iot.Device.CharacterLcd
Assembly
Iot.Device.CharacterLcd.dll

This is a high-level interface to an LCD display. It supports automatic wrapping of text, automatic scrolling and code page mappings. This class is thread safe, however using Write from different threads may lead to unexpected results, since the order is not guaranteed.

public sealed class LcdConsole
Inheritance
LcdConsole

Constructors

LcdConsole(ICharacterLcd, string, bool)

Creates a new instance of the LcdConsole class using the specified LCD low-level interface. This class automatically configures the low-level interface. Do not use the low-level interface at the same time.

public LcdConsole(ICharacterLcd lcd, string romType, bool shouldDispose = true)

Parameters

lcd ICharacterLcd

The low-level LCD interface.

romType string

Name of character ROM of display. Currently supported types: A00 and A02.

shouldDispose bool

If the class should dispose the LCD driver when it is disposed. Defaults to true

Properties

BacklightOn

Enables or disables the backlight

public bool BacklightOn { get; set; }

Property Value

bool

CursorLeft

Position of the cursor, from left. Note: May be outside the bounds of the display.

public int CursorLeft { get; }

Property Value

int

CursorTop

Position of the cursor, from top Note: May be outside the bounds of the display.

public int CursorTop { get; }

Property Value

int

DisplayOn

Enables or disables the display

public bool DisplayOn { get; set; }

Property Value

bool

LineFeedMode

Sets the Line Feed Mode. This defines what happens when writting past the end of the line/screen.

public LineWrapMode LineFeedMode { get; set; }

Property Value

LineWrapMode

ScrollUpDelay

If this is larger than zero, an a wait is introduced each time the display wraps to the next line or scrolls up. Can be used to print long texts to the display, but keeping it readable.

public TimeSpan ScrollUpDelay { get; set; }

Property Value

TimeSpan

Size

Size of the display

public Size Size { get; }

Property Value

Size

Methods

BlinkDisplay(int)

Blinks the display text (and the backlight, if available). Can be used to get user attention. Operation is synchronous.

public void BlinkDisplay(int times)

Parameters

times int

Number of times to blink. The blink rate is 1 Hz

Clear()

Clears the screen and sets the cursor back to the start.

public void Clear()

CreateEncoding(string, string, char, int, LcdCharacterEncodingFactory?)

Creates an encoding that can be used for an LCD display. Typically, the returned value will be loaded using LoadEncoding(LcdCharacterEncoding).

public static LcdCharacterEncoding CreateEncoding(string culture, string romType, char unknownCharacter = '?', int maxNumberOfCustomCharacters = 8, LcdCharacterEncodingFactory? factory = null)

Parameters

culture string

Required display culture (forwarded to the factory)

romType string

The name of the ROM for which the encoding is to be applied. The default factory supports roms A00 and A02.

unknownCharacter char

The character to print for unknown letters, default: ?

maxNumberOfCustomCharacters int

The maximum number of custom characters supported by the hardware.

factory LcdCharacterEncodingFactory

Character encoding factory that delivers the mapping of the Char type to the hardware ROM character codes. May add special characters into the character ROM. Default: Null (Use internal factory)

Returns

LcdCharacterEncoding

Dispose()

Disposes this instance.

public void Dispose()

LoadEncoding(LcdCharacterEncoding)

Loads the specified character encoding. This loads any custom characters from the encoding to the display.

public bool LoadEncoding(LcdCharacterEncoding encoding)

Parameters

encoding LcdCharacterEncoding

The encoding to load.

Returns

bool

True if the character encoding was successfully loaded, false if there are not enough custom slots for all the required custom characters. This may also return false if the encoding factory returned incomplete results, such as a missing custom character for a special diacritic.

LoadEncoding(Encoding)

Loads the specified encoding. This behaves as LoadEncoding(LcdCharacterEncoding) when the argument is of the dynamic type LcdCharacterEncoding, otherwise like an encding with no special characters.

public bool LoadEncoding(Encoding encoding)

Parameters

encoding Encoding

The encoding to load.

Returns

bool

See true if the encoding was correctly loaded.

ReplaceLine(int, string)

Replaces the text of the given line. This will overwrite the text in the given line, filling up with spaces, if needed. This will never wrap to the next line, and line feeds in the input string are not allowed.

public void ReplaceLine(int lineNumber, string text)

Parameters

lineNumber int

0-based index of the line to start

text string

Text to insert. No newlines supported.

Exceptions

ArgumentException

The string contains newlines.

ResetEncoding()

Resets the character encoding to hardware defaults (using simply the lower byte of a char).

public void ResetEncoding()

SetCursorPosition(int, int)

Moves the cursor to an explicit column and row position. The position may be outside the bounds of the display. Any subsequent writes will then have no effect, unless LineFeedMode allows it or a newline character is written.

public void SetCursorPosition(int left, int top)

Parameters

left int

The column position from left to right starting with 0.

top int

The row position from the top starting with 0.

Exceptions

ArgumentOutOfRangeException

The new position negative.

Write(string)

Write text to display.

public void Write(string text)

Parameters

text string

Text to be displayed.

Remarks

There are only 256 characters available. There are chip variants with different character sets. Characters from space ' ' (32) to '}' are usually the same with the exception of '', which is a yen symbol on some chips '¥'.

Exceptions

ArgumentNullException

text was null.

WriteLine(string)

Writes the given text to the current position, then wraps to the next line.

public void WriteLine(string text = "")

Parameters

text string

Text to draw.

Exceptions

ArgumentNullException

text was null.