mirror of https://github.com/Desuuuu/klipper.git
console: Add support for connecting via CAN bus
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a20f4a8759
commit
babde17c4c
|
@ -30,9 +30,11 @@ help_txt = """
|
|||
re_eval = re.compile(r'\{(?P<eval>[^}]*)\}')
|
||||
|
||||
class KeyboardReader:
|
||||
def __init__(self, reactor, serialport, baud):
|
||||
def __init__(self, reactor, serialport, baud, canbus_iface, canbus_nodeid):
|
||||
self.serialport = serialport
|
||||
self.baud = baud
|
||||
self.canbus_iface = canbus_iface
|
||||
self.canbus_nodeid = canbus_nodeid
|
||||
self.ser = serialhdl.SerialReader(reactor)
|
||||
self.reactor = reactor
|
||||
self.start_time = reactor.monotonic()
|
||||
|
@ -54,7 +56,10 @@ class KeyboardReader:
|
|||
def connect(self, eventtime):
|
||||
self.output(help_txt)
|
||||
self.output("="*20 + " attempting to connect " + "="*20)
|
||||
if self.baud:
|
||||
if self.canbus_iface is not None:
|
||||
self.ser.connect_canbus(self.serialport, self.canbus_nodeid,
|
||||
self.canbus_iface)
|
||||
elif self.baud:
|
||||
self.ser.connect_uart(self.serialport, self.baud)
|
||||
else:
|
||||
self.ser.connect_pipe(self.serialport)
|
||||
|
@ -207,6 +212,10 @@ def main():
|
|||
opts.add_option("-v", action="store_true", dest="verbose",
|
||||
help="enable debug messages")
|
||||
opts.add_option("-b", "--baud", type="int", dest="baud", help="baud rate")
|
||||
opts.add_option("-c", "--canbus_iface", dest="canbus_iface",
|
||||
help="Use CAN bus interface; serialdevice is the chip UUID")
|
||||
opts.add_option("-i", "--canbus_nodeid", type="int", dest="canbus_nodeid",
|
||||
default=64, help="The CAN nodeid to use (default 64)")
|
||||
options, args = opts.parse_args()
|
||||
if len(args) != 1:
|
||||
opts.error("Incorrect number of arguments")
|
||||
|
@ -223,7 +232,8 @@ def main():
|
|||
logging.basicConfig(level=debuglevel)
|
||||
|
||||
r = reactor.Reactor()
|
||||
kbd = KeyboardReader(r, serialport, baud)
|
||||
kbd = KeyboardReader(r, serialport, baud, options.canbus_iface,
|
||||
options.canbus_nodeid)
|
||||
try:
|
||||
r.run()
|
||||
except KeyboardInterrupt:
|
||||
|
|
Loading…
Reference in New Issue