|
12 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 13 | # GNU General Public License for more details. |
14 | 14 |
|
15 | | -from time import sleep |
| 15 | +from time import sleep, time |
16 | 16 | from nxt.error import I2CError, I2CPendingError |
17 | 17 |
|
18 | 18 | PORT_1 = 0x00 |
@@ -93,7 +93,6 @@ def __init__(cls, name, bases, dict): |
93 | 93 | q = _make_query(address, n_bytes) |
94 | 94 | setattr(cls, 'get_' + name, q) |
95 | 95 |
|
96 | | -import time |
97 | 96 | class DigitalSensor(Sensor): |
98 | 97 | 'Object for digital sensors' |
99 | 98 |
|
@@ -121,14 +120,14 @@ def i2c_command(self, address, value): |
121 | 120 |
|
122 | 121 | def i2c_query(self, address, n_bytes): |
123 | 122 | 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) |
128 | 127 | self.brick.ls_write(self.port, msg, n_bytes) |
129 | 128 | self._ls_get_status(n_bytes) |
130 | 129 | data = self.brick.ls_read(self.port) |
131 | | - self.lastpoll = time.time() |
| 130 | + self.lastpoll = time() |
132 | 131 | if len(data) < n_bytes: |
133 | 132 | raise I2CError, 'Read failure' |
134 | 133 | return data[-n_bytes:] |
|
0 commit comments