Prepared switch bank control
This commit is contained in:
47
boatdata.py
47
boatdata.py
@@ -342,6 +342,45 @@ class BoatValueText(BoatValue):
|
||||
if self.value and self.valid:
|
||||
return self.value
|
||||
|
||||
class SwitchBank():
|
||||
"""
|
||||
Es können Instanzen von 0 bis 252 verwendet werden.
|
||||
Jede Bank hat 28 Schalter mit den Zuständen On(1), Off(0) und Undef(3)
|
||||
TODO Erweiterung: Typ eines Switches: Schalter oder Taster
|
||||
Die Callback-Funktion erwartet zwei Parameter: Index und Wert
|
||||
"""
|
||||
def __init__(self, instance=0):
|
||||
self.instance = instance
|
||||
self.shortname = f"bank #{instance}"
|
||||
self.switch = [0] * 28
|
||||
self.callback = [None] * 28
|
||||
|
||||
def clear(self, value=0):
|
||||
self.switch[:] = [value] * 28
|
||||
self.callback[:] = [None] * 28
|
||||
|
||||
def setSwitchOn(self, index):
|
||||
if index < 1 or index > 28:
|
||||
raise IndexError("Switch index out of range")
|
||||
self.switch[index-1] = 1
|
||||
if self.callback[index-1]:
|
||||
self.callback[index-1](index, 1)
|
||||
|
||||
def setSwitchOff(self, index):
|
||||
if index < 1 or index > 28:
|
||||
raise IndexError("Switch index out of range")
|
||||
self.switch[index-1] = 0
|
||||
if self.callback[index-1]:
|
||||
self.callback[index-1](index, 0)
|
||||
|
||||
def setName(self, newname):
|
||||
self.shortname = newname
|
||||
|
||||
def setCallback(self, index, cb_function):
|
||||
if index < 1 or index > 28:
|
||||
raise IndexError("Switch index out of range")
|
||||
self.callback[index] = cb_function
|
||||
|
||||
class Tank():
|
||||
"""
|
||||
Die Instanz beziegt sich auf den Typ. So kann die Instanz 0
|
||||
@@ -503,6 +542,9 @@ class BoatData():
|
||||
# Tanks
|
||||
self.tank = {}
|
||||
|
||||
# Switch banks
|
||||
self.switchbank = {}
|
||||
|
||||
# Mehrere getrennte Batteriekreise
|
||||
# - Starter
|
||||
# - Verbrauchen
|
||||
@@ -561,6 +603,11 @@ class BoatData():
|
||||
'YAW': self.yaw
|
||||
}
|
||||
|
||||
def addSwitchBank(self, instance):
|
||||
if instance < 0 or instance > 252:
|
||||
raise IndexError("Instance number out of range")
|
||||
self.switchbank[instance] = SwitchBank(instance)
|
||||
|
||||
def addTank(self, instance):
|
||||
self.tank[instance] = Tank(instance)
|
||||
|
||||
|
||||
30
parser.py
30
parser.py
@@ -155,9 +155,9 @@ def parse_127257(buf, boatdata):
|
||||
boatdata.setValue("ROLL", roll)
|
||||
|
||||
def parse_127501(buf):
|
||||
# Switch control status
|
||||
# Switch bank control status
|
||||
# 7 byte for switches every switch takes 2 bits
|
||||
# 0 = Off, 1=On, 2 and 3 unknown
|
||||
# 0 = Off, 1=On, 2=reserved and 3=no action
|
||||
instance = buf[0]
|
||||
switch = [0] * 28
|
||||
ix = 0
|
||||
@@ -169,18 +169,24 @@ def parse_127501(buf):
|
||||
ix += 1
|
||||
|
||||
def parse_127502(buf):
|
||||
# Switch control
|
||||
# Switch bank control
|
||||
# 7 byte for switches every switch takes 2 bits
|
||||
# 0 = Off, 1=On, 2 and 3 unknown
|
||||
# 0 = Off, 1=On, 2=reserved and 3=no action
|
||||
instance = buf[0]
|
||||
switch = [0] * 28
|
||||
ix = 0
|
||||
for b in range(1, 8):
|
||||
val = buf[b]
|
||||
for x in range(4):
|
||||
switch[ix] = val & 0x03
|
||||
val = val >> 2
|
||||
ix += 1
|
||||
if instance in boatdata.switchbank:
|
||||
ix = 1
|
||||
for b in range(1, 8):
|
||||
val = buf[b]
|
||||
for x in range(4):
|
||||
switch = val & 0x03
|
||||
if switch == 1:
|
||||
boatdata.switchbank[instance].setSwitchOn(ix)
|
||||
elif switch == 0:
|
||||
boatdata.switchbank[instance].setSwitchOff(ix)
|
||||
val = val >> 2
|
||||
ix += 1
|
||||
else:
|
||||
print(f"Switchbank {instance} not defined")
|
||||
|
||||
def parse_127505(buf, boatdata):
|
||||
# Fluid Level
|
||||
|
||||
Reference in New Issue
Block a user