Class: Tinkerforge::BrickletOLED64x48

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

Overview

1.68cm (0.66“) OLED display with 64x48 pixels

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

264
DEVICE_DISPLAY_NAME =

:nodoc:

'OLED 64x48 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) ⇒ BrickletOLED64x48

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_64x48.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 BrickletOLED64x48#new_window.



82
83
84
85
86
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 82

def clear_display
  check_validity

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

#get_display_configurationObject

Returns the configuration as set by BrickletOLED64x48#set_display_configuration.



99
100
101
102
103
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 99

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|



134
135
136
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 134

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 BrickletOLED64x48#write. One row has a height of 8 pixels.



75
76
77
78
79
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 75

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.



92
93
94
95
96
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 92

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 BrickletOLED64x48#new_window.

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

Example: if you call BrickletOLED64x48#new_window with column from 0 to 63 and row from 0 to 5 (the whole display) each call of BrickletOLED64x48#write (red arrow) will write one row.

.. image

/Images/Bricklets/bricklet_oled_64x48_display.png

:scale: 100 %
:alt: Display pixel order
:align: center
:target: ../../_images/Bricklets/bricklet_oled_64x48_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 BrickletOLED64x48#write will write the second row and so on. To fill the whole display you need to call BrickletOLED64x48#write 6 times.



67
68
69
70
71
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 67

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 13 characters.

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

You can draw to the display with BrickletOLED64x48#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.



118
119
120
121
122
# File 'lib/tinkerforge/bricklet_oled_64x48.rb', line 118

def write_line(line, position, text)
  check_validity

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