Class: Tinkerforge::BrickletDMX
- Defined in:
- lib/tinkerforge/bricklet_dmx.rb
Overview
DMX master and slave
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
285
- DEVICE_DISPLAY_NAME =
:nodoc:
'DMX Bricklet'
- CALLBACK_FRAME_STARTED =
This callback is triggered as soon as a new frame write is started. You should send the data for the next frame directly after this callback was triggered.
For an explanation of the general approach see BrickletDMX#write_frame.
This callback can be enabled via BrickletDMX#set_frame_callback_config.
This callback can only be triggered in master mode.
14
- CALLBACK_FRAME_AVAILABLE =
This callback is triggered in slave mode when a new frame was received from the DMX master and it can be read out. You have to read the frame before the master has written the next frame, see BrickletDMX#read_frame for more details.
The parameter is the frame number, it is increased by one with each received frame.
This callback can be enabled via BrickletDMX#set_frame_callback_config.
This callback can only be triggered in slave mode.
15
- CALLBACK_FRAME_LOW_LEVEL =
See CALLBACK_FRAME
16
- CALLBACK_FRAME_ERROR_COUNT =
This callback is called if a new error occurs. It returns the current overrun and framing error count.
17
- CALLBACK_FRAME =
This callback is called as soon as a new frame is available (written by the DMX master).
The size of the array is equivalent to the number of channels in the frame. Each byte represents one channel.
This callback can be enabled via BrickletDMX#set_frame_callback_config.
This callback can only be triggered in slave mode.
- .. note
-
If reconstructing the value fails, the callback is triggered with nil for frame.
-16
- FUNCTION_SET_DMX_MODE =
:nodoc:
1
- FUNCTION_GET_DMX_MODE =
:nodoc:
2
- FUNCTION_WRITE_FRAME_LOW_LEVEL =
:nodoc:
3
- FUNCTION_READ_FRAME_LOW_LEVEL =
:nodoc:
4
- FUNCTION_SET_FRAME_DURATION =
:nodoc:
5
- FUNCTION_GET_FRAME_DURATION =
:nodoc:
6
- FUNCTION_GET_FRAME_ERROR_COUNT =
:nodoc:
7
- FUNCTION_SET_COMMUNICATION_LED_CONFIG =
:nodoc:
8
- FUNCTION_GET_COMMUNICATION_LED_CONFIG =
:nodoc:
9
- FUNCTION_SET_ERROR_LED_CONFIG =
:nodoc:
10
- FUNCTION_GET_ERROR_LED_CONFIG =
:nodoc:
11
- FUNCTION_SET_FRAME_CALLBACK_CONFIG =
:nodoc:
12
- FUNCTION_GET_FRAME_CALLBACK_CONFIG =
:nodoc:
13
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
234
- FUNCTION_SET_BOOTLOADER_MODE =
:nodoc:
235
- FUNCTION_GET_BOOTLOADER_MODE =
:nodoc:
236
- FUNCTION_SET_WRITE_FIRMWARE_POINTER =
:nodoc:
237
- FUNCTION_WRITE_FIRMWARE =
:nodoc:
238
- FUNCTION_SET_STATUS_LED_CONFIG =
:nodoc:
239
- FUNCTION_GET_STATUS_LED_CONFIG =
:nodoc:
240
- FUNCTION_GET_CHIP_TEMPERATURE =
:nodoc:
242
- FUNCTION_RESET =
:nodoc:
243
- FUNCTION_WRITE_UID =
:nodoc:
248
- FUNCTION_READ_UID =
:nodoc:
249
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- DMX_MODE_MASTER =
:nodoc:
0
- DMX_MODE_SLAVE =
:nodoc:
1
- COMMUNICATION_LED_CONFIG_OFF =
:nodoc:
0
- COMMUNICATION_LED_CONFIG_ON =
:nodoc:
1
- COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION =
:nodoc:
3
- ERROR_LED_CONFIG_OFF =
:nodoc:
0
- ERROR_LED_CONFIG_ON =
:nodoc:
1
- ERROR_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- ERROR_LED_CONFIG_SHOW_ERROR =
:nodoc:
3
- BOOTLOADER_MODE_BOOTLOADER =
:nodoc:
0
- BOOTLOADER_MODE_FIRMWARE =
:nodoc:
1
- BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =
:nodoc:
2
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =
:nodoc:
3
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =
:nodoc:
4
- BOOTLOADER_STATUS_OK =
:nodoc:
0
- BOOTLOADER_STATUS_INVALID_MODE =
:nodoc:
1
- BOOTLOADER_STATUS_NO_CHANGE =
:nodoc:
2
- BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =
:nodoc:
3
- BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =
:nodoc:
4
- BOOTLOADER_STATUS_CRC_MISMATCH =
:nodoc:
5
- STATUS_LED_CONFIG_OFF =
:nodoc:
0
- STATUS_LED_CONFIG_ON =
:nodoc:
1
- STATUS_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- STATUS_LED_CONFIG_SHOW_STATUS =
:nodoc:
3
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
-
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletDMX#set_bootloader_mode.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_communication_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_communication_led_config.
-
#get_dmx_mode ⇒ Object
Returns the DMX mode, as set by BrickletDMX#set_dmx_mode.
-
#get_error_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_error_led_config.
-
#get_frame_callback_config ⇒ Object
Returns the frame callback config as set by BrickletDMX#set_frame_callback_config.
-
#get_frame_duration ⇒ Object
Returns the frame duration as set by BrickletDMX#set_frame_duration.
-
#get_frame_error_count ⇒ Object
Returns the current number of overrun and framing errors.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_spitfp_error_count ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_status_led_config.
-
#initialize(uid, ipcon) ⇒ BrickletDMX
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#read_frame ⇒ Object
Returns the last frame that was written by the DMX master.
-
#read_frame_low_level ⇒ Object
Returns the last frame that was written by the DMX master.
-
#read_uid ⇒ Object
Returns the current UID as an integer.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Bricklet.
-
#set_bootloader_mode(mode) ⇒ Object
Sets the bootloader mode and returns the status after the requested mode change was instigated.
-
#set_communication_led_config(config) ⇒ Object
Sets the communication LED configuration.
-
#set_dmx_mode(dmx_mode) ⇒ Object
Sets the DMX mode to either master or slave.
-
#set_error_led_config(config) ⇒ Object
Sets the error LED configuration.
-
#set_frame_callback_config(frame_started_callback_enabled, frame_available_callback_enabled, frame_callback_enabled, frame_error_count_callback_enabled) ⇒ Object
Enables/Disables the different callbacks.
-
#set_frame_duration(frame_duration) ⇒ Object
Sets the duration of a frame.
-
#set_status_led_config(config) ⇒ Object
Sets the status LED configuration.
-
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletDMX#write_firmware.
-
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletDMX#set_write_firmware_pointer before.
-
#write_frame(frame) ⇒ Object
Writes a DMX frame.
-
#write_frame_low_level(frame_length, frame_chunk_offset, frame_chunk_data) ⇒ Object
Writes a DMX frame.
-
#write_uid(uid) ⇒ Object
Writes a new UID into flash.
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) ⇒ BrickletDMX
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletDMX#set_bootloader_mode.
347 348 349 350 351 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 347 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end |
#get_chip_temperature ⇒ Object
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.
405 406 407 408 409 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 405 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_communication_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_communication_led_config
266 267 268 269 270 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 266 def get_communication_led_config check_validity send_request FUNCTION_GET_COMMUNICATION_LED_CONFIG, [], '', 9, 'C' end |
#get_dmx_mode ⇒ Object
Returns the DMX mode, as set by BrickletDMX#set_dmx_mode.
167 168 169 170 171 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 167 def get_dmx_mode check_validity send_request FUNCTION_GET_DMX_MODE, [], '', 9, 'C' end |
#get_error_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_error_led_config.
288 289 290 291 292 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 288 def get_error_led_config check_validity send_request FUNCTION_GET_ERROR_LED_CONFIG, [], '', 9, 'C' end |
#get_frame_callback_config ⇒ Object
Returns the frame callback config as set by BrickletDMX#set_frame_callback_config.
308 309 310 311 312 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 308 def get_frame_callback_config check_validity send_request FUNCTION_GET_FRAME_CALLBACK_CONFIG, [], '', 12, '? ? ? ?' end |
#get_frame_duration ⇒ Object
Returns the frame duration as set by BrickletDMX#set_frame_duration.
240 241 242 243 244 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 240 def get_frame_duration check_validity send_request FUNCTION_GET_FRAME_DURATION, [], '', 10, 'S' end |
#get_frame_error_count ⇒ Object
Returns the current number of overrun and framing errors.
247 248 249 250 251 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 247 def get_frame_error_count check_validity send_request FUNCTION_GET_FRAME_ERROR_COUNT, [], '', 16, 'L L' end |
#get_identity ⇒ Object
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|
452 453 454 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 452 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_spitfp_error_count ⇒ Object
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.
325 326 327 328 329 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 325 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end |
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletDMX#set_status_led_config
393 394 395 396 397 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 393 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end |
#read_frame ⇒ Object
Returns the last frame that was written by the DMX master. The size of the array is equivalent to the number of channels in the frame. Each byte represents one channel.
The next frame is available after the CALLBACK_FRAME_AVAILABLE callback was called.
Generic approach:
-
Call BrickletDMX#read_frame to get first frame.
-
Wait for the CALLBACK_FRAME_AVAILABLE callback.
-
Call BrickletDMX#read_frame to get second frame.
-
Wait for the CALLBACK_FRAME_AVAILABLE callback.
-
and so on.
Instead of polling this function you can also use the CALLBACK_FRAME callback. You can enable it with BrickletDMX#set_frame_callback_config.
The frame number starts at 0 and it is increased by one with each received frame.
This function can only be called in slave mode.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 526 def read_frame ret = nil # assigned in block frame_length = nil # assigned in block frame_data = nil # assigned in block @stream_mutex.synchronize { ret = read_frame_low_level frame_length = ret[0] frame_chunk_offset = ret[1] frame_out_of_sync = frame_chunk_offset != 0 frame_data = ret[2] while not frame_out_of_sync and frame_data.length < frame_length ret = read_frame_low_level frame_length = ret[0] frame_chunk_offset = ret[1] frame_out_of_sync = frame_chunk_offset != frame_data.length frame_data += ret[2] end if frame_out_of_sync # discard remaining stream to bring it back in-sync while frame_chunk_offset + 56 < frame_length ret = read_frame_low_level frame_length = ret[0] frame_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Frame stream is out-of-sync' end } [frame_data[0, frame_length], ret[3]] end |
#read_frame_low_level ⇒ Object
Returns the last frame that was written by the DMX master. The size of the array is equivalent to the number of channels in the frame. Each byte represents one channel.
The next frame is available after the CALLBACK_FRAME_AVAILABLE callback was called.
Generic approach:
-
Call BrickletDMX#read_frame to get first frame.
-
Wait for the CALLBACK_FRAME_AVAILABLE callback.
-
Call BrickletDMX#read_frame to get second frame.
-
Wait for the CALLBACK_FRAME_AVAILABLE callback.
-
and so on.
Instead of polling this function you can also use the CALLBACK_FRAME callback. You can enable it with BrickletDMX#set_frame_callback_config.
The frame number starts at 0 and it is increased by one with each received frame.
This function can only be called in slave mode.
218 219 220 221 222 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 218 def read_frame_low_level check_validity send_request FUNCTION_READ_FRAME_LOW_LEVEL, [], '', 72, 'S S C56 L' end |
#read_uid ⇒ Object
Returns the current UID as an integer. Encode as Base58 to get the usual string version.
436 437 438 439 440 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 436 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
561 562 563 564 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 561 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
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!
417 418 419 420 421 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 417 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_bootloader_mode(mode) ⇒ Object
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.
340 341 342 343 344 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 340 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end |
#set_communication_led_config(config) ⇒ Object
Sets the communication LED configuration. By default the LED shows communication traffic, 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 off.
259 260 261 262 263 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 259 def set_communication_led_config(config) check_validity send_request FUNCTION_SET_COMMUNICATION_LED_CONFIG, [config], 'C', 8, '' end |
#set_dmx_mode(dmx_mode) ⇒ Object
Sets the DMX mode to either master or slave.
Calling this function sets frame number to 0.
160 161 162 163 164 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 160 def set_dmx_mode(dmx_mode) check_validity send_request FUNCTION_SET_DMX_MODE, [dmx_mode], 'C', 8, '' end |
#set_error_led_config(config) ⇒ Object
Sets the error LED configuration.
By default the error LED turns on if there is any error (see CALLBACK_FRAME_ERROR_COUNT callback). If you call this function with the Show-Error option again, the LED will turn off until the next error occurs.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is off.
281 282 283 284 285 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 281 def set_error_led_config(config) check_validity send_request FUNCTION_SET_ERROR_LED_CONFIG, [config], 'C', 8, '' end |
#set_frame_callback_config(frame_started_callback_enabled, frame_available_callback_enabled, frame_callback_enabled, frame_error_count_callback_enabled) ⇒ Object
Enables/Disables the different callbacks. By default the CALLBACK_FRAME_STARTED callback and CALLBACK_FRAME_AVAILABLE callback are enabled while the CALLBACK_FRAME callback and CALLBACK_FRAME_ERROR_COUNT callback are disabled.
If you want to use the CALLBACK_FRAME callback you can enable it and disable the cb:‘Frame Available` callback at the same time. It becomes redundant in this case.
301 302 303 304 305 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 301 def set_frame_callback_config(frame_started_callback_enabled, frame_available_callback_enabled, frame_callback_enabled, frame_error_count_callback_enabled) check_validity send_request FUNCTION_SET_FRAME_CALLBACK_CONFIG, [frame_started_callback_enabled, frame_available_callback_enabled, frame_callback_enabled, frame_error_count_callback_enabled], '? ? ? ?', 8, '' end |
#set_frame_duration(frame_duration) ⇒ Object
Sets the duration of a frame.
Example: If you want to achieve 20 frames per second, you should set the frame duration to 50ms (50ms * 20 = 1 second).
If you always want to send a frame as fast as possible you can set this value to 0.
This setting is only used in master mode.
233 234 235 236 237 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 233 def set_frame_duration(frame_duration) check_validity send_request FUNCTION_SET_FRAME_DURATION, [frame_duration], 'S', 8, '' end |
#set_status_led_config(config) ⇒ Object
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.
386 387 388 389 390 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 386 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end |
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletDMX#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.
359 360 361 362 363 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 359 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end |
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletDMX#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.
373 374 375 376 377 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 373 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end |
#write_frame(frame) ⇒ Object
Writes a DMX frame. The maximum frame size is 512 byte. Each byte represents one channel.
The next frame can be written after the CALLBACK_FRAME_STARTED callback was called. The frame is double buffered, so a new frame can be written as soon as the writing of the prior frame starts.
The data will be transfered when the next frame duration ends, see BrickletDMX#set_frame_duration.
Generic approach:
-
Set the frame duration to a value that represents the number of frames per second you want to achieve.
-
Set channels for first frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
Set channels for next frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
and so on.
This approach ensures that you can set new DMX data with a fixed frame rate.
This function can only be called in master mode.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 476 def write_frame(frame) if frame.length > 65535 raise ArgumentError, 'Frame can be at most 65535 items long' end frame_length = frame.length frame_chunk_offset = 0 if frame_length == 0 frame_chunk_data = [0] * 60 ret = write_frame_low_level frame_length, frame_chunk_offset, frame_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while frame_chunk_offset < frame_length frame_chunk_data = frame[frame_chunk_offset, 60] if frame_chunk_data.length < 60 frame_chunk_data += [0] * (60 - frame_chunk_data.length) end ret = write_frame_low_level frame_length, frame_chunk_offset, frame_chunk_data frame_chunk_offset += 60 end } end ret end |
#write_frame_low_level(frame_length, frame_chunk_offset, frame_chunk_data) ⇒ Object
Writes a DMX frame. The maximum frame size is 512 byte. Each byte represents one channel.
The next frame can be written after the CALLBACK_FRAME_STARTED callback was called. The frame is double buffered, so a new frame can be written as soon as the writing of the prior frame starts.
The data will be transfered when the next frame duration ends, see BrickletDMX#set_frame_duration.
Generic approach:
-
Set the frame duration to a value that represents the number of frames per second you want to achieve.
-
Set channels for first frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
Set channels for next frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
and so on.
This approach ensures that you can set new DMX data with a fixed frame rate.
This function can only be called in master mode.
193 194 195 196 197 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 193 def write_frame_low_level(frame_length, frame_chunk_offset, frame_chunk_data) check_validity send_request FUNCTION_WRITE_FRAME_LOW_LEVEL, [frame_length, frame_chunk_offset, frame_chunk_data], 'S S C60', 8, '' end |
#write_uid(uid) ⇒ Object
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.
428 429 430 431 432 |
# File 'lib/tinkerforge/bricklet_dmx.rb', line 428 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end |