GHIElectronics.Endpoint.Devices.Watchdog 0.5.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ """The watchdog of Endpoint, with the same API as TinyCLR (and the .NET
2
+ GHIElectronics.Endpoint.Devices.Watchdog):
3
+
4
+ from datetime import timedelta
5
+ from GHIElectronics.Endpoint.Core import EPM815
6
+ from GHIElectronics.Endpoint.Devices.Watchdog import WatchdogController
7
+
8
+ watchdog = WatchdogController.FromName(EPM815.Watchdog.Id)
9
+ watchdog.Enable(timedelta(seconds=10))
10
+ while True:
11
+ do_work()
12
+ watchdog.Reset()
13
+
14
+ The chip's watchdog cannot be stopped once it runs: Disable hands it to the
15
+ system, which then keeps it fed. If the program ends or crashes without
16
+ Disable, the board restarts after the timeout, also when debugging stops.
17
+ """
18
+
19
+ import datetime
20
+
21
+ from GHIElectronics.Endpoint.Core._errors import ArgumentException
22
+ from GHIElectronics.Endpoint.Core._native import native
23
+
24
+ __all__ = ["WatchdogController"]
25
+
26
+ _ID = "EPM815.Watchdog"
27
+
28
+
29
+ class WatchdogController:
30
+ def __init__(self):
31
+ handle = native.out_handle()
32
+ native.watchdog_create(native.ref(handle))
33
+ self._handle = handle
34
+
35
+ @staticmethod
36
+ def GetDefault():
37
+ return WatchdogController()
38
+
39
+ @staticmethod
40
+ def FromName(name):
41
+ if name != _ID:
42
+ raise ArgumentException(f'There is no watchdog named "{name}": use EPM815.Watchdog.Id')
43
+ return WatchdogController()
44
+
45
+ def _h(self):
46
+ if self._handle is None:
47
+ raise native.disposed("WatchdogController")
48
+ return self._handle
49
+
50
+ @property
51
+ def MaxTimeout(self):
52
+ """131 seconds (4096 x 1024 ticks of the chip's 32 kHz clock)"""
53
+ milliseconds = native.out_int()
54
+ native.watchdog_max_timeout(native.ref(milliseconds))
55
+ return datetime.timedelta(milliseconds=milliseconds.value)
56
+
57
+ @property
58
+ def IsEnabled(self):
59
+ enabled = native.out_int()
60
+ native.watchdog_is_enabled(self._h(), native.ref(enabled))
61
+ return bool(enabled.value)
62
+
63
+ def Enable(self, timeout):
64
+ """Starts the watchdog, or changes its timeout (a timedelta, or seconds).
65
+ The system counts whole seconds: the timeout is rounded up."""
66
+ if isinstance(timeout, datetime.timedelta):
67
+ timeout = timeout.total_seconds()
68
+ native.watchdog_enable(self._h(), max(0, int(round(timeout * 1000))))
69
+
70
+ def Reset(self):
71
+ """Starts the timeout again: call it more often than the timeout"""
72
+ native.watchdog_reset(self._h())
73
+
74
+ def Disable(self):
75
+ """Stops watching this program: the system keeps the watchdog fed from now on"""
76
+ native.watchdog_disable(self._h())
77
+
78
+ def Dispose(self):
79
+ """An enabled watchdog stays enabled: call Disable first to avoid a restart"""
80
+ if self._handle is not None:
81
+ native.watchdog_dispose(self._handle)
82
+ self._handle = None
83
+
84
+ def __enter__(self):
85
+ return self
86
+
87
+ def __exit__(self, *exception):
88
+ self.Dispose()
89
+
90
+ def __del__(self):
91
+ try:
92
+ self.Dispose()
93
+ except Exception:
94
+ pass
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: GHIElectronics.Endpoint.Devices.Watchdog
3
+ Version: 0.5.3
4
+ Summary: The watchdog of GHI Electronics Endpoint, with the TinyCLR API.
5
+ Author-email: "GHI Electronics, LLC" <support@ghielectronics.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://www.ghielectronics.com/
8
+ Project-URL: Repository, https://github.com/ghi-electronics/Endpoint-Libraries
9
+ Project-URL: Issues, https://github.com/ghi-electronics/Endpoint-Libraries/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: GHIElectronics.Endpoint.Core<0.6,>=0.5.3
15
+
16
+ # GHIElectronics.Endpoint.Devices.Watchdog
17
+
18
+ The watchdog of GHI Electronics Endpoint, with the TinyCLR API.
19
+
20
+ Part of the [GHI Electronics Endpoint](https://github.com/ghi-electronics/Endpoint-Libraries) libraries. See the repository README for the full package list and getting-started guide.
@@ -0,0 +1,5 @@
1
+ GHIElectronics/Endpoint/Devices/Watchdog/__init__.py,sha256=iDFYhDkENIk7d1gft1CFsNY68Rtbhgk5Sk3VyCROewY,3017
2
+ ghielectronics_endpoint_devices_watchdog-0.5.3.dist-info/METADATA,sha256=sUCAsE1NLQhgKxuTGTUtEtpYfr3IFtAuMNGdkq7lcyE,991
3
+ ghielectronics_endpoint_devices_watchdog-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ ghielectronics_endpoint_devices_watchdog-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
5
+ ghielectronics_endpoint_devices_watchdog-0.5.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+