Skip to content

Change stop to False and throw error if True. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions adafruit_bus_device/i2c_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ def write(self, buf, **kwargs):

#pylint: disable-msg=too-many-arguments
def write_then_readinto(self, out_buffer, in_buffer, *,
out_start=0, out_end=None, in_start=0, in_end=None, stop=True):
out_start=0, out_end=None, in_start=0, in_end=None, stop=False):
"""
Write the bytes from ``out_buffer`` to the device, then immediately
reads into ``in_buffer`` from the device. The number of bytes read
will be the length of ``in_buffer``.
Transmits a stop bit after the write, if ``stop`` is set.

If ``out_start`` or ``out_end`` is provided, then the output buffer
will be sliced as if ``out_buffer[out_start:out_end]``. This will
Expand All @@ -136,21 +135,23 @@ def write_then_readinto(self, out_buffer, in_buffer, *,
:param int out_end: Index to read up to but not include
:param int in_start: Index to start writing at
:param int in_end: Index to write up to but not include
:param bool stop: If true, output an I2C stop condition after the buffer is written
:param bool stop: Deprecated
"""
if out_end is None:
out_end = len(out_buffer)
if in_end is None:
in_end = len(in_buffer)
if stop:
raise ValueError("Stop must be False. Use writeto instead.")
if hasattr(self.i2c, 'writeto_then_readfrom'):
# In linux, at least, this is a special kernel function call
self.i2c.writeto_then_readfrom(self.device_address, out_buffer, in_buffer,
out_start=out_start, out_end=out_end,
in_start=in_start, in_end=in_end, stop=stop)
in_start=in_start, in_end=in_end)

else:
# If we don't have a special implementation, we can fake it with two calls
self.write(out_buffer, start=out_start, end=out_end, stop=stop)
self.write(out_buffer, start=out_start, end=out_end, stop=False)
self.readinto(in_buffer, start=in_start, end=in_end)

#pylint: enable-msg=too-many-arguments
Expand Down