@@ -61,12 +61,13 @@ class I2CDevice:
6161 def __init__ (self , i2c , device_address , probe = True ):
6262
6363 self .i2c = i2c
64+ self ._has_write_read = hasattr (self .i2c , 'writeto_then_readfrom' )
6465 self .device_address = device_address
6566
6667 if probe :
6768 self .__probe_for_device ()
6869
69- def readinto (self , buf , ** kwargs ):
70+ def readinto (self , buf , * , start = 0 , end = None ):
7071 """
7172 Read into ``buf`` from the device. The number of bytes read will be the
7273 length of ``buf``.
@@ -79,9 +80,9 @@ def readinto(self, buf, **kwargs):
7980 :param int start: Index to start writing at
8081 :param int end: Index to write up to but not include
8182 """
82- self .i2c .readfrom_into (self .device_address , buf , ** kwargs )
83+ self .i2c .readfrom_into (self .device_address , buf , start = start , end = end )
8384
84- def write (self , buf , ** kwargs ):
85+ def write (self , buf , * , start = 0 , end = None , stop = True ):
8586 """
8687 Write the bytes from ``buffer`` to the device. Transmits a stop bit if
8788 ``stop`` is set.
@@ -95,7 +96,7 @@ def write(self, buf, **kwargs):
9596 :param int end: Index to read up to but not include
9697 :param bool stop: If true, output an I2C stop condition after the buffer is written
9798 """
98- self .i2c .writeto (self .device_address , buf , ** kwargs )
99+ self .i2c .writeto (self .device_address , buf , start = start , end = end , stop = stop )
99100
100101#pylint: disable-msg=too-many-arguments
101102 def write_then_readinto (self , out_buffer , in_buffer , * ,
@@ -129,7 +130,7 @@ def write_then_readinto(self, out_buffer, in_buffer, *,
129130 in_end = len (in_buffer )
130131 if stop :
131132 raise ValueError ("Stop must be False. Use writeto instead." )
132- if hasattr ( self .i2c , 'writeto_then_readfrom' ) :
133+ if self ._has_write_read :
133134 # In linux, at least, this is a special kernel function call
134135 self .i2c .writeto_then_readfrom (self .device_address , out_buffer , in_buffer ,
135136 out_start = out_start , out_end = out_end ,
@@ -147,7 +148,7 @@ def __enter__(self):
147148 pass
148149 return self
149150
150- def __exit__ (self , * exc ):
151+ def __exit__ (self , exc_type , exc_val , exc_tb ):
151152 self .i2c .unlock ()
152153 return False
153154
0 commit comments