Class: Tinkerforge::BrickletOLED128x64V2
- Inherits:
-
Object
- Object
- Tinkerforge::BrickletOLED128x64V2
- Includes:
- Shared::IBM437_encoding
- Defined in:
- lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb
Instance Method Summary collapse
-
#blackout ⇒ Object
Turns the display all black.
-
#buffered? ⇒ Boolean
Returns true if automatic draw is set to false.
-
#encode(string) ⇒ Object
Encodes a string in the IBM437 character set used by some displays.
-
#put_screen(text = '', test: false) ⇒ Object
Clears the display and prints upto 8 lines of text.
-
#redraw(force_complete_redraw = false) ⇒ Object
(also: #flush)
Draws the currently buffered frame.
-
#show(object) ⇒ Object
Shows an object.
-
#state ⇒ Object
Returns the device’s state.
Instance Method Details
#blackout ⇒ Object
Turns the display all black.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 20 def blackout c = get_display_configuration if c[1] # inverted set_display_configuration c[0], false, c[2] end clear_display if ! c[2] # buffered draw_buffered_frame(true) end true end |
#buffered? ⇒ Boolean
Returns true if automatic draw is set to false.
37 38 39 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 37 def buffered? ! get_display_configuration[2] end |
#encode(string) ⇒ Object
Encodes a string in the IBM437 character set used by some displays.
Characters that can not be encoded are replaced with ‘?’.
See:
15 16 17 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 15 def encode(string) ibm437_encode(string) end |
#put_screen(text = '', test: false) ⇒ Object
Clears the display and prints upto 8 lines of text.
Text may contain newline characters to separate lines. Lines longer than 21 characters will be wrapped.
Text is automatically encoded in the IBM437 character set.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 63 def put_screen(text='', test: false) lines = text.split("\n") lines = lines.map { |s| s.empty? ? '' : s.scan(/.{1,21}/) }.flatten lines = lines[0,8].map { |l| encode l } return lines if test clear_display lines.each_with_index do |s,l| write_line l, 0, s end nil end |
#redraw(force_complete_redraw = false) ⇒ Object Also known as: flush
Draws the currently buffered frame.
42 43 44 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 42 def redraw(force_complete_redraw=false) draw_buffered_frame force_complete_redraw end |
#show(object) ⇒ Object
Shows an object.
78 79 80 81 82 83 84 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 78 def show(object) if object.respond_to?( :_view_21x8, true) put_screen ( object.send(:_view_21x8) rescue "21x8 view error\n\n#{object.class.to_s}" ) elsif put_screen object.inspect[0,168] end end |
#state ⇒ Object
Returns the device’s state.
49 50 51 52 53 |
# File 'lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb', line 49 def state super.merge( 'display_configuration' => get_display_configuration, ) end |