Class: OdroidLCD::LCD
- Inherits:
-
Object
- Object
- OdroidLCD::LCD
- Defined in:
- lib/odroid_lcd/lcd.rb
Instance Attribute Summary collapse
-
#max_column ⇒ Object
readonly
The main interface to the LCD screen.
-
#max_row ⇒ Object
readonly
Returns the value of attribute max_row.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the display.
-
#initialize(mocks: {}) ⇒ LCD
constructor
A new instance of LCD.
-
#set_character(row:, column:, character:) ⇒ Object
set_character.
-
#set_lines(lines:, align: "left") ⇒ Object
::lines::
[“line one”, “line two”] [“line one”, “line two”, “line three”]. -
#set_string(row: 0, string:, align: "left") ⇒ Object
set_string.
Constructor Details
#initialize(mocks: {}) ⇒ LCD
Returns a new instance of LCD.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/odroid_lcd/lcd.rb', line 12 def initialize(mocks: {}) @hw = if mocks[:odroidlcd_hw] mocks[:odroidlcd_hw] else require 'odroid_lcd/hw' OdroidLCD::HW.new end @max_column = @hw.max_column @max_row = @hw.max_row freeze() end |
Instance Attribute Details
#max_column ⇒ Object (readonly)
The main interface to the LCD screen.
9 10 11 |
# File 'lib/odroid_lcd/lcd.rb', line 9 def max_column @max_column end |
#max_row ⇒ Object (readonly)
Returns the value of attribute max_row.
10 11 12 |
# File 'lib/odroid_lcd/lcd.rb', line 10 def max_row @max_row end |
Instance Method Details
#clear ⇒ Object
Clear the display
26 27 28 |
# File 'lib/odroid_lcd/lcd.rb', line 26 def clear @hw.clear end |
#set_character(row:, column:, character:) ⇒ Object
set_character
Sets a single character at a particular position on the display.
Note that the display uses a Japanese display driver, so the following quirks / features are present:
“" is displayed as the yen character ”~“ is displayed as a right arrow delete (or rubout) is displayed as a left arrow
Row 0 is the top row, row 1 is the bottom row.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/odroid_lcd/lcd.rb', line 43 def set_character(row:, column:, character:) begin # It's a Japanese display, seemingly using Windows-31J # # Note that \ displays as a yen sign, ~ displays as a right arrow, DEL displays as a left arrow chr = character.encode("Windows-31J") @hw.set_character(row, column, chr) rescue Encoding::UndefinedConversionError => e raise OdroidLCD::LCDError, "Could not display character: #{character}, the display uses Japanese Windows-31J" end end |
#set_lines(lines:, align: "left") ⇒ Object
::lines::
["line one", "line two"]
["line one", "line two", "line three"]
::align::
Optional, either "left", "right", or "center"
Defaults to: "left"
93 94 95 96 97 98 99 100 |
# File 'lib/odroid_lcd/lcd.rb', line 93 def set_lines(lines:, align: "left") if lines.length >= @max_row set_string(row: 0, string: lines[0].to_s, align: align) set_string(row: 1, string: lines[1].to_s, align: align) else set_string(row: 0, string: lines[0].to_s, align: align) end end |
#set_string(row: 0, string:, align: "left") ⇒ Object
set_string
Sets a string on the display.
::row::
Which row of the display to update.
Row 0 is the top row, row 1 is the bottom row.
::string::
The string to send to the display.
::align::
Optional, either "left", "right", or "center"
Defaults to: "left"
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/odroid_lcd/lcd.rb', line 70 def set_string(row: 0, string:, align: "left") column = 0 str = case align when "left" then string[0, @max_column].ljust(@max_column) when "right" then string[0, @max_column].rjust(@max_column) when "center" then string[0, @max_column].center(@max_column) else string[0, @max_column].ljust(@max_column) end str.chars do |chr| set_character(row: row, column: column, character: chr) column += 1 end end |