Class: Tinkerforge::BrickletOLED128x64

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_oled_128x64.rb

Overview

3.3cm (1.3“) OLED display with 128x64 pixels

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

263
DEVICE_DISPLAY_NAME =

:nodoc:

'OLED 128x64 Bricklet'
FUNCTION_WRITE =

:nodoc:

1
FUNCTION_NEW_WINDOW =

:nodoc:

2
FUNCTION_CLEAR_DISPLAY =

:nodoc:

3
FUNCTION_SET_DISPLAY_CONFIGURATION =

:nodoc:

4
FUNCTION_GET_DISPLAY_CONFIGURATION =

:nodoc:

5
FUNCTION_WRITE_LINE =

:nodoc:

6
FUNCTION_GET_IDENTITY =

:nodoc:

255

Constants inherited from Device

Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid

Instance Method Summary collapse

Methods inherited from Device

#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletOLED128x64

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 31

def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_WRITE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_NEW_WINDOW] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE


  @ipcon.add_device self
end

Instance Method Details

#clear_displayObject

Clears the current content of the window as set by BrickletOLED128x64#new_window.



83
84
85
86
87
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 83

def clear_display
  check_validity

  send_request FUNCTION_CLEAR_DISPLAY, [], '', 8, ''
end

#get_display_configurationObject

Returns the configuration as set by BrickletOLED128x64#set_display_configuration.



100
101
102
103
104
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 100

def get_display_configuration
  check_validity

  send_request FUNCTION_GET_DISPLAY_CONFIGURATION, [], '', 10, 'C ?'
end

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



135
136
137
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 135

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#new_window(column_from, column_to, row_from, row_to) ⇒ Object

Sets the window in which you can write with BrickletOLED128x64#write. One row has a height of 8 pixels.



76
77
78
79
80
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 76

def new_window(column_from, column_to, row_from, row_to)
  check_validity

  send_request FUNCTION_NEW_WINDOW, [column_from, column_to, row_from, row_to], 'C C C C', 8, ''
end

#set_display_configuration(contrast, invert) ⇒ Object

Sets the configuration of the display.

You can set a contrast value from 0 to 255 and you can invert the color (black/white) of the display.



93
94
95
96
97
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 93

def set_display_configuration(contrast, invert)
  check_validity

  send_request FUNCTION_SET_DISPLAY_CONFIGURATION, [contrast, invert], 'C ?', 8, ''
end

#write(data) ⇒ Object

Appends 64 byte of data to the window as set by BrickletOLED128x64#new_window.

Each row has a height of 8 pixels which corresponds to one byte of data.

Example: if you call BrickletOLED128x64#new_window with column from 0 to 127 and row from 0 to 7 (the whole display) each call of BrickletOLED128x64#write (red arrow) will write half of a row.

.. image

/Images/Bricklets/bricklet_oled_128x64_display.png

:scale: 100 %
:alt: Display pixel order
:align: center
:target: ../../_images/Bricklets/bricklet_oled_128x64_display.png

The LSB (D0) of each data byte is at the top and the MSB (D7) is at the bottom of the row.

The next call of BrickletOLED128x64#write will write the second half of the row and the next two the second row and so on. To fill the whole display you need to call BrickletOLED128x64#write 16 times.



68
69
70
71
72
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 68

def write(data)
  check_validity

  send_request FUNCTION_WRITE, [data], 'C64', 8, ''
end

#write_line(line, position, text) ⇒ Object

Writes text to a specific line with a specific position. The text can have a maximum of 26 characters.

For example: (1, 10, “Hello”) will write Hello in the middle of the second line of the display.

You can draw to the display with BrickletOLED128x64#write and then add text to it afterwards.

The display uses a special 5x7 pixel charset. You can view the characters of the charset in Brick Viewer.

The font conforms to code page 437.



119
120
121
122
123
# File 'lib/tinkerforge/bricklet_oled_128x64.rb', line 119

def write_line(line, position, text)
  check_validity

  send_request FUNCTION_WRITE_LINE, [line, position, text], 'C C Z26', 8, ''
end