optional gpio initial

This commit is contained in:
Devaev Maxim 2020-09-07 14:42:29 +03:00
parent c2831853a0
commit 1353ca2e97
2 changed files with 9 additions and 8 deletions

View File

@ -200,7 +200,7 @@ def _patch_dynamic( # pylint: disable=too-many-locals
if mode == "output": if mode == "output":
ch_scheme.update({ ch_scheme.update({
"busy_delay": Option(0.2, type=valid_float_f01), "busy_delay": Option(0.2, type=valid_float_f01),
"initial": Option(False, type=valid_bool), "initial": Option(False, type=(lambda arg: (None if arg is None else valid_bool(arg)))),
"switch": Option(True, type=valid_bool), "switch": Option(True, type=valid_bool),
"pulse": { "pulse": {
"delay": Option(0.1, type=valid_float_f0), "delay": Option(0.1, type=valid_float_f0),

View File

@ -112,7 +112,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
self.__channel = channel self.__channel = channel
self.__pin: int = config.pin self.__pin: int = config.pin
self.__inverted: bool = config.inverted self.__inverted: bool = config.inverted
self.__initial: bool = config.initial self.__initial: Optional[bool] = config.initial
self.__switch: bool = config.switch self.__switch: bool = config.switch
@ -123,7 +123,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
self.__busy_delay: float = config.busy_delay self.__busy_delay: float = config.busy_delay
self.__driver = driver self.__driver = driver
self.__driver.register_output(self.__pin, (config.initial ^ config.inverted)) self.__driver.register_output(self.__pin, (None if config.initial is None else (config.initial ^ config.inverted)))
self.__region = aiotools.AioExclusiveRegion(GpioChannelIsBusyError, notifier) self.__region = aiotools.AioExclusiveRegion(GpioChannelIsBusyError, notifier)
@ -156,6 +156,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
} }
def cleanup(self) -> None: def cleanup(self) -> None:
if self.__initial is not None:
try: try:
self.__driver.write(self.__pin, (self.__initial ^ self.__inverted)) self.__driver.write(self.__pin, (self.__initial ^ self.__inverted))
except Exception: except Exception: