Skip to content

Commit 8379138

Browse files
LisaLisa
authored andcommitted
Uart bug fixes
1 parent 7be16ae commit 8379138

4 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
__email__ = "[email protected]"
2323
__status__ = "Beta"
2424
__logname__ = "uPyEasy"
25-
__build__ = "65"
25+
__build__ = "7be16ae8462bb326f9b6d1bcc07357d538124218"
2626

2727
upyeasy_starttime = 0
2828
initial_upyeasyname = "uPyEasy"

src/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class configTable(uorm.Model):
3232
("sleepenable", ""),
3333
("sleeptime", 60),
3434
("sleepfailure", ""),
35-
("version", int(core.__build__)),
35+
("version", core.__build__),
3636
])
3737

3838
@classmethod

src/hal.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ def initdevice(self, device):
124124
db.deviceTable.update({"timestamp":device['timestamp']},enable="off")
125125
except Exception as e:
126126
self._log.error("Plugins: Init device: "+device['name']+" with plugin: "+str(device['pluginid'])+" failed, exception: "+repr(e))
127-
128-
_initcomplete = True
127+
else:
128+
_initcomplete = True
129129

130130
if not _initcomplete:
131131
self._log.debug("Plugins: Init device {} failed!".format(device['name']))
132+
# device init failed, disable!
133+
db.deviceTable.update({"timestamp":device['timestamp']},enable="off")
132134

133135
def loadform(self, plugindata):
134136
self._log.debug("Plugins: Loadform plugin "+plugindata['name'])

0 commit comments

Comments
 (0)