@@ -779,9 +779,6 @@ def wifiscan(self):
779779 def hardwaredb_init (self ):
780780 self ._log .debug ("Hal: hardwaredb init" )
781781
782- #connect to database
783- _dbc .connect ()
784-
785782 if self ._utils .get_platform () == 'linux' :
786783 self ._log .debug ("Hal: hardwaredb linux" )
787784 # create hardwareTable
@@ -804,12 +801,9 @@ def hardwaredb_init(self):
804801 db .hardwareTable .create (boardled1 = "" )
805802 else :
806803 self ._log .error ("Hal: hardwaredb failure" )
807-
808- _dbc .close ()
809-
810804
811805 def pin (self , vpin , mode = None , pull = None ):
812- self ._log .debug ("Hal: pin = " + vpin )
806+ self ._log .debug ("Hal: pin = {}" . format ( vpin ) )
813807
814808 from machine import Pin
815809
@@ -882,13 +876,26 @@ def pin(self, vpin, mode = None, pull = None):
882876 self ._log .error ("Hal: pin failure" )
883877
884878 return pin
879+
880+ def vpin2pin (self , vpin ):
881+ self ._log .debug ("Hal: vpin2pin = {}" .format (vpin ))
882+
883+ # check if id is present
884+ if not vpin :
885+ self ._log .error ("Hal: vpin = None!" )
886+ return None
887+
888+ # get dx map
889+ dxmap = db .dxmapTable .getrow ()
890+
891+ # received virtual pin, transforming to actual pin
892+ pin = dxmap [vpin ].split (';' )[0 ]
893+
894+ return pin
885895
886896 def dxmaps_init (self ):
887897 self ._log .debug ("Hal: dxmaps_init" )
888898
889- #connect to database
890- _dbc .connect ()
891-
892899 if self ._utils .get_platform () == 'linux' :
893900 self ._log .debug ("Hal: dxmaps_init linux" )
894901 # Create pin mapping
@@ -910,8 +917,6 @@ def dxmaps_init(self):
910917 db .dxmapTable .create (count = 12 ,d0 = "0;GPIO0" ,d1 = "1;GPIO1" ,d2 = "2;GPIO2" ,d3 = "3;GPIO3" ,d4 = "4;GPIO4" ,d5 = "5;GPIO5" ,d6 = "9;GPIO9" ,d7 = "10;GPIO10" ,d8 = "12;GPIO12" ,d9 = "13;GPIO13" ,d10 = "14;GPIO14" ,d11 = "15;GPIO15" )
911918 else :
912919 self ._log .error ("Hal: dxmaps_init failure" )
913-
914- _dbc .close ()
915920
916921 def board (self ):
917922 self ._log .debug ("Hal: board info" )
@@ -1015,7 +1020,7 @@ def get_i2c(self, id=1):
10151020
10161021 # Create new or reuse existing
10171022 if id not in self ._i2c .keys ():
1018- self ._log .debug ("Hal: get i2c esp32, create i2c object with id: " + str (id ))
1023+ self ._log .debug ("Hal: get i2c esp32, create i2c object with id: {}, sda={}, scl={} " . format (id , hardware [ "sda" ], hardware [ "scl" ] ))
10191024 try :
10201025 self ._i2c [id ] = I2C (sda = self .pin (hardware ["sda" ]), scl = self .pin (hardware ["scl" ]))
10211026 except ValueError :
@@ -1155,9 +1160,11 @@ def get_uart(self, id=1):
11551160
11561161 # Create new or reuse existing
11571162 if id not in self ._uart .keys ():
1158- self ._log .debug ("Hal: get uart esp32, create uart object with id: " + str (id ))
1163+ txpin = int (self .vpin2pin (hardware ["tx" ]))
1164+ rxpin = int (self .vpin2pin (hardware ["rx" ]))
1165+ self ._log .debug ("Hal: get uart esp32, create uart object with id: {}, tx={}, rx={}" .format (id ,txpin ,rxpin ))
11591166 try :
1160- self ._uart [id ] = UART (id , tx = int ( hardware [ "tx" ][ 1 :]) , rx = int ( hardware [ "rx" ][ 1 :]) )
1167+ self ._uart [id ] = UART (id , tx = txpin , rx = rxpin )
11611168 except ValueError :
11621169 self ._log .error ("Hal: get uart esp32, exception valueerror" )
11631170 return None
0 commit comments