2727# class to manage publish and subscribe
2828# COULD BE CHANGED AFTERWARDS
2929class NodeHandle (object ):
30- def __init__ (self , serial_id , baudrate ):
30+ def __init__ (self , serial_id = 2 , baudrate = 115200 , ** kwargs ):
3131
3232 """
3333 id: used for topics id (negotiation)
@@ -41,8 +41,23 @@ def __init__(self, serial_id, baudrate):
4141 self .subscribing_topics = dict ()
4242 self .serial_id = serial_id
4343 self .baudrate = baudrate
44- self .uart = m .UART (self .serial_id , self .baudrate )
45- self .uart .init (self .baudrate , bits = 8 , parity = None , stop = 1 , txbuf = 0 )
44+
45+ if "serial" in kwargs :
46+ self .uart = kwargs .get ("serial" )
47+ elif "tx" in kwargs and "rx" in kwargs :
48+ self .uart = m .UART (self .serial_id , self .baudrate )
49+ self .uart .init (
50+ self .baudrate ,
51+ tx = kwargs .get ("tx" ),
52+ rx = kwargs .get ("rx" ),
53+ bits = 8 ,
54+ parity = None ,
55+ stop = 1 ,
56+ txbuf = 0 ,
57+ )
58+ else :
59+ self .uart = m .UART (self .serial_id , self .baudrate )
60+ self .uart .init (self .baudrate , bits = 8 , parity = None , stop = 1 , txbuf = 0 )
4661
4762 if sys .platform == "esp32" :
4863 threading .start_new_thread (self ._listen , ())
0 commit comments