@@ -77,8 +77,7 @@ def read_register(self, register: int, byte_count: int = 1, max_tries: int = 5)
7777 except RuntimeError as e :
7878 LH .warning ("[%s] Unable to read register 0x%02X (%i/%i): %s" , __name__ , register , cur_try , max_tries , e )
7979 time .sleep (0.001 )
80- else :
81- raise RuntimeError (f"Unable to read register 0x{ register :02X} after { cur_try } attempts. Giving up." )
80+ raise RuntimeError (f"Unable to read register 0x{ register :02X} after { cur_try } attempts. Giving up." )
8281
8382 def write_register (self , register : int , value : int , byte_count : int = 1 , max_tries : int = 3 ):
8483 """
@@ -91,10 +90,9 @@ def write_register(self, register: int, value: int, byte_count: int = 1, max_tri
9190 """
9291 _validate_register_address (register )
9392 ba = convert_uint_to_bytearry (value , byte_count )
94- buf = bytearray (1 + len (ba ))
95- buf [0 ] = register
96- for i in range (len (ba )):
97- buf [1 + i ] = ba [i ]
93+ buf = bytearray ([register ])
94+ for byte in ba :
95+ buf .append (byte )
9896 for cur_try in range (1 , 1 + max_tries ):
9997 try :
10098 self ._i2c_bus .writeto (address = self ._i2c_adr , buffer = buf )
@@ -106,8 +104,7 @@ def write_register(self, register: int, value: int, byte_count: int = 1, max_tri
106104 except RuntimeError as e :
107105 LH .warning ("[%s] Unable to read register 0x%02X (%i/%i): %s" , __name__ , register , cur_try , max_tries , e )
108106 time .sleep (0.1 )
109- else :
110- raise RuntimeError (f"Unable to read register 0x{ register :02X} after { cur_try } attempts. Giving up." )
107+ raise RuntimeError (f"Unable to read register 0x{ register :02X} after { cur_try } attempts. Giving up." )
111108
112109 # it is unclear if it's possible to have a multi-byte state registers
113110 # (a register write looks exactly like a multi-byte state write)
@@ -135,8 +132,7 @@ def get_state(self, byte_count: int = 1, max_tries: int = 5) -> int:
135132 except RuntimeError as e :
136133 LH .warning ("[%s] Unable to read state (%i/%i): %s" , __name__ , cur_try , max_tries , e )
137134 time .sleep (0.001 )
138- else :
139- raise RuntimeError (f"Unable to read state after { cur_try } attempts. Giving up." )
135+ raise RuntimeError (f"Unable to read state after { cur_try } attempts. Giving up." )
140136
141137 def set_state (self , value : int , byte_count : int = 1 , max_tries : int = 3 ):
142138 """
@@ -158,10 +154,9 @@ def set_state(self, value: int, byte_count: int = 1, max_tries: int = 3):
158154 LH .warning ("[%s] Failed to write state (%i/%i): %s" , __name__ , cur_try , max_tries , e )
159155 time .sleep (0.1 )
160156 except RuntimeError as e :
161- LH .warning ("[%s] Unable to write state 0x%02X (%i/%i): %s" , __name__ , cur_try , max_tries , e )
157+ LH .warning ("[%s] Unable to write state (%i/%i): %s" , __name__ , cur_try , max_tries , e )
162158 time .sleep (0.1 )
163- else :
164- raise RuntimeError (f"Unable to write state after { cur_try } attempts. Giving up." )
159+ raise RuntimeError (f"Unable to write state after { cur_try } attempts. Giving up." )
165160
166161
167162class BurstHandler :
@@ -182,6 +177,8 @@ def __init__(self, i2c_bus: busio.I2C, i2c_adr: int, timeout_ms: int | None = 50
182177 self ._timeout_ms = timeout_ms
183178 else :
184179 raise ValueError ("Provided timeout is not a positive integer or 'None'!" )
180+ # register '_timestart_ns' - we will populate it later on
181+ self ._timestart_ns = 0
185182
186183 def __enter__ (self ) -> BurstHandle :
187184 """
0 commit comments