@@ -61,12 +61,13 @@ class I2CDevice:
61
61
def __init__ (self , i2c , device_address , probe = True ):
62
62
63
63
self .i2c = i2c
64
+ self ._has_write_read = hasattr (self .i2c , 'writeto_then_readfrom' )
64
65
self .device_address = device_address
65
66
66
67
if probe :
67
68
self .__probe_for_device ()
68
69
69
- def readinto (self , buf , ** kwargs ):
70
+ def readinto (self , buf , * , start = 0 , end = None ):
70
71
"""
71
72
Read into ``buf`` from the device. The number of bytes read will be the
72
73
length of ``buf``.
@@ -79,9 +80,9 @@ def readinto(self, buf, **kwargs):
79
80
:param int start: Index to start writing at
80
81
:param int end: Index to write up to but not include
81
82
"""
82
- self .i2c .readfrom_into (self .device_address , buf , ** kwargs )
83
+ self .i2c .readfrom_into (self .device_address , buf , start = start , end = end )
83
84
84
- def write (self , buf , ** kwargs ):
85
+ def write (self , buf , * , start = 0 , end = None , stop = True ):
85
86
"""
86
87
Write the bytes from ``buffer`` to the device. Transmits a stop bit if
87
88
``stop`` is set.
@@ -95,7 +96,7 @@ def write(self, buf, **kwargs):
95
96
:param int end: Index to read up to but not include
96
97
:param bool stop: If true, output an I2C stop condition after the buffer is written
97
98
"""
98
- self .i2c .writeto (self .device_address , buf , ** kwargs )
99
+ self .i2c .writeto (self .device_address , buf , start = start , end = end , stop = stop )
99
100
100
101
#pylint: disable-msg=too-many-arguments
101
102
def write_then_readinto (self , out_buffer , in_buffer , * ,
@@ -129,7 +130,7 @@ def write_then_readinto(self, out_buffer, in_buffer, *,
129
130
in_end = len (in_buffer )
130
131
if stop :
131
132
raise ValueError ("Stop must be False. Use writeto instead." )
132
- if hasattr ( self .i2c , 'writeto_then_readfrom' ) :
133
+ if self ._has_write_read :
133
134
# In linux, at least, this is a special kernel function call
134
135
self .i2c .writeto_then_readfrom (self .device_address , out_buffer , in_buffer ,
135
136
out_start = out_start , out_end = out_end ,
@@ -147,7 +148,7 @@ def __enter__(self):
147
148
pass
148
149
return self
149
150
150
- def __exit__ (self , * exc ):
151
+ def __exit__ (self , exc_type , exc_val , exc_tb ):
151
152
self .i2c .unlock ()
152
153
return False
153
154
0 commit comments