class Tinkerforge::BrickletEPaper296x128
Three color 296x128 e-paper display
Constants
- CALLBACK_DRAW_STATUS
Callback for the current draw status. Will be called every time the draw status changes (see
BrickletEPaper296x128#get_draw_status
).
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 92 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 0] @response_expected[FUNCTION_DRAW] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_DRAW_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_WRITE_BLACK_WHITE_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_READ_BLACK_WHITE_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_WRITE_COLOR_LOW_LEVEL] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_READ_COLOR_LOW_LEVEL] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_FILL_DISPLAY] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_DRAW_TEXT] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_DRAW_LINE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_DRAW_BOX] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_SET_UPDATE_MODE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_UPDATE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DISPLAY_TYPE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_DISPLAY_TYPE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_DRAW_STATUS] = [9, 'C'] @ipcon.add_device self end
Public Instance Methods
Draws the current black/white and red or gray buffer to the e-paper display.
The Bricklet does not have any double-buffering. You should not call this function while writing to the buffer. See BrickletEPaper296x128#get_draw_status
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 133 def draw check_validity send_request FUNCTION_DRAW, [], '', 8, '' end
Draws a box from (x, y)-start to (x, y)-end in the given color.
If you set fill to true, the box will be filled with the color. Otherwise only the outline will be drawn.
This function writes the pixels into the black/white/red|gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 261 def draw_box(position_x_start, position_y_start, position_x_end, position_y_end, fill, color) check_validity send_request FUNCTION_DRAW_BOX, [position_x_start, position_y_start, position_x_end, position_y_end, fill, color], 'S C S C ? C', 8, '' end
Draws a line from (x, y)-start to (x, y)-end in the given color.
This function writes the pixels into the black/white/red|gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 248 def draw_line(position_x_start, position_y_start, position_x_end, position_y_end, color) check_validity send_request FUNCTION_DRAW_LINE, [position_x_start, position_y_start, position_x_end, position_y_end, color], 'S C S C C', 8, '' end
Draws a text with up to 50 characters at the pixel position (x, y).
You can use one of 9 different font sizes and draw the text in black/white/red|gray. The text can be drawn horizontal or vertical.
This function writes the pixels into the black/white/red|gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 238 def draw_text(position_x, position_y, font, color, orientation, text) check_validity send_request FUNCTION_DRAW_TEXT, [position_x, position_y, font, color, orientation, text], 'S C C C C Z50', 8, '' end
Fills the complete content of the display with the given color.
This function writes the pixels into the black/white/red|gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 225 def fill_display(color) check_validity send_request FUNCTION_FILL_DISPLAY, [color], 'C', 8, '' end
Returns the current bootloader mode, see BrickletEPaper296x128#set_bootloader_mode
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 365 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end
Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!
The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 423 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end
Returns the type of the e-paper display. It can either be black/white/red or black/white/gray.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 326 def get_display_type check_validity send_request FUNCTION_GET_DISPLAY_TYPE, [], '', 9, 'C' end
Returns one of three draw statuses:
-
Idle
-
Copying: Data is being copied from the buffer of the Bricklet to the buffer of the display.
-
Drawing: The display is updating its content (during this phase the flickering etc happens).
You can write to the buffer (through one of the write or draw functions) when the status is either idle or drawing. You should not write to the buffer while it is being copied to the display. There is no double-buffering.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 148 def get_draw_status check_validity send_request FUNCTION_GET_DRAW_STATUS, [], '', 9, 'C' end
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|
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 470 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
-
ACK checksum errors,
-
message checksum errors,
-
framing errors and
-
overflow errors.
The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 343 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end
Returns the configuration as set by BrickletEPaper296x128#set_status_led_config
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 411 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end
Returns the update mode as set by BrickletEPaper296x128#set_update_mode
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 308 def get_update_mode check_validity send_request FUNCTION_GET_UPDATE_MODE, [], '', 9, 'C' end
Returns the current content of the black/white pixel buffer for the specified window.
The pixels are read into the window line by line top to bottom and each line is read from left to right.
The current content of the buffer does not have to be the current content of the display. It is possible that the data was not drawn to the display yet and after a restart of the Bricklet the buffer will be reset to black, while the display retains its content.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 525 def read_black_white(x_start, y_start, x_end, y_end) pixels_length = nil # assigned in block pixels_data = nil # assigned in block @stream_mutex.synchronize { ret = read_black_white_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] pixels_out_of_sync = pixels_chunk_offset != 0 pixels_data = ret[2] while not pixels_out_of_sync and pixels_data.length < pixels_length ret = read_black_white_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] pixels_out_of_sync = pixels_chunk_offset != pixels_data.length pixels_data += ret[2] end if pixels_out_of_sync # discard remaining stream to bring it back in-sync while pixels_chunk_offset + 464 < pixels_length ret = read_black_white_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Pixels stream is out-of-sync' end } pixels_data[0, pixels_length] end
Returns the current content of the black/white pixel buffer for the specified window.
The pixels are read into the window line by line top to bottom and each line is read from left to right.
The current content of the buffer does not have to be the current content of the display. It is possible that the data was not drawn to the display yet and after a restart of the Bricklet the buffer will be reset to black, while the display retains its content.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 180 def read_black_white_low_level(x_start, y_start, x_end, y_end) check_validity send_request FUNCTION_READ_BLACK_WHITE_LOW_LEVEL, [x_start, y_start, x_end, y_end], 'S C S C', 70, 'S S ?464' end
Returns the current content of the red or gray pixel buffer for the specified window.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The current content of the buffer does not have to be the current content of the display. It is possible that the data was not drawn to the display yet and after a restart of the Bricklet the buffer will be reset to black, while the display retains its content.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 612 def read_color(x_start, y_start, x_end, y_end) pixels_length = nil # assigned in block pixels_data = nil # assigned in block @stream_mutex.synchronize { ret = read_color_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] pixels_out_of_sync = pixels_chunk_offset != 0 pixels_data = ret[2] while not pixels_out_of_sync and pixels_data.length < pixels_length ret = read_color_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] pixels_out_of_sync = pixels_chunk_offset != pixels_data.length pixels_data += ret[2] end if pixels_out_of_sync # discard remaining stream to bring it back in-sync while pixels_chunk_offset + 464 < pixels_length ret = read_color_low_level x_start, y_start, x_end, y_end pixels_length = ret[0] pixels_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Pixels stream is out-of-sync' end } pixels_data[0, pixels_length] end
Returns the current content of the red or gray pixel buffer for the specified window.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The current content of the buffer does not have to be the current content of the display. It is possible that the data was not drawn to the display yet and after a restart of the Bricklet the buffer will be reset to black, while the display retains its content.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 215 def read_color_low_level(x_start, y_start, x_end, y_end) check_validity send_request FUNCTION_READ_COLOR_LOW_LEVEL, [x_start, y_start, x_end, y_end], 'S C S C', 70, 'S S ?464' end
Returns the current UID as an integer. Encode as Base58
to get the usual string version.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 454 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 646 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Calling this function will reset the Bricklet. All configurations will be lost.
After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 435 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end
Sets the bootloader mode and returns the status after the requested mode change was instigated.
You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 358 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end
Sets the type of the display. The e-paper display is available in black/white/red and black/white/gray. This will be factory set during the flashing and testing phase. The value is saved in non-volatile memory and will stay after a power cycle.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 318 def set_display_type(display_type) check_validity send_request FUNCTION_SET_DISPLAY_TYPE, [display_type], 'C', 8, '' end
Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 404 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end
- .. note
-
The default update mode corresponds to the default e-paper display manufacturer settings. All of the other modes are experimental and will result in increased ghosting and possibly other long-term side effects.
If you want to know more about the inner workings of an e-paper display take a look at this excellent video from Ben Krasnow: `www.youtube.com/watch?v=MsbiO8EAsGw <
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 301 def set_update_mode(update_mode) check_validity send_request FUNCTION_SET_UPDATE_MODE, [update_mode], 'C', 8, '' end
Sets the firmware pointer for BrickletEPaper296x128#write_firmware
. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 377 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end
Writes black/white pixels to the specified window into the buffer.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The value 0 (false) corresponds to a black pixel and the value 1 (true) to a white pixel.
This function writes the pixels into the black/white pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
Use BrickletEPaper296x128#write_color
to write red or gray pixels.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 486 def write_black_white(x_start, y_start, x_end, y_end, pixels) if pixels.length > 65535 raise ArgumentError, 'Pixels can be at most 65535 items long' end pixels_length = pixels.length pixels_chunk_offset = 0 if pixels_length == 0 pixels_chunk_data = [false] * 432 ret = write_black_white_low_level x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while pixels_chunk_offset < pixels_length pixels_chunk_data = pixels[pixels_chunk_offset, 432] if pixels_chunk_data.length < 432 pixels_chunk_data += [false] * (432 - pixels_chunk_data.length) end ret = write_black_white_low_level x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data pixels_chunk_offset += 432 end } end ret end
Writes black/white pixels to the specified window into the buffer.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The value 0 (false) corresponds to a black pixel and the value 1 (true) to a white pixel.
This function writes the pixels into the black/white pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
Use BrickletEPaper296x128#write_color
to write red or gray pixels.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 166 def write_black_white_low_level(x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data) check_validity send_request FUNCTION_WRITE_BLACK_WHITE_LOW_LEVEL, [x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data], 'S C S C S S ?432', 8, '' end
The E-Paper 296x128 Bricklet is available with the colors black/white/red and black/white/gray. Depending on the model this function writes either red or gray pixels to the specified window into the buffer.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The value 0 (false) means that this pixel does not have color. It will be either black or white (see BrickletEPaper296x128#write_black_white
). The value 1 (true) corresponds to a red or gray pixel, depending on the Bricklet model.
This function writes the pixels into the red or gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
Use BrickletEPaper296x128#write_black_white
to write black/white pixels.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 573 def write_color(x_start, y_start, x_end, y_end, pixels) if pixels.length > 65535 raise ArgumentError, 'Pixels can be at most 65535 items long' end pixels_length = pixels.length pixels_chunk_offset = 0 if pixels_length == 0 pixels_chunk_data = [false] * 432 ret = write_color_low_level x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while pixels_chunk_offset < pixels_length pixels_chunk_data = pixels[pixels_chunk_offset, 432] if pixels_chunk_data.length < 432 pixels_chunk_data += [false] * (432 - pixels_chunk_data.length) end ret = write_color_low_level x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data pixels_chunk_offset += 432 end } end ret end
The E-Paper 296x128 Bricklet is available with the colors black/white/red and black/white/gray. Depending on the model this function writes either red or gray pixels to the specified window into the buffer.
The pixels are written into the window line by line top to bottom and each line is written from left to right.
The value 0 (false) means that this pixel does not have color. It will be either black or white (see BrickletEPaper296x128#write_black_white
). The value 1 (true) corresponds to a red or gray pixel, depending on the Bricklet model.
This function writes the pixels into the red or gray pixel buffer, to draw the buffer to the display use BrickletEPaper296x128#draw
.
Use BrickletEPaper296x128#write_black_white
to write black/white pixels.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 201 def write_color_low_level(x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data) check_validity send_request FUNCTION_WRITE_COLOR_LOW_LEVEL, [x_start, y_start, x_end, y_end, pixels_length, pixels_chunk_offset, pixels_chunk_data], 'S C S C S S ?432', 8, '' end
Writes 64 Bytes of firmware at the position as written by BrickletEPaper296x128#set_write_firmware_pointer
before. The firmware is written to flash every 4 chunks.
You can only write firmware in bootloader mode.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 391 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end
Writes a new UID into flash. If you want to set a new UID you have to decode the Base58
encoded UID string into an integer first.
We recommend that you use Brick Viewer to change the UID.
# File lib/tinkerforge/bricklet_e_paper_296x128.rb, line 446 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end