Commit 8e9b98e9 authored by Damien George's avatar Damien George
Browse files

esp8266/modules/onewire: Change to onewire.readinto().

This allows 1-wire drivers (eg DS18X20) to perform in-place operations and
hence do less memory allocations.
parent 9fba6183
......@@ -8,6 +8,7 @@ _WR_SCRATCH = const(0x4e)
class DS18X20:
def __init__(self, onewire):
self.ow = onewire
self.buf = bytearray(9)
def scan(self):
return [rom for rom in self.ow.scan() if rom[0] == 0x28]
......@@ -21,10 +22,10 @@ class DS18X20:
buf =
if self.ow.crc8(buf):
if self.ow.crc8(self.buf):
raise Exception('CRC error')
return buf
return self.buf
def write_scratch(self, rom, buf):
......@@ -27,11 +27,9 @@ class OneWire:
def readbyte(self):
return _ow.readbyte(
def read(self, count):
buf = bytearray(count)
for i in range(count):
def readinto(self, buf):
for i in range(len(buf)):
buf[i] = _ow.readbyte(
return buf
def writebit(self, value):
return _ow.writebit(, value)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment