2022-04-29 02:57:47 +01:00
|
|
|
from functools import partial
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-06-16 16:10:06 +01:00
|
|
|
from .util import cache_bool, cache_string
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def channel_bool_prop(param):
|
2022-06-16 16:10:06 +01:00
|
|
|
"""meta function for channel boolean parameters"""
|
2022-04-29 02:57:47 +01:00
|
|
|
|
|
|
|
@partial(cache_bool, param=param)
|
2022-03-20 12:25:50 +00:00
|
|
|
def fget(self):
|
2023-10-21 18:02:55 +01:00
|
|
|
cmd = self._cmd(param)
|
|
|
|
self.logger.debug(f"getter: {cmd}")
|
2022-04-29 02:57:47 +01:00
|
|
|
return (
|
|
|
|
not int.from_bytes(
|
2022-06-16 16:10:06 +01:00
|
|
|
getattr(
|
|
|
|
self.public_packet,
|
|
|
|
f"{'strip' if 'strip' in type(self).__name__.lower() else 'bus'}state",
|
|
|
|
)[self.index],
|
2022-04-29 02:57:47 +01:00
|
|
|
"little",
|
2022-03-26 23:00:09 +00:00
|
|
|
)
|
2023-06-25 02:38:59 +01:00
|
|
|
& getattr(self._modes, f"_{param.lower()}")
|
2022-04-29 02:57:47 +01:00
|
|
|
== 0
|
|
|
|
)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fset(self, val):
|
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def channel_label_prop():
|
2022-06-16 16:10:06 +01:00
|
|
|
"""meta function for channel label parameters"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
@partial(cache_string, param="label")
|
|
|
|
def fget(self) -> str:
|
2022-06-16 16:10:06 +01:00
|
|
|
return getattr(
|
|
|
|
self.public_packet,
|
|
|
|
f"{'strip' if 'strip' in type(self).__name__.lower() else 'bus'}labels",
|
|
|
|
)[self.index]
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
def fset(self, val: str):
|
2022-07-04 16:06:04 +01:00
|
|
|
self.setter("label", str(val))
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def strip_output_prop(param):
|
2022-06-16 16:10:06 +01:00
|
|
|
"""meta function for strip output parameters. (A1-A5, B1-B3)"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
@partial(cache_bool, param=param)
|
2022-03-04 14:22:29 +00:00
|
|
|
def fget(self):
|
2023-10-21 18:02:55 +01:00
|
|
|
cmd = self._cmd(param)
|
|
|
|
self.logger.debug(f"getter: {cmd}")
|
2022-04-29 02:57:47 +01:00
|
|
|
return (
|
|
|
|
not int.from_bytes(self.public_packet.stripstate[self.index], "little")
|
|
|
|
& getattr(self._modes, f"_bus{param.lower()}")
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def fset(self, val):
|
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
return property(fget, fset)
|
2022-03-17 14:08:49 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def bus_mode_prop(param):
|
2022-06-16 16:10:06 +01:00
|
|
|
"""meta function for bus mode parameters"""
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-05-04 18:33:04 +01:00
|
|
|
@partial(cache_bool, param=param)
|
2022-03-17 14:08:49 +00:00
|
|
|
def fget(self):
|
2023-10-21 18:02:55 +01:00
|
|
|
cmd = self._cmd(param)
|
|
|
|
self.logger.debug(f"getter: {cmd}")
|
2024-07-05 17:43:28 +01:00
|
|
|
return [
|
|
|
|
(int.from_bytes(self.public_packet.busstate[self.index], "little") & val)
|
|
|
|
>> 4
|
2022-04-29 02:57:47 +01:00
|
|
|
for val in self._modes.modevals
|
2024-07-05 17:43:28 +01:00
|
|
|
] == self.modestates[param]
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def fset(self, val):
|
2022-05-04 18:33:04 +01:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
return property(fget, fset)
|
2022-03-21 11:20:53 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2023-06-25 02:38:59 +01:00
|
|
|
def action_fn(param, val=1):
|
|
|
|
"""A function that performs an action"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
def fdo(self):
|
|
|
|
self.setter(param, val)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
return fdo
|