Skip to content

Commit 703d54a

Browse files
committed
Add patches for nxt_python to fix imports
1 parent d19615c commit 703d54a

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

nxt/nxt_python/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ nxt-python: $(INSTALL_DIR)/installed
1414
$(INSTALL_DIR)/installed: $(SOURCE_DIR)/unpacked
1515
rm -rf src/nxt
1616
cd $(SOURCE_DIR) && python setup.py install --prefix=$(INSTALL_DIR) --install-purelib=$(INSTALL_DIR)/src
17-
patch -p0 bin/nxt_filer patches/nxt_filer.patch
18-
patch -p0 bin/nxt_push patches/nxt_push.patch
19-
patch -p0 bin/nxt_server patches/nxt_server.patch
20-
patch -p0 bin/nxt_test patches/nxt_test.patch
17+
patch -p0 src/nxt/brick.py patches/brick.patch
18+
patch -p0 src/nxt/sensor/digital.py patches/digital.patch
19+
patch -p0 bin/nxt_filer patches/nxt_filer.patch
20+
patch -p0 bin/nxt_push patches/nxt_push.patch
21+
patch -p0 bin/nxt_server patches/nxt_server.patch
22+
patch -p0 bin/nxt_test patches/nxt_test.patch
2123
touch $(INSTALL_DIR)/installed
2224

2325
clean:

nxt/nxt_python/patches/brick.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- brick.py
2+
+++ brick-new.py
3+
@@ -13,7 +13,7 @@
4+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5+
# GNU General Public License for more details.
6+
7+
-from time import sleep
8+
+import time # sleep()
9+
from threading import Lock
10+
from nxt.error import FileNotFound, ModuleNotFound
11+
from nxt.telegram import OPCODES, Telegram
12+
@@ -224,7 +224,7 @@
13+
14+
def play_tone_and_wait(self, frequency, duration):
15+
self.play_tone(frequency, duration)
16+
- sleep(duration / 1000.0)
17+
+ time.sleep(duration / 1000.0)
18+
19+
def __del__(self):
20+
self.sock.close()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--- digital.py
2+
+++ digital-new.py
3+
@@ -16,7 +16,7 @@
4+
from nxt.error import I2CError, I2CPendingError, DirProtError
5+
6+
from common import *
7+
-from time import sleep, time
8+
+import time # sleep(), time()
9+
import struct
10+
11+
12+
@@ -63,9 +63,9 @@
13+
"""
14+
super(BaseDigitalSensor, self).__init__(brick, port)
15+
self.set_input_mode(Type.LOW_SPEED_9V, Mode.RAW)
16+
- self.last_poll = time()
17+
+ self.last_poll = time.time()
18+
self.poll_delay = 0.01
19+
- sleep(0.1) # Give I2C time to initialize
20+
+ time.sleep(0.1) # Give I2C time to initialize
21+
#Don't do type checking if this class has no compatible sensors listed.
22+
try: self.compatible_sensors
23+
except AttributeError: check_compatible = False
24+
@@ -96,11 +96,11 @@
25+
"""
26+
value = struct.pack(format, *value)
27+
msg = chr(self.I2C_DEV) + chr(address) + value
28+
- now = time()
29+
+ now = time.time()
30+
if self.last_poll+self.poll_delay > now:
31+
diff = now - self.last_poll
32+
- sleep(self.poll_delay - diff)
33+
- self.last_poll = time()
34+
+ time.sleep(self.poll_delay - diff)
35+
+ self.last_poll = time.time()
36+
self.brick.ls_write(self.port, msg, 0)
37+
38+
def _i2c_query(self, address, format):
39+
@@ -110,11 +110,11 @@
40+
"""
41+
n_bytes = struct.calcsize(format)
42+
msg = chr(self.I2C_DEV) + chr(address)
43+
- now = time()
44+
+ now = time.time()
45+
if self.last_poll+self.poll_delay > now:
46+
diff = now - self.last_poll
47+
- sleep(self.poll_delay - diff)
48+
- self.last_poll = time()
49+
+ time.sleep(self.poll_delay - diff)
50+
+ self.last_poll = time.time()
51+
self.brick.ls_write(self.port, msg, n_bytes)
52+
try:
53+
self._ls_get_status(n_bytes)

0 commit comments

Comments
 (0)