From 631ea6e8a8497fcb53c55f20cdf5c94ceab23812 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 17 Apr 2024 07:15:05 +0200 Subject: [PATCH] feat: Add counter reset function to the MIO module Due to the new firmware 1.1 on the MIO module, the GPIOs that were configured as counters can now also be reset to 0. With this change, the .reset() function in RevPiModIO is added to the respective counter IOs. --- src/revpimodio2/device.py | 24 ++++++++++++++++++++++-- src/revpimodio2/modio.py | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/revpimodio2/device.py b/src/revpimodio2/device.py index 92ce3b6..a2b502f 100644 --- a/src/revpimodio2/device.py +++ b/src/revpimodio2/device.py @@ -345,8 +345,10 @@ class Device(object): elif bool(dict_io[key][7]): # Bei Bitwerten IOBase verwenden io_new = IOBase(self, dict_io[key], iotype, "little", False) - elif isinstance(self, DioModule) and dict_io[key][3] in self._lst_counter: - # Counter IO auf einem DI oder DIO + elif (isinstance(self, DioModule) or isinstance(self, MioModule)) and dict_io[key][ + 3 + ] in self._lst_counter: + # Counter IO on a DI, DIO or MIO module io_new = IntIOCounter( self._lst_counter.index(dict_io[key][3]), self, @@ -1978,6 +1980,24 @@ class DioModule(Device): super().__init__(parentmodio, dict_device, simulator=simulator) +class MioModule(Device): + """Represents a MIO module.""" + + __slots__ = "_lst_counter" + + def __init__(self, parentmodio, dict_device, simulator=False): + """ + Extended device class to recognize IntIOCounter. + + :rev: :func:`Device.__init__()` + """ + # String list of byte addresses that are a counter. + self._lst_counter = list(map(str, range(9, 17, 2))) + + # Basisklasse laden + super().__init__(parentmodio, dict_device, simulator=simulator) + + class RoModule(Device): """Relais output (RO) module with""" diff --git a/src/revpimodio2/modio.py b/src/revpimodio2/modio.py index b6828de..94e1f3a 100644 --- a/src/revpimodio2/modio.py +++ b/src/revpimodio2/modio.py @@ -392,6 +392,9 @@ class RevPiModIO(object): elif pt == ProductType.RO: # RO dev_new = devicemodule.RoModule(self, device, simulator=self._simulator) + elif pt == ProductType.MIO: + # MIO + dev_new = devicemodule.MioModule(self, device, simulator=self._simulator) else: # Alle anderen IO-Devices dev_new = devicemodule.Device(self, device, simulator=self._simulator)