def send_image_command_with_slaves(self, image_bits, sequence_byte): """ :param image_bits is a numpy uint array of the current payload :param sequence_byte is there for bookkeeping, gets placed as sequence byte of first command """ payload_length = np.size(image_bits) assert payload_length <= 504 command = [0x00] * 8 command[1] = np.uint8(sequence_byte % 256) data_length_with_data_header = hh.int2reversed_hex_array( 2 + 2 + payload_length) # 2 for the command bytes, 2 for the length bytes in the payload, then payload data_length = hh.int2reversed_hex_array(np.size(image_bits)) # compute number of slaves if payload_length <= 56: print "preparing last packet of image" n_slaves = 0 pad_width = 56 - payload_length image_bits_padded = np.pad(image_bits, (0, pad_width), 'constant', constant_values=(0, 0)) else: n_slaves = (payload_length - 56) / 64 if (payload_length - 56) % 64 != 0: n_slaves += 1 pad_width = (64 - (payload_length - 56) % 64) % 64 image_bits_padded = np.pad(image_bits, (0, pad_width), 'constant', constant_values=(0, 0)) for i in range(2): command[2 + i] = data_length_with_data_header[i] command[4] = 0x2B command[5] = 0x1A for j in range(2): command[6 + j] = data_length[j] if n_slaves == 0: command += image_bits_padded.tolist() self.raw_command(command) else: command += image_bits_padded[0:56].tolist() self.raw_command(command) slave_bits = image_bits_padded[56:] for k in range(n_slaves): if OS_TYPE == 'windows': print "slave rng %s, %s" % (64 * k, 64 * (k + 1)) print "length %s" % len( slave_bits[64 * k:64 * k + 64].tolist()) self.raw_command(slave_bits[64 * k:64 * k + 64].tolist())
def trigger_out_1_config(self, trigger_on_delay=50, trigger_off_delay=-20): # us trigger_on_delay_bytes = hh.int2reversed_hex_array(trigger_on_delay, n_bytes=2) trigger_off_delay_bytes = hh.int2reversed_hex_array(trigger_off_delay, n_bytes=2) trigger_inversion = [0x00] # for inverted trigger set equal to [0x01] data = trigger_inversion + trigger_on_delay_bytes + trigger_off_delay_bytes self.dmd_command('w', True, 0x43, 0x1a, 0x1d, data)
def pattern_display_lut_definition(self, num_patterns, num_repeat=0): print "configuring lookup table" num_patterns_bytes = hh.int2reversed_hex_array(num_patterns, n_bytes=2) num_repeats_bytes = hh.int2reversed_hex_array(num_repeat, n_bytes=4) data = num_patterns_bytes + num_repeats_bytes #self.dmd_command('w', True, 0x78, 0x1a, 0x31, data) self.dmd_command( 'w', False, 0x0d, 0x1a, 0x31, data, is_read=False) #NOTE: THE IS READ = FALSE IS ESSENTIAL self.check_for_errors()
def pattern_def_cmd(self, pattern_index, exposure_time=105, dark_time=0, is_wait_for_trig=True): assert pattern_index < 256 and pattern_index >= 0 pattern_index_bytes = hh.int2reversed_hex_array(pattern_index, 2) exposure_bytes = hh.int2reversed_hex_array(exposure_time, 3) trigger_settings_bytes = [0xf1] if is_wait_for_trig else [0x01] dark_time_bytes = hh.int2reversed_hex_array(dark_time, 3) trig2_output_bytes = [0x00] data = pattern_index_bytes + exposure_bytes + trigger_settings_bytes + \ dark_time_bytes + trig2_output_bytes + pattern_index_bytes self.dmd_command('w', True, 0x65, 0x1a, 0x34, data) self.check_for_errors()
def trigger_1_config(self, trigger_delay, is_trigger_rising_edge=True): assert trigger_delay > 104 print "configuring trigger" trigger_delay_bytes = hh.int2reversed_hex_array(trigger_delay, n_bytes=2) rising_edge_bit = [0x00] if is_trigger_rising_edge else [0x01] self.dmd_command('w', True, 0x43, 0x1a, 0x35, trigger_delay_bytes + rising_edge_bit) self.check_for_errors()
def make_header(compressed_pattern_length,compression_type): """ :return header for sending the images """ #Note: taken directly from sniffer of the TI GUI header = [0x53, 0x70, 0x6C, 0x64, #Signature 0x80, 0x07, 0x38, 0x04, #Width and height: 1920, 1080 0x60, 0x11, 0x00, 0x00, #Number of bytes in encoded image_data 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, #reserved 0x00, 0x00, 0x00, 0x00, # BG color BB, GG, RR, 00 0x01, #0x01 reserved - manual says 0, sniffer says 1 0x02, #encoding 0 none, 1 rle, 2 erle 0x01, #reserved 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] #reserved encoded_length_bytes_header = hh.int2reversed_hex_array(compressed_pattern_length, 4) compression_dictionary = {'none': 0, 'rle': 1, 'erle': 2} for i in range(4): header[8 + i] = encoded_length_bytes_header[i] header[25] = compression_dictionary[compression_type] return np.array(header, dtype=np.uint8).tolist()
def bmp_load(self, length, index=0): data = hh.int2reversed_hex_array(index, n_bytes=2) data += hh.int2reversed_hex_array(length, n_bytes=4) self.dmd_command('w', True, 0x11, 0x1a, 0x2a, data=data) self.check_for_errors()