8000 drivers/onewire: Fix undefined variable errors. · micropython/micropython@fbfea3b · GitHub
[go: up one dir, main page]

Skip to content

Commit fbfea3b

Browse files
amotldpgeorge
authored andcommitted
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).
1 parent 2f7d2bb commit fbfea3b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/onewire/onewire.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# 1-Wire driver for MicroPython
22
# MIT license; Copyright (c) 2016 Damien P. George
33

4-
from micropython import const
54
import _onewire as _ow
65

76

@@ -10,9 +9,9 @@ class OneWireError(Exception):
109

1110

1211
class OneWire:
13-
SEARCH_ROM = const(0xF0)
14-
MATCH_ROM = const(0x55)
15-
SKIP_ROM = const(0xCC)
12+
SEARCH_ROM = 0xF0
13+
MATCH_ROM = 0x55
14+
SKIP_ROM = 0xCC
1615

1716
def __init__(self, pin):
1817
self.pin = pin
@@ -46,7 +45,7 @@ def write(self, buf):
4645

4746
def select_rom(self, rom):
4847
self.reset()
49-
self.writebyte(MATCH_ROM)
48+
self.writebyte(self.MATCH_ROM)
5049
self.write(rom)
5150

5251
def scan(self):
@@ -64,7 +63,7 @@ def scan(self):
6463
def _search_rom(self, l_rom, diff):
6564
if not self.reset():
6665
return None, 0
67-
self.writebyte(SEARCH_ROM)
66+
self.writebyte(self.SEARCH_ROM)
6867
if not l_rom:
6968
l_rom = bytearray(8)
7069
rom = bytearray(8)

0 commit comments

Comments
 (0)
0