"""
This example is used for I2C communication between Raspberry pi and ECC-1C controller with lens.
It sets I2C readout pointers (0x3100 and 0x3101) to 0xE802 (current value) and 0x2200 (device temperature) register addresses.
And sets Focal Power to 2.5 dpt.
"""

import smbus
import time

bus = smbus.SMBus(1)

slave_address = 0x20  # ECC-1C slave address
num_bytes = 12  # 12 bytes of data sent in 1 package

data_array_ReadCurTemp = [0x00, 0x00, 0x00, 0xE8, 0x02, 0x31, 0x01, 0x00, 0x00, 0x22, 0x00]
# Arduino uses array: data_array_ReadCurTemp = [0x31, 0x00, 0x00, 0x00, 0xE8, 0x02, 0x31, 0x01, 0x00, 0x00, 0x22, 0x00]
# but the 0x31 address is used in register address in write_i2c_block_data
data_array_SetFPReadTemp = [0x04, 0x40, 0x20, 0x00, 0x00, 0x31, 0x01, 0x00, 0x00, 0x22, 0x00]
# Arduino uses array: data_array_SetFPReadTemp = [0x50, 0x04, 0x40, 0x20, 0x00, 0x00, 0x31, 0x01, 0x00, 0x00, 0x22, 0x00]
# but the 0x50 address is used in register address in write_i2c_block_data

bus.write_i2c_block_data(slave_address, 0x31, data_array_ReadCurReadTemp)
time.sleep(0.05)
    
bus.write_i2c_block_data(slave_address, 0x50, data_array_SetFPReadTemp)
time.sleep(0.05)

print("Data sent over I2C bus")

data_received = bus.read_i2c_block_data(slave_address, 0x00, num_bytes)
print("Data received:", data_received)
