Skip to content

Commit 3eade55

Browse files
committed
First porting from Hamster
1 parent 28d6f98 commit 3eade55

15 files changed

+3074
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
22
dist/
3-
*.egg-info/
3+
*.egg-info/
4+
__pycache__/

neobot/__init__.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,55 @@
1616
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1717
# Boston, MA 02111-1307 USA
1818

19+
import signal
20+
21+
from neobot.scanner import Scanner
22+
from neobot.mode import Mode
23+
from neobot.keyboard import Keyboard
24+
from neobot.runner import Runner
25+
from neobot.model import DeviceType
26+
from neobot.model import DataType
27+
from neobot.neosoco import Neosoco
28+
1929
__version__ = "0.1.0"
2030

21-
__all__ = ["NEO SoCo"]
31+
__all__ = ["DeviceType", "DataType", "Neosoco", "Keyboard", "scan", "is_link_mode", "link_mode", "dispose", "set_executable", "wait", "wait_until_ready", "wait_until", "when_do", "while_do", "parallel"]
32+
33+
def scan():
34+
Scanner.scan()
35+
36+
def is_link_mode():
37+
return Mode.is_link_mode()
38+
39+
def link_mode(url='ws://127.0.0.1:59418'):
40+
Mode.set_link_mode(url)
41+
42+
def dispose():
43+
Runner.dispose_all()
44+
45+
def set_executable(execute):
46+
Runner.set_executable(execute)
47+
48+
def wait(milliseconds):
49+
Runner.wait(milliseconds)
50+
51+
def wait_until_ready():
52+
Runner.wait_until_ready()
53+
54+
def wait_until(condition, args=None):
55+
Runner.wait_until(condition, args)
56+
57+
def when_do(condition, do, args=None):
58+
Runner.when_do(condition, do, args)
59+
60+
def while_do(condition, do, args=None):
61+
Runner.while_do(condition, do, args)
62+
63+
def parallel(*functions):
64+
Runner.parallel(functions)
65+
66+
def _handle_signal(signal, frame):
67+
Runner.shutdown()
68+
raise SystemExit
69+
70+
signal.signal(signal.SIGINT, _handle_signal)

neobot/connector copy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Part of the ROBOID project - https://roboticsware.uz
2+
# Copyright (C) 2022 RoboticsWare ([email protected])
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General
15+
# Public License along with this library; if not, write to the
16+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17+
# Boston, MA 02111-1307 USA
18+
19+
State = type("Enum", (), {"CONNECTING": 1, "CONNECTED": 2, "CONNECTION_LOST": 3, "DISCONNECTED": 4, "DISPOSED": 5})
20+
Result = type("Enum", (), {"FOUND": 1, "NOT_CONNECTED": 2, "NOT_AVAILABLE": 3})

neobot/connector.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Part of the RoboticsWare project - https://roboticsware.uz
2+
# Copyright (C) 2022 RoboticsWare ([email protected])
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General
15+
# Public License along with this library; if not, write to the
16+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17+
# Boston, MA 02111-1307 USA
18+
19+
State = type("Enum", (), {"CONNECTING": 1, "CONNECTED": 2, "CONNECTION_LOST": 3, "DISCONNECTED": 4, "DISPOSED": 5})
20+
Result = type("Enum", (), {"FOUND": 1, "NOT_CONNECTED": 2, "NOT_AVAILABLE": 3})

neobot/keyboard.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Part of the ROBOID project - https://roboticsware.uz
2+
# Copyright (C) 2022 RoboticsWare ([email protected])
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2.1 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General
15+
# Public License along with this library; if not, write to the
16+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17+
# Boston, MA 02111-1307 USA
18+
19+
import os
20+
21+
22+
if os.name == "nt": # sys.platform == "win32":
23+
import msvcrt
24+
25+
class Keyboard(object):
26+
BACKSPACE = 8
27+
TAB = 9
28+
ENTER = 13
29+
ESC = 27
30+
F1 = 59
31+
F2 = 60
32+
F3 = 61
33+
F4 = 62
34+
F5 = 63
35+
F6 = 64
36+
F7 = 65
37+
F8 = 66
38+
F9 = 67
39+
F10 = 68
40+
F11 = 133
41+
F12 = 134
42+
43+
HOME = 71
44+
UP = 72
45+
PAGE_UP = 73
46+
LEFT = 75
47+
RIGHT = 77
48+
END = 79
49+
DOWN = 80
50+
PAGE_DOWN = 81
51+
INSERT = 82
52+
DELETE = 83
53+
54+
_special_keys = (BACKSPACE, TAB, ENTER, ESC)
55+
_function_numpads = (F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, HOME, UP, PAGE_UP, LEFT, RIGHT, END, DOWN, PAGE_DOWN, INSERT, DELETE)
56+
57+
@staticmethod
58+
def read():
59+
if msvcrt.kbhit():
60+
key = msvcrt.getch()
61+
code = ord(key)
62+
if code == 224: # special key (F11, F12, HOME, UP, PAGE_UP, LEFT, RIGHT, END, DOWN, PAGE_DOWN, INSERT, DELETE)
63+
return ord(msvcrt.getch())
64+
elif code == 0: # function key (F1 - F10) or num pad
65+
code = ord(msvcrt.getch())
66+
if code in Keyboard._function_numpads:
67+
return code
68+
elif code in Keyboard._special_keys:
69+
return code
70+
else:
71+
return key.decode("utf-8")
72+
else:
73+
import sys
74+
import termios
75+
from contextlib import contextmanager
76+
77+
class Keyboard(object):
78+
BACKSPACE = 127
79+
TAB = 9
80+
ENTER = 10
81+
F1 = 80 # 27 79 80
82+
F2 = 81 # 27 79 81
83+
F3 = 82 # 27 79 82
84+
F4 = 83 # 27 79 83
85+
F5 = 53 # 27 91 49 53 126
86+
F6 = 55 # 27 91 49 55 126
87+
F7 = 56 # 27 91 49 56 126
88+
F8 = 57 # 27 91 49 57 126
89+
F9 = 48 # 27 91 50 48 126
90+
F10 = 49 # 27 91 50 49 126
91+
F11 = 51
92+
F12 = 52 # 27 91 50 52 126
93+
94+
HOME = 72 # 27 91 72
95+
UP = 65 # 27 91 65
96+
PAGE_UP = 153 # 27 91 53 126
97+
LEFT = 68 # 27 91 68
98+
RIGHT = 67 # 27 91 67
99+
END = 70 # 27 91 70
100+
DOWN = 66 # 27 91 66
101+
PAGE_DOWN = 154 # 27 91 54 126
102+
INSERT = 150 # 27 91 50 126
103+
DELETE = 151 # 27 91 51 126
104+
105+
_special_keys = (BACKSPACE, TAB, ENTER)
106+
107+
@staticmethod
108+
@contextmanager
109+
def _mode(file):
110+
old_attrs = termios.tcgetattr(file.fileno())
111+
new_attrs = old_attrs[:]
112+
new_attrs[3] = new_attrs[3] & ~(termios.ECHO | termios.ICANON)
113+
try:
114+
termios.tcsetattr(file.fileno(), termios.TCSADRAIN, new_attrs)
115+
yield
116+
finally:
117+
termios.tcsetattr(file.fileno(), termios.TCSADRAIN, old_attrs)
118+
119+
@staticmethod
120+
def read():
121+
with Keyboard._mode(sys.stdin):
122+
key = sys.stdin.read(1)
123+
code = ord(key)
124+
if code == 27: # special key
125+
code = ord(sys.stdin.read(1))
126+
if code == 79:
127+
return ord(sys.stdin.read(1))
128+
elif code == 91:
129+
code = ord(sys.stdin.read(1))
130+
if code >= 65:
131+
return code
132+
else:
133+
code2 = ord(sys.stdin.read(1))
134+
if code2 == 126:
135+
return code + 100
136+
else:
137+
sys.stdin.read(1) # 126
138+
return code2
139+
else:
140+
return code
141+
elif code in Keyboard._special_keys:
142+
return code
143+
else:
144+
return key

0 commit comments

Comments
 (0)