Skip to content

Commit 7bcee8d

Browse files
author
marcusw
committed
Cleaned up digital sensor bug fix in trunk.
1 parent e57aa14 commit 7bcee8d

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

nxt/sensor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
1414

15-
from time import sleep
15+
from time import sleep, time
1616
from nxt.error import I2CError, I2CPendingError
1717

1818
PORT_1 = 0x00
@@ -93,7 +93,6 @@ def __init__(cls, name, bases, dict):
9393
q = _make_query(address, n_bytes)
9494
setattr(cls, 'get_' + name, q)
9595

96-
import time
9796
class DigitalSensor(Sensor):
9897
'Object for digital sensors'
9998

@@ -121,14 +120,14 @@ def i2c_command(self, address, value):
121120

122121
def i2c_query(self, address, n_bytes):
123122
msg = chr(DigitalSensor.I2C_DEV) + chr(address)
124-
if not self.lastpoll: self.lastpoll = time.time()
125-
if self.lastpoll+0.02 > time.time():
126-
diff = time.time() - self.lastpoll
127-
time.sleep(0.02 - diff)
123+
if not self.lastpoll: self.lastpoll = time()
124+
if self.lastpoll+0.02 > time():
125+
diff = time() - self.lastpoll
126+
sleep(0.02 - diff)
128127
self.brick.ls_write(self.port, msg, n_bytes)
129128
self._ls_get_status(n_bytes)
130129
data = self.brick.ls_read(self.port)
131-
self.lastpoll = time.time()
130+
self.lastpoll = time()
132131
if len(data) < n_bytes:
133132
raise I2CError, 'Read failure'
134133
return data[-n_bytes:]

0 commit comments

Comments
 (0)