kopia lustrzana https://github.com/micropython/micropython
drivers/onewire: Fix undefined variable errors.
On CPython, and with pylint, the variables MATCH_ROM and SEARCH_ROM are undefined. This code works in MicroPython because these variables are constants and the MicroPython parser/compiler optimises them out. But it is not valid Python because they are technically undefined within the scope they are used. This commit makes the code valid Python code. The const part is removed completely because these constants are part of the public API and so cannot be moved to the global scope (where they could still use the MicroPython const optimisation).pull/5788/merge
rodzic
2f7d2bb3e2
commit
fbfea3b440
|
@ -1,7 +1,6 @@
|
||||||
# 1-Wire driver for MicroPython
|
# 1-Wire driver for MicroPython
|
||||||
# MIT license; Copyright (c) 2016 Damien P. George
|
# MIT license; Copyright (c) 2016 Damien P. George
|
||||||
|
|
||||||
from micropython import const
|
|
||||||
import _onewire as _ow
|
import _onewire as _ow
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,9 +9,9 @@ class OneWireError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class OneWire:
|
class OneWire:
|
||||||
SEARCH_ROM = const(0xF0)
|
SEARCH_ROM = 0xF0
|
||||||
MATCH_ROM = const(0x55)
|
MATCH_ROM = 0x55
|
||||||
SKIP_ROM = const(0xCC)
|
SKIP_ROM = 0xCC
|
||||||
|
|
||||||
def __init__(self, pin):
|
def __init__(self, pin):
|
||||||
self.pin = pin
|
self.pin = pin
|
||||||
|
@ -46,7 +45,7 @@ class OneWire:
|
||||||
|
|
||||||
def select_rom(self, rom):
|
def select_rom(self, rom):
|
||||||
self.reset()
|
self.reset()
|
||||||
self.writebyte(MATCH_ROM)
|
self.writebyte(self.MATCH_ROM)
|
||||||
self.write(rom)
|
self.write(rom)
|
||||||
|
|
||||||
def scan(self):
|
def scan(self):
|
||||||
|
@ -64,7 +63,7 @@ class OneWire:
|
||||||
def _search_rom(self, l_rom, diff):
|
def _search_rom(self, l_rom, diff):
|
||||||
if not self.reset():
|
if not self.reset():
|
||||||
return None, 0
|
return None, 0
|
||||||
self.writebyte(SEARCH_ROM)
|
self.writebyte(self.SEARCH_ROM)
|
||||||
if not l_rom:
|
if not l_rom:
|
||||||
l_rom = bytearray(8)
|
l_rom = bytearray(8)
|
||||||
rom = bytearray(8)
|
rom = bytearray(8)
|
||||||
|
|
Ładowanie…
Reference in New Issue