-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·78 lines (62 loc) · 2.68 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
#!/usr/bin/env python3
""" Control computerised machine tools using G-Code programming language.
https://en.wikipedia.org/wiki/G-code
Uses plugins for different hardware controller types. (Eg, Grbl, etc.)
Uses plugins for different operating modes. (Eg. Jog, run GCode file, etc.)
"""
from typing import List, Type
import argparse
import core.common
from core.coordinator import Coordinator
from terminals._terminal_base import _TerminalBase
from controllers._controller_base import _ControllerBase
from interfaces._interface_base import _InterfaceBase
def main() -> None:
""" Main program loop. """
# Component plugin classes.
class_terminals = core.common.load_plugins("terminals")
class_controllers = core.common.load_plugins("controllers")
class_interfaces = core.common.load_plugins("interfaces")
# Component plugin instances.
terminals: List[_TerminalBase] = \
[]
controllers: List[Type[_ControllerBase]] = \
[controller for active, controller in class_controllers if active]
# Instantiate the interfaces here.
interfaces: List[_InterfaceBase] = \
[interface() for active, interface in class_interfaces if active]
# Command line arguments.
parser = argparse.ArgumentParser(description="A UI for CNC machines.")
parser.add_argument("-debug_show_events",
action="store_true",
help="Display events.")
for active_by_default, terminal in class_terminals:
if active_by_default:
parser.add_argument("-no_%s" % terminal.get_classname(),
dest=terminal.get_classname(),
action="store_false",
help="terminal.description")
else:
parser.add_argument("-%s" % terminal.get_classname(),
dest=terminal.get_classname(),
action="store_true",
help="terminal.description")
args = parser.parse_args()
print(args)
# Instantiate terminals according to command line flags.
for _, terminal in class_terminals:
if getattr(args, terminal.get_classname()):
terminal_instance = terminal()
terminal_instance.debug_show_events = args.debug_show_events
terminals.append(terminal_instance)
# Populate and start the coordinator.
coordinator = Coordinator(terminals, interfaces, controllers, args.debug_show_events)
# Main program loop.
while True:
if not coordinator.update_components():
break
# Cleanup and exit.
coordinator.close()
print("done")
if __name__ == "__main__":
main()