GHIElectronics.Endpoint.Devices.Pwm 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.
- GHIElectronics/Endpoint/Devices/Pwm/__init__.py +79 -0
- ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/METADATA +20 -0
- ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/RECORD +5 -0
- ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""PWM for Endpoint, with the same API as .NET's System.Device.Pwm:
|
|
2
|
+
|
|
3
|
+
from GHIElectronics.Endpoint.Core import PwmController, EPM815
|
|
4
|
+
from GHIElectronics.Endpoint.Devices.Pwm import PwmChannel
|
|
5
|
+
|
|
6
|
+
PwmController.Initialize(EPM815.Pwm.Pin.PA8)
|
|
7
|
+
pwm = PwmChannel.Create(EPM815.Pwm.GetChipId(EPM815.Pwm.Pin.PA8),
|
|
8
|
+
EPM815.Pwm.GetChannelId(EPM815.Pwm.Pin.PA8), 1000, 0.5)
|
|
9
|
+
pwm.Start()
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from GHIElectronics.Endpoint.Core._native import native
|
|
13
|
+
|
|
14
|
+
__all__ = ["PwmChannel"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PwmChannel:
|
|
18
|
+
"""A PWM output (call PwmController.Initialize for the pin first)"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, chip, channel, frequency=400, dutyCyclePercentage=0.5):
|
|
21
|
+
handle = native.out_handle()
|
|
22
|
+
native.pwmchannel_create(chip, channel, frequency, float(dutyCyclePercentage), native.ref(handle))
|
|
23
|
+
self._handle = handle
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def Create(chip, channel, frequency=400, dutyCyclePercentage=0.5):
|
|
27
|
+
"""dutyCyclePercentage is 0.0 to 1.0, as in .NET"""
|
|
28
|
+
return PwmChannel(chip, channel, frequency, dutyCyclePercentage)
|
|
29
|
+
|
|
30
|
+
def _h(self):
|
|
31
|
+
if self._handle is None:
|
|
32
|
+
raise native.disposed("PwmChannel")
|
|
33
|
+
return self._handle
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def Frequency(self):
|
|
37
|
+
"""Hz"""
|
|
38
|
+
value = native.out_int()
|
|
39
|
+
native.pwmchannel_get_frequency(self._h(), native.ref(value))
|
|
40
|
+
return value.value
|
|
41
|
+
|
|
42
|
+
@Frequency.setter
|
|
43
|
+
def Frequency(self, frequency):
|
|
44
|
+
native.pwmchannel_set_frequency(self._h(), frequency)
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def DutyCycle(self):
|
|
48
|
+
"""0.0 to 1.0"""
|
|
49
|
+
value = native.out_double()
|
|
50
|
+
native.pwmchannel_get_duty_cycle(self._h(), native.ref(value))
|
|
51
|
+
return value.value
|
|
52
|
+
|
|
53
|
+
@DutyCycle.setter
|
|
54
|
+
def DutyCycle(self, dutyCycle):
|
|
55
|
+
native.pwmchannel_set_duty_cycle(self._h(), float(dutyCycle))
|
|
56
|
+
|
|
57
|
+
def Start(self):
|
|
58
|
+
native.pwmchannel_start(self._h())
|
|
59
|
+
|
|
60
|
+
def Stop(self):
|
|
61
|
+
native.pwmchannel_stop(self._h())
|
|
62
|
+
|
|
63
|
+
def Dispose(self):
|
|
64
|
+
"""Stops the output and gives the channel back"""
|
|
65
|
+
if self._handle is not None:
|
|
66
|
+
native.pwmchannel_dispose(self._handle)
|
|
67
|
+
self._handle = None
|
|
68
|
+
|
|
69
|
+
def __enter__(self):
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
def __exit__(self, *exception):
|
|
73
|
+
self.Dispose()
|
|
74
|
+
|
|
75
|
+
def __del__(self):
|
|
76
|
+
try:
|
|
77
|
+
self.Dispose()
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Devices.Pwm
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: PWM for GHI Electronics Endpoint, with the API of .NET's System.Device.Pwm.
|
|
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.Pwm
|
|
17
|
+
|
|
18
|
+
PWM for GHI Electronics Endpoint, with the API of .NET's System.Device.Pwm.
|
|
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/Pwm/__init__.py,sha256=wd6XJTuuI41dtvrWf_Bbjolli0dvNXRvzmt7tuqU5gg,2384
|
|
2
|
+
ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/METADATA,sha256=I3hBFhScTbQ-8AAkg-Uq6pLS286T3Zw9xYs_wcojAPo,1005
|
|
3
|
+
ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_devices_pwm-0.5.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|