-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
128 lines (96 loc) · 3.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# ===============================================================================
# Copyright 2020 ross
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
import logging
import curses
from ams.sender import Sender
from ams.bot import Bot
#from ams.mosaic import Mosaic
#from ams.camera import Camera
def setup_logging():
logger = logging.getLogger('ams')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('ams.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
def terminal(s):
while 1:
cmd = input('>>')
cmd = f'G0 X{cmd}'
s.send(cmd)
def joystick(sender):
sender.send('G91')
def key_up():
return 'G0 Y10'
def key_down():
return 'G0 Y-10'
def key_left():
return 'G0 X-10'
def key_right():
return 'G0 X10'
def page_up():
return 'G0 Z1'
def page_down():
return 'G0 Z-1'
def closure(std):
std.clear()
std.keypad(True)
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
funcs = {curses.KEY_UP: key_up,
curses.KEY_DOWN: key_down,
curses.KEY_LEFT: key_left,
curses.KEY_RIGHT: key_right,
curses.KEY_PPAGE: page_up,
curses.KEY_NPAGE: page_down
}
while 1:
ch = std.getch()
func = funcs.get(ch)
if func:
cmd = func()
std.clear()
std.addstr(cmd, curses.color_pair(1))
std.refresh()
if sender:
sender.send(cmd)
return closure
def main():
setup_logging()
s = Sender()
bot = Bot(s)
addr = '/dev/tty.usbmodem1451101'
addr = '/dev/ttyACM0'
if s.open(addr):
s.wakeup()
bot.home()
bot.home()
#c = Camera()
#m = Mosaic(c, bot)
#m.run()
curses.wrapper(joystick(s))
# terminal(s)
if __name__ == '__main__':
main()
# ============= EOF =============================================