mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 15:13:52 +01:00
Call functions with watchdogs.py.
Call psstop after "reset driver"
This commit is contained in:
@@ -791,6 +791,7 @@ class RevPiPyLoad():
|
||||
|
||||
# Watchdog to detect the reset_driver event
|
||||
pictory_reset_driver = ResetDriverWatchdog()
|
||||
pictory_reset_driver.register_call(self.xml_psstop)
|
||||
|
||||
# mainloop
|
||||
while not self._exit:
|
||||
@@ -1369,6 +1370,7 @@ class RevPiPyLoad():
|
||||
@return True, wenn stop erfolgreich"""
|
||||
if self.xml_ps is not None:
|
||||
self.xml_ps.stop()
|
||||
self.xml_ps.loadrevpimodio()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -178,6 +178,7 @@ class ResetDriverWatchdog(Thread):
|
||||
def __init__(self):
|
||||
super(ResetDriverWatchdog, self).__init__()
|
||||
self.daemon = True
|
||||
self._calls = []
|
||||
self._exit = False
|
||||
self._fh = None
|
||||
self.not_implemented = False
|
||||
@@ -213,6 +214,8 @@ class ResetDriverWatchdog(Thread):
|
||||
if rc == 0 and byte_buff[0] == 1:
|
||||
self._triggered = True
|
||||
pi.logger.debug("piCtory reset_driver detected")
|
||||
for func in self._calls:
|
||||
func()
|
||||
except Exception:
|
||||
self.not_implemented = True
|
||||
os.close(self._fh)
|
||||
@@ -222,6 +225,13 @@ class ResetDriverWatchdog(Thread):
|
||||
|
||||
pi.logger.debug("leave ResetDriverWatchdog.run()")
|
||||
|
||||
def register_call(self, function):
|
||||
"""Register a function, if watchdog triggers."""
|
||||
if not callable(function):
|
||||
return ValueError("Function is not callable.")
|
||||
if function not in self._calls:
|
||||
self._calls.append(function)
|
||||
|
||||
def stop(self):
|
||||
"""Stop watchdog for piCtory reset_driver."""
|
||||
pi.logger.debug("enter ResetDriverWatchdog.stop()")
|
||||
@@ -233,6 +243,13 @@ class ResetDriverWatchdog(Thread):
|
||||
|
||||
pi.logger.debug("leave ResetDriverWatchdog.stop()")
|
||||
|
||||
def unregister_call(self, function=None):
|
||||
"""Remove a function call on watchdog trigger."""
|
||||
if function is None:
|
||||
self._calls.clear()
|
||||
elif function in self._calls:
|
||||
self._calls.remove(function)
|
||||
|
||||
@property
|
||||
def triggered(self):
|
||||
"""Will return True one time after watchdog was triggered."""
|
||||
|
||||
Reference in New Issue
Block a user