GHIElectronics.Endpoint.Devices.I2c 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,84 @@
1
+ """I2C for Endpoint, with the same API as .NET's System.Device.I2c:
2
+
3
+ from GHIElectronics.Endpoint.Core import I2cController, EPM815
4
+ from GHIElectronics.Endpoint.Devices.I2c import I2cDevice, I2cConnectionSettings
5
+
6
+ I2cController.Initialize(EPM815.I2c.I2c1)
7
+ device = I2cDevice.Create(I2cConnectionSettings(EPM815.I2c.I2c1, 0x50))
8
+ data = bytearray(2)
9
+ device.WriteRead(bytes([0x00]), data)
10
+
11
+ Buffers to read into are bytearrays (filled in place, as .NET's Span<byte>).
12
+ """
13
+
14
+ from GHIElectronics.Endpoint.Core._native import native
15
+
16
+ __all__ = ["I2cDevice", "I2cConnectionSettings"]
17
+
18
+
19
+ class I2cConnectionSettings:
20
+ def __init__(self, busId, deviceAddress):
21
+ self.BusId = busId
22
+ self.DeviceAddress = deviceAddress
23
+
24
+ def __repr__(self):
25
+ return f"I2cConnectionSettings({self.BusId}, 0x{self.DeviceAddress:02X})"
26
+
27
+
28
+ class I2cDevice:
29
+ """A device on an I2C bus (call I2cController.Initialize for the bus first)"""
30
+
31
+ def __init__(self, settings):
32
+ handle = native.out_handle()
33
+ native.i2cdevice_create(settings.BusId, settings.DeviceAddress, native.ref(handle))
34
+ self._handle = handle
35
+ self.ConnectionSettings = settings
36
+
37
+ @staticmethod
38
+ def Create(settings):
39
+ return I2cDevice(settings)
40
+
41
+ def _h(self):
42
+ if self._handle is None:
43
+ raise native.disposed("I2cDevice")
44
+ return self._handle
45
+
46
+ def Read(self, buffer):
47
+ """Reads len(buffer) bytes into the bytearray buffer"""
48
+ pointer, length = native.writable(buffer)
49
+ native.i2cdevice_read(self._h(), pointer, length)
50
+
51
+ def ReadByte(self):
52
+ buffer = bytearray(1)
53
+ self.Read(buffer)
54
+ return buffer[0]
55
+
56
+ def Write(self, buffer):
57
+ pointer, length, _keep = native.readable(buffer)
58
+ native.i2cdevice_write(self._h(), pointer, length)
59
+
60
+ def WriteByte(self, value):
61
+ self.Write(bytes([value]))
62
+
63
+ def WriteRead(self, writeBuffer, readBuffer):
64
+ """Writes, then reads into readBuffer with a repeated start (no stop in between)"""
65
+ write, write_length, _keep = native.readable(writeBuffer)
66
+ read, read_length = native.writable(readBuffer)
67
+ native.i2cdevice_write_read(self._h(), write, write_length, read, read_length)
68
+
69
+ def Dispose(self):
70
+ if self._handle is not None:
71
+ native.i2cdevice_dispose(self._handle)
72
+ self._handle = None
73
+
74
+ def __enter__(self):
75
+ return self
76
+
77
+ def __exit__(self, *exception):
78
+ self.Dispose()
79
+
80
+ def __del__(self):
81
+ try:
82
+ self.Dispose()
83
+ except Exception:
84
+ pass
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: GHIElectronics.Endpoint.Devices.I2c
3
+ Version: 0.5.1
4
+ Summary: I2C for GHI Electronics Endpoint, with the API of .NET's System.Device.I2c.
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.I2c
17
+
18
+ I2C for GHI Electronics Endpoint, with the API of .NET's System.Device.I2c.
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/I2c/__init__.py,sha256=__JBwVMFBp_O-uQ-MOgxD5Ln2lfGI6pB2NDjleAtD_A,2629
2
+ ghielectronics_endpoint_devices_i2c-0.5.1.dist-info/METADATA,sha256=piEvjREjFMxnGEi0u4zP18DQQrbrnNdrQX1-MM9Ur_I,1005
3
+ ghielectronics_endpoint_devices_i2c-0.5.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ ghielectronics_endpoint_devices_i2c-0.5.1.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
5
+ ghielectronics_endpoint_devices_i2c-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
+