Prepared switch bank control

This commit is contained in:
2025-12-28 09:26:22 +01:00
parent 1c78f24505
commit d6ce21ff03
2 changed files with 65 additions and 12 deletions

View File

@@ -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)