notify only on change

This commit is contained in:
Devaev Maxim 2020-09-14 21:51:53 +03:00
parent 50d0612f82
commit 6ef53e48c5

View File

@ -102,12 +102,16 @@ class AioPinsReader: # pylint: disable=too-many-instance-attributes
while not self.__stop_event.is_set(): while not self.__stop_event.is_set():
ev_lines = lines.event_wait(1) ev_lines = lines.event_wait(1)
if ev_lines: if ev_lines:
changed = False
for ev_line in ev_lines: for ev_line in ev_lines:
events = ev_line.event_read_multiply() events = ev_line.event_read_multiply()
if events: if events:
(pin, value) = self.__parse_event(events[-1]) (pin, value) = self.__parse_event(events[-1])
self.__state[pin] = value if self.__state[pin] != value:
self.__notify() self.__state[pin] = value
changed = True
if changed:
self.__notify()
def __parse_event(self, event: gpiod.LineEvent) -> Tuple[int, bool]: def __parse_event(self, event: gpiod.LineEvent) -> Tuple[int, bool]:
pin = event.source.offset() pin = event.source.offset()