GHIElectronics.Endpoint.Devices.Rtc 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.
- GHIElectronics/Endpoint/Devices/Rtc/__init__.py +108 -0
- ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/METADATA +20 -0
- ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/RECORD +5 -0
- ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""The real-time clock of Endpoint, with the same API as .NET IoT's RtcBase
|
|
2
|
+
(and the .NET GHIElectronics.Endpoint.Devices.Rtc), plus TinyCLR's IsValid
|
|
3
|
+
and SetChargeMode:
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from GHIElectronics.Endpoint.Devices.Rtc import RtcController
|
|
7
|
+
|
|
8
|
+
rtc = RtcController()
|
|
9
|
+
if not rtc.IsValid:
|
|
10
|
+
rtc.DateTime = datetime.now(timezone.utc) # set it once; a backup battery keeps it
|
|
11
|
+
print(rtc.DateTime)
|
|
12
|
+
|
|
13
|
+
It counts UTC: at boot, the system time is set from it.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import calendar
|
|
17
|
+
import datetime
|
|
18
|
+
from enum import IntEnum
|
|
19
|
+
|
|
20
|
+
from GHIElectronics.Endpoint.Core._errors import NotImplementedException
|
|
21
|
+
from GHIElectronics.Endpoint.Core._native import native
|
|
22
|
+
|
|
23
|
+
__all__ = ["RtcController", "BatteryChargeMode"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BatteryChargeMode(IntEnum):
|
|
27
|
+
"""How the backup battery or supercapacitor (VBAT) is charged.
|
|
28
|
+
Python cannot name a member None: it is None_ here."""
|
|
29
|
+
None_ = 0
|
|
30
|
+
Fast = 1 # through 1.5 kOhm
|
|
31
|
+
Slow = 2 # through 5 kOhm
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _read():
|
|
35
|
+
seconds = native.out_int64()
|
|
36
|
+
native.rtc_read_time(native.ref(seconds))
|
|
37
|
+
return seconds.value
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RtcController:
|
|
41
|
+
"""The chip's RTC"""
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def DateTime(self):
|
|
45
|
+
"""The time as an aware datetime (.NET's DateTimeOffset), in UTC"""
|
|
46
|
+
return datetime.datetime.fromtimestamp(_read(), tz=datetime.timezone.utc)
|
|
47
|
+
|
|
48
|
+
@DateTime.setter
|
|
49
|
+
def DateTime(self, value):
|
|
50
|
+
if value.tzinfo is None:
|
|
51
|
+
value = value.replace(tzinfo=datetime.timezone.utc)
|
|
52
|
+
native.rtc_set_time(int(value.timestamp()))
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def RtcDateTime(self):
|
|
56
|
+
"""The RTC's own time (UTC) as a naive datetime"""
|
|
57
|
+
return datetime.datetime.fromtimestamp(_read(), tz=datetime.timezone.utc).replace(tzinfo=None)
|
|
58
|
+
|
|
59
|
+
@RtcDateTime.setter
|
|
60
|
+
def RtcDateTime(self, value):
|
|
61
|
+
if value.tzinfo is not None:
|
|
62
|
+
value = value.astimezone(datetime.timezone.utc).replace(tzinfo=None)
|
|
63
|
+
native.rtc_set_time(calendar.timegm(value.timetuple()))
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def LocalTimeZone(self):
|
|
67
|
+
"""The RTC counts UTC, as the system expects"""
|
|
68
|
+
return datetime.timezone.utc
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def IsValid(self):
|
|
72
|
+
"""Whether the RTC has been set since it last lost power (without power
|
|
73
|
+
it starts again at 2000-01-01)"""
|
|
74
|
+
valid = native.out_int()
|
|
75
|
+
native.rtc_is_valid(native.ref(valid))
|
|
76
|
+
return bool(valid.value)
|
|
77
|
+
|
|
78
|
+
def SetChargeMode(self, chargeMode):
|
|
79
|
+
"""Charges the backup battery or supercapacitor on VBAT, or stops charging"""
|
|
80
|
+
native.rtc_set_charge_mode(int(chargeMode))
|
|
81
|
+
|
|
82
|
+
# TODO: backup memory and Calibrate (TinyCLR API), as in .NET
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def BackupMemorySize(self):
|
|
86
|
+
"""Not implemented yet"""
|
|
87
|
+
raise NotImplementedException("Not implemented")
|
|
88
|
+
|
|
89
|
+
def WriteBackupMemory(self, sourceData, *offsets):
|
|
90
|
+
"""Not implemented yet"""
|
|
91
|
+
raise NotImplementedException("Not implemented")
|
|
92
|
+
|
|
93
|
+
def ReadBackupMemory(self, destinationData, *offsets):
|
|
94
|
+
"""Not implemented yet"""
|
|
95
|
+
raise NotImplementedException("Not implemented")
|
|
96
|
+
|
|
97
|
+
def Calibrate(self, pulse):
|
|
98
|
+
"""Not implemented yet"""
|
|
99
|
+
raise NotImplementedException("Not implemented")
|
|
100
|
+
|
|
101
|
+
def Dispose(self):
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
def __enter__(self):
|
|
105
|
+
return self
|
|
106
|
+
|
|
107
|
+
def __exit__(self, *exception):
|
|
108
|
+
self.Dispose()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Devices.Rtc
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: The real-time clock of GHI Electronics Endpoint, with the API of .NET IoT's RtcBase.
|
|
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.Rtc
|
|
17
|
+
|
|
18
|
+
The real-time clock of GHI Electronics Endpoint, with the API of .NET IoT's RtcBase.
|
|
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/Rtc/__init__.py,sha256=KchzdOPk-_jvGOPXaXg9HYDRc9B4H1S1B0AVomYxuBg,3361
|
|
2
|
+
ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/METADATA,sha256=3BmSuf6UBTOzKBUEb8MBEzfrI5PCHeffb1kARL4M7qA,1023
|
|
3
|
+
ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_devices_rtc-0.5.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|