GHIElectronics.Endpoint.Devices.Dac 0.5.1__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,104 @@
1
+ """The analog outputs of Endpoint, with the same API as TinyCLR (and the
2
+ .NET GHIElectronics.Endpoint.Devices.Dac):
3
+
4
+ from GHIElectronics.Endpoint.Core import EPM815
5
+ from GHIElectronics.Endpoint.Devices.Dac import DacController
6
+
7
+ dac = DacController.FromName(EPM815.Dac.Id)
8
+ output = dac.OpenChannel(EPM815.Dac.PA5)
9
+ output.WriteValue(0.5) # a float is a ratio: half of 3.3 V
10
+ output.WriteValue(4095) # an int is a raw value: 3.3 V
11
+
12
+ Opening a channel makes its pin an analog output; closing it switches the
13
+ output off and puts the pin back as it was.
14
+ """
15
+
16
+ from GHIElectronics.Endpoint.Core._errors import ArgumentException
17
+ from GHIElectronics.Endpoint.Core._native import native
18
+
19
+ __all__ = ["DacController", "DacChannel"]
20
+
21
+ _ID = "EPM815.Dac"
22
+
23
+
24
+ class DacController:
25
+ def __init__(self):
26
+ self._channels = []
27
+
28
+ @staticmethod
29
+ def GetDefault():
30
+ return DacController()
31
+
32
+ @staticmethod
33
+ def FromName(name):
34
+ if name != _ID:
35
+ raise ArgumentException(f'There is no DAC named "{name}": use EPM815.Dac.Id')
36
+ return DacController()
37
+
38
+ ChannelCount = 2
39
+ """The number of channels in the chip (channel numbers start at 0)"""
40
+ ResolutionInBits = 12
41
+ MinValue = 0
42
+ """The value for 0 V"""
43
+ MaxValue = 4095
44
+ """The value for the reference voltage (3.3 V)"""
45
+
46
+ def OpenChannel(self, channelNumber):
47
+ """EPM815.Dac.PA4 or EPM815.Dac.PA5"""
48
+ channel = DacChannel(self, channelNumber)
49
+ self._channels.append(channel)
50
+ return channel
51
+
52
+ def Dispose(self):
53
+ """Nothing to release: each channel is released when it is disposed"""
54
+
55
+ def __enter__(self):
56
+ return self
57
+
58
+ def __exit__(self, *exception):
59
+ self.Dispose()
60
+
61
+
62
+ class DacChannel:
63
+ def __init__(self, controller, channelNumber):
64
+ handle = native.out_handle()
65
+ native.dac_open_channel(channelNumber, native.ref(handle))
66
+ self._handle = handle
67
+ self.ChannelNumber = channelNumber
68
+ self.Controller = controller
69
+
70
+ def _h(self):
71
+ if self._handle is None:
72
+ raise native.disposed("DacChannel")
73
+ return self._handle
74
+
75
+ @property
76
+ def LastWrittenValue(self):
77
+ value = native.out_int()
78
+ native.dac_last_written_value(self._h(), native.ref(value))
79
+ return value.value
80
+
81
+ def WriteValue(self, value):
82
+ """An int is a raw value (MinValue to MaxValue); a float is a part of the
83
+ range, 0.0 (0 V) to 1.0 (3.3 V): the two WriteValue of .NET"""
84
+ if isinstance(value, float):
85
+ value = int(value * (DacController.MaxValue - DacController.MinValue) + DacController.MinValue)
86
+ native.dac_write_value(self._h(), int(value))
87
+
88
+ def Dispose(self):
89
+ """Switches the output off and puts the pin back as it was"""
90
+ if self._handle is not None:
91
+ native.dac_close_channel(self._handle)
92
+ self._handle = None
93
+
94
+ def __enter__(self):
95
+ return self
96
+
97
+ def __exit__(self, *exception):
98
+ self.Dispose()
99
+
100
+ def __del__(self):
101
+ try:
102
+ self.Dispose()
103
+ except Exception:
104
+ pass
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: GHIElectronics.Endpoint.Devices.Dac
3
+ Version: 0.5.1
4
+ Summary: Analog outputs for 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.1
15
+
16
+ # GHIElectronics.Endpoint.Devices.Dac
17
+
18
+ Analog outputs for 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/Dac/__init__.py,sha256=boUI7HpgjI_FzvA-OPoKk2rQa5wT0ArLmKxm2uKCdp0,3154
2
+ ghielectronics_endpoint_devices_dac-0.5.1.dist-info/METADATA,sha256=o-pZp8qyoXSYAw_JO-95nBNNfU3E1kR14pKBQdocYlY,987
3
+ ghielectronics_endpoint_devices_dac-0.5.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ ghielectronics_endpoint_devices_dac-0.5.1.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
5
+ ghielectronics_endpoint_devices_dac-0.5.1.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
+