27
27
# class to manage publish and subscribe
28
28
# COULD BE CHANGED AFTERWARDS
29
29
class NodeHandle (object ):
30
- def __init__ (self , serial_id , baudrate ):
30
+ def __init__ (self , serial_id = 2 , baudrate = 115200 , ** kwargs ):
31
31
32
32
"""
33
33
id: used for topics id (negotiation)
@@ -41,8 +41,23 @@ def __init__(self, serial_id, baudrate):
41
41
self .subscribing_topics = dict ()
42
42
self .serial_id = serial_id
43
43
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 )
46
61
47
62
if sys .platform == "esp32" :
48
63
threading .start_new_thread (self ._listen , ())
0 commit comments