sensor-sdk 0.0.1__tar.gz

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.

Potentially problematic release.


This version of sensor-sdk might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OYMotion Technologies Co., Ltd..
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.1
2
+ Name: sensor-sdk
3
+ Version: 0.0.1
4
+ Summary: Python sdk for Synchroni
5
+ Home-page: https://github.com/oymotion/SynchroniSDKPython
6
+ Author: Martin Ye
7
+ Author-email: yecq_82@hotmail.com
8
+ Requires-Python: >=3.8.0
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE.txt
11
+
12
+ # synchroni_sdk_python
13
+
14
+ Synchroni sdk for Python
15
+
16
+ ## Brief
17
+
18
+ Synchroni SDK is the software development kit for developers to access Synchroni products.
19
+
20
+
21
+ ## Contributing
22
+
23
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
24
+
25
+ ## License
26
+
27
+ MIT
28
+
29
+ ---
30
+
31
+ ## Installation
32
+
33
+ ```sh
34
+ pip install synchroni_sdk_python
35
+ ```
36
+
37
+ ## 1. Permission
38
+
39
+ Application will obtain bluetooth permission by itself.
40
+
41
+ ## 2. Import SDK
42
+
43
+ ```python
44
+ from sensor import *
45
+ ```
46
+
47
+ # SensorController methods:
48
+
49
+ ## 1. Initalize
50
+
51
+ ```python
52
+ sensorControllerInstance = SensorController.Instance
53
+
54
+ # register scan listener
55
+ if not sensorControllerInstance.hasDeviceCallback:
56
+ def on_device_callback(devices):
57
+ # return all devices doesn't connected
58
+ pass
59
+ sensorControllerInstance.onDeviceCallback = on_device_callback
60
+ ```
61
+
62
+ ## 2. Start scan
63
+ Use `async def start_scan(period_in_ms: int) -> bool` to start scan
64
+ ```python
65
+ success = await sensorControllerInstance.startScan(6000)
66
+ ```
67
+ returns true if start scan success, periodInMS means onDeviceCallback will be called every periodInMS
68
+
69
+ ## 3. Stop scan
70
+
71
+ Use `async def stop_scan() -> None` to stop scan
72
+ ```python
73
+ await sensorControllerInstance.stopScan()
74
+ ```
75
+ ## 4. Check scaning
76
+
77
+ Use `property isScanning: bool` to check scanning status
78
+ ```python
79
+ isScanning = sensorControllerInstance.isScanning
80
+ ```
81
+
82
+ ## 5. Check if bluetooth is enabled
83
+
84
+ Use `property isEnabled: bool` to check if bluetooth is enabled
85
+ ```python
86
+ isEnabled = sensorControllerInstance.isEnabled
87
+ ```
88
+ ## 6. Create SensorProfile
89
+
90
+ Use `def requireSensor(device: BLEDevice) -> SensorProfile | None` to create SensorProfile.
91
+
92
+ If bleDevice is invalid, result is None.
93
+
94
+ ```python
95
+ sensorProfile = sensorControllerInstance.requireSensor(bleDevice)
96
+ ```
97
+
98
+ ## 7. Get SensorProfile
99
+
100
+ Use `def getSensor(device: BLEDevice) -> SensorProfile | None` to get SensorProfile.
101
+
102
+ If SensorProfile didn't created, result is None.
103
+
104
+ ```python
105
+ sensorProfile = SensorControllerInstance.getSensor(bleDevice)
106
+ ```
107
+
108
+ ## 8. Get Connected SensorProfiles
109
+
110
+ Use `def getConnectedSensors() -> list[SensorProfile]` to get connected SensorProfiles.
111
+ ```python
112
+ sensorProfiles = SensorControllerInstance.getConnectedSensors()
113
+ ```
114
+
115
+ ## 9. Get Connected BLE Devices
116
+
117
+ Use `def getConnectedDevices() -> list[SensorProfile]` to get connected BLE Devices.
118
+ ```python
119
+ bleDevices = SensorControllerInstance.getConnectedDevices()
120
+ ```
121
+
122
+ # SensorProfile methods:
123
+
124
+ ## 1. Initalize
125
+ Please register callbacks for SensorProfile
126
+ ```python
127
+ sensorProfile = sensorControllerInstance.requireSensor(bleDevice)
128
+
129
+ # register callbacks
130
+ def on_state_changed(sensor, newState):
131
+ # please do logic when device disconnected unexpected
132
+ pass
133
+
134
+ def on_error_callback(sensor, reason):
135
+ # called when error occurs
136
+ pass
137
+
138
+ def on_power_changed(sensor, power):
139
+ # callback for get battery level of device, power from 0 - 100, -1 is invalid
140
+ pass
141
+
142
+ def on_data_callback(sensor, data):
143
+ # called after start data transfer
144
+ pass
145
+
146
+ sensorProfile.onStateChanged = on_state_changed
147
+ sensorProfile.onErrorCallback = on_error_callback
148
+ sensorProfile.onPowerChanged = on_power_changed
149
+ sensorProfile.onDataCallback = on_data_callback
150
+ ```
151
+
152
+ ## 2. Connect device
153
+ Use `async def connect() -> bool` to connect.
154
+ ```python
155
+ success = await sensorProfile.connect()
156
+ ```
157
+
158
+ ## 3. Disconnect
159
+ Use `async def disconnect() -> bool` to disconnect.
160
+ ```python
161
+ success = await sensorProfile.disconnect()
162
+ ```
163
+
164
+
165
+ ## 4. Get device status
166
+ Use `property connectionState: DeviceStateEx` to get device status.
167
+
168
+ Please send command in 'Ready' state, should be after connect() return True.
169
+
170
+ ```python
171
+ deviceStateEx = sensorProfile.connectionState
172
+
173
+ # deviceStateEx has define:
174
+ # class DeviceStateEx(Enum):
175
+ # Disconnected = 0
176
+ # Connecting = 1
177
+ # Connected = 2
178
+ # Ready = 3
179
+ # Disconnecting = 4
180
+ # Invalid = 5
181
+ ```
182
+
183
+
184
+
185
+ ## 5. Get BLE device of SensorProfile
186
+ Use `property BLEDevice: BLEDevice` to get BLE device of SensorProfile.
187
+ ```python
188
+ bleDevice = sensorProfile.BLEDevice
189
+ ```
190
+
191
+ ## 6. Get device info of SensorProfile
192
+ Use `async def deviceInfo() -> dict | None` to get device info of SensorProfile.
193
+
194
+ Please call after device in 'Ready' state, return None if it's not connected.
195
+
196
+ ```python
197
+ deviceInfo = await sensorProfile.deviceInfo()
198
+
199
+ # deviceInfo has defines:
200
+ # deviceInfo = {
201
+ # "deviceName": str,
202
+ # "modelName": str,
203
+ # "hardwareVersion": str,
204
+ # "firmwareVersion": str,
205
+ # "emgChannelCount": int,
206
+ # "eegChannelCount": int,
207
+ # "ecgChannelCount": int,
208
+ # "accChannelCount": int,
209
+ # "gyroChannelCount": int,
210
+ # "brthChannelCount": int,
211
+ # "mtuSize": int
212
+ # }
213
+ ```
214
+
215
+
216
+ ## 7. Init data transfer
217
+ Use `async def init(packageSampleCount: int, powerRefreshInterval: int) -> bool`.
218
+
219
+ Please call after device in 'Ready' state, return True if init succeed.
220
+ ```python
221
+ success = await sensorProfile.init(5, 60*1000)
222
+ ```
223
+ packageSampleCount: set sample counts of SensorData.channelSamples in onDataCallback()
224
+ powerRefreshInterval: callback period for onPowerChanged()
225
+
226
+ ## 8. Check if init data transfer succeed
227
+ Use `property hasInited: bool` to check if init data transfer succeed.
228
+ ```python
229
+ hasInited = sensorProfile.hasInited
230
+ ```
231
+
232
+ ## 9. DataNotify
233
+ Use `async def startDataNotification() -> bool` to start data notification.
234
+
235
+ Please call if hasInited return True
236
+ ### 9.1 Start data transfer
237
+
238
+ ```python
239
+ success = await sensorProfile.startDataNotification()
240
+ ```
241
+
242
+ Data type list:
243
+
244
+ ```python
245
+ class DataType(Enum):
246
+ NTF_ACC = 0x1 # unit is g
247
+ NTF_GYRO = 0x2 # unit is degree/s
248
+ NTF_EEG = 0x10 # unit is uV
249
+ NTF_ECG = 0x11 # unit is uV
250
+ NTF_BRTH = 0x15 # unit is uV
251
+ ```
252
+
253
+ Process data in onDataCallback.
254
+
255
+ ```python
256
+ def on_data_callback(sensor, data):
257
+ if data.dataType == DataType.NTF_EEG:
258
+ pass
259
+ elif data.dataType == DataType.NTF_ECG:
260
+ pass
261
+
262
+ # process data as you wish
263
+ for oneChannelSamples in data.channelSamples:
264
+ for sample in oneChannelSamples:
265
+ if sample.isLost:
266
+ # do some logic
267
+ pass
268
+ else:
269
+ # draw with sample.data & sample.channelIndex
270
+ # print(f"{sample.channelIndex} | {sample.sampleIndex} | {sample.data} | {sample.impedance}")
271
+ pass
272
+
273
+ sensorProfile.onDataCallback = on_data_callback
274
+ ```
275
+
276
+ ### 9.2 Stop data transfer
277
+ Use `async def stopDataNotification() -> bool` to stop data transfer.
278
+ ```python
279
+ success = await sensorProfile.stopDataNotification()
280
+ ```
281
+
282
+ ### 9.3 Check if it's data transfering
283
+ Use `property isDataTransfering: bool` to check if it's data transfering.
284
+ ```python
285
+ isDataTransfering = sensorProfile.isDataTransfering
286
+ ```
287
+
288
+ ## 10. Get battery level
289
+ Use `async def batteryPower() -> int` to get battery level. Please call after device in 'Ready' state.
290
+
291
+ ```python
292
+ batteryPower = await sensorProfile.batteryPower()
293
+
294
+ # batteryPower is battery level returned, value ranges from 0 to 100, 0 means out of battery, while 100 means full.
295
+ ```
296
+
297
+ Please check SimpleTest function in App
@@ -0,0 +1,286 @@
1
+ # synchroni_sdk_python
2
+
3
+ Synchroni sdk for Python
4
+
5
+ ## Brief
6
+
7
+ Synchroni SDK is the software development kit for developers to access Synchroni products.
8
+
9
+
10
+ ## Contributing
11
+
12
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
13
+
14
+ ## License
15
+
16
+ MIT
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ pip install synchroni_sdk_python
24
+ ```
25
+
26
+ ## 1. Permission
27
+
28
+ Application will obtain bluetooth permission by itself.
29
+
30
+ ## 2. Import SDK
31
+
32
+ ```python
33
+ from sensor import *
34
+ ```
35
+
36
+ # SensorController methods:
37
+
38
+ ## 1. Initalize
39
+
40
+ ```python
41
+ sensorControllerInstance = SensorController.Instance
42
+
43
+ # register scan listener
44
+ if not sensorControllerInstance.hasDeviceCallback:
45
+ def on_device_callback(devices):
46
+ # return all devices doesn't connected
47
+ pass
48
+ sensorControllerInstance.onDeviceCallback = on_device_callback
49
+ ```
50
+
51
+ ## 2. Start scan
52
+ Use `async def start_scan(period_in_ms: int) -> bool` to start scan
53
+ ```python
54
+ success = await sensorControllerInstance.startScan(6000)
55
+ ```
56
+ returns true if start scan success, periodInMS means onDeviceCallback will be called every periodInMS
57
+
58
+ ## 3. Stop scan
59
+
60
+ Use `async def stop_scan() -> None` to stop scan
61
+ ```python
62
+ await sensorControllerInstance.stopScan()
63
+ ```
64
+ ## 4. Check scaning
65
+
66
+ Use `property isScanning: bool` to check scanning status
67
+ ```python
68
+ isScanning = sensorControllerInstance.isScanning
69
+ ```
70
+
71
+ ## 5. Check if bluetooth is enabled
72
+
73
+ Use `property isEnabled: bool` to check if bluetooth is enabled
74
+ ```python
75
+ isEnabled = sensorControllerInstance.isEnabled
76
+ ```
77
+ ## 6. Create SensorProfile
78
+
79
+ Use `def requireSensor(device: BLEDevice) -> SensorProfile | None` to create SensorProfile.
80
+
81
+ If bleDevice is invalid, result is None.
82
+
83
+ ```python
84
+ sensorProfile = sensorControllerInstance.requireSensor(bleDevice)
85
+ ```
86
+
87
+ ## 7. Get SensorProfile
88
+
89
+ Use `def getSensor(device: BLEDevice) -> SensorProfile | None` to get SensorProfile.
90
+
91
+ If SensorProfile didn't created, result is None.
92
+
93
+ ```python
94
+ sensorProfile = SensorControllerInstance.getSensor(bleDevice)
95
+ ```
96
+
97
+ ## 8. Get Connected SensorProfiles
98
+
99
+ Use `def getConnectedSensors() -> list[SensorProfile]` to get connected SensorProfiles.
100
+ ```python
101
+ sensorProfiles = SensorControllerInstance.getConnectedSensors()
102
+ ```
103
+
104
+ ## 9. Get Connected BLE Devices
105
+
106
+ Use `def getConnectedDevices() -> list[SensorProfile]` to get connected BLE Devices.
107
+ ```python
108
+ bleDevices = SensorControllerInstance.getConnectedDevices()
109
+ ```
110
+
111
+ # SensorProfile methods:
112
+
113
+ ## 1. Initalize
114
+ Please register callbacks for SensorProfile
115
+ ```python
116
+ sensorProfile = sensorControllerInstance.requireSensor(bleDevice)
117
+
118
+ # register callbacks
119
+ def on_state_changed(sensor, newState):
120
+ # please do logic when device disconnected unexpected
121
+ pass
122
+
123
+ def on_error_callback(sensor, reason):
124
+ # called when error occurs
125
+ pass
126
+
127
+ def on_power_changed(sensor, power):
128
+ # callback for get battery level of device, power from 0 - 100, -1 is invalid
129
+ pass
130
+
131
+ def on_data_callback(sensor, data):
132
+ # called after start data transfer
133
+ pass
134
+
135
+ sensorProfile.onStateChanged = on_state_changed
136
+ sensorProfile.onErrorCallback = on_error_callback
137
+ sensorProfile.onPowerChanged = on_power_changed
138
+ sensorProfile.onDataCallback = on_data_callback
139
+ ```
140
+
141
+ ## 2. Connect device
142
+ Use `async def connect() -> bool` to connect.
143
+ ```python
144
+ success = await sensorProfile.connect()
145
+ ```
146
+
147
+ ## 3. Disconnect
148
+ Use `async def disconnect() -> bool` to disconnect.
149
+ ```python
150
+ success = await sensorProfile.disconnect()
151
+ ```
152
+
153
+
154
+ ## 4. Get device status
155
+ Use `property connectionState: DeviceStateEx` to get device status.
156
+
157
+ Please send command in 'Ready' state, should be after connect() return True.
158
+
159
+ ```python
160
+ deviceStateEx = sensorProfile.connectionState
161
+
162
+ # deviceStateEx has define:
163
+ # class DeviceStateEx(Enum):
164
+ # Disconnected = 0
165
+ # Connecting = 1
166
+ # Connected = 2
167
+ # Ready = 3
168
+ # Disconnecting = 4
169
+ # Invalid = 5
170
+ ```
171
+
172
+
173
+
174
+ ## 5. Get BLE device of SensorProfile
175
+ Use `property BLEDevice: BLEDevice` to get BLE device of SensorProfile.
176
+ ```python
177
+ bleDevice = sensorProfile.BLEDevice
178
+ ```
179
+
180
+ ## 6. Get device info of SensorProfile
181
+ Use `async def deviceInfo() -> dict | None` to get device info of SensorProfile.
182
+
183
+ Please call after device in 'Ready' state, return None if it's not connected.
184
+
185
+ ```python
186
+ deviceInfo = await sensorProfile.deviceInfo()
187
+
188
+ # deviceInfo has defines:
189
+ # deviceInfo = {
190
+ # "deviceName": str,
191
+ # "modelName": str,
192
+ # "hardwareVersion": str,
193
+ # "firmwareVersion": str,
194
+ # "emgChannelCount": int,
195
+ # "eegChannelCount": int,
196
+ # "ecgChannelCount": int,
197
+ # "accChannelCount": int,
198
+ # "gyroChannelCount": int,
199
+ # "brthChannelCount": int,
200
+ # "mtuSize": int
201
+ # }
202
+ ```
203
+
204
+
205
+ ## 7. Init data transfer
206
+ Use `async def init(packageSampleCount: int, powerRefreshInterval: int) -> bool`.
207
+
208
+ Please call after device in 'Ready' state, return True if init succeed.
209
+ ```python
210
+ success = await sensorProfile.init(5, 60*1000)
211
+ ```
212
+ packageSampleCount: set sample counts of SensorData.channelSamples in onDataCallback()
213
+ powerRefreshInterval: callback period for onPowerChanged()
214
+
215
+ ## 8. Check if init data transfer succeed
216
+ Use `property hasInited: bool` to check if init data transfer succeed.
217
+ ```python
218
+ hasInited = sensorProfile.hasInited
219
+ ```
220
+
221
+ ## 9. DataNotify
222
+ Use `async def startDataNotification() -> bool` to start data notification.
223
+
224
+ Please call if hasInited return True
225
+ ### 9.1 Start data transfer
226
+
227
+ ```python
228
+ success = await sensorProfile.startDataNotification()
229
+ ```
230
+
231
+ Data type list:
232
+
233
+ ```python
234
+ class DataType(Enum):
235
+ NTF_ACC = 0x1 # unit is g
236
+ NTF_GYRO = 0x2 # unit is degree/s
237
+ NTF_EEG = 0x10 # unit is uV
238
+ NTF_ECG = 0x11 # unit is uV
239
+ NTF_BRTH = 0x15 # unit is uV
240
+ ```
241
+
242
+ Process data in onDataCallback.
243
+
244
+ ```python
245
+ def on_data_callback(sensor, data):
246
+ if data.dataType == DataType.NTF_EEG:
247
+ pass
248
+ elif data.dataType == DataType.NTF_ECG:
249
+ pass
250
+
251
+ # process data as you wish
252
+ for oneChannelSamples in data.channelSamples:
253
+ for sample in oneChannelSamples:
254
+ if sample.isLost:
255
+ # do some logic
256
+ pass
257
+ else:
258
+ # draw with sample.data & sample.channelIndex
259
+ # print(f"{sample.channelIndex} | {sample.sampleIndex} | {sample.data} | {sample.impedance}")
260
+ pass
261
+
262
+ sensorProfile.onDataCallback = on_data_callback
263
+ ```
264
+
265
+ ### 9.2 Stop data transfer
266
+ Use `async def stopDataNotification() -> bool` to stop data transfer.
267
+ ```python
268
+ success = await sensorProfile.stopDataNotification()
269
+ ```
270
+
271
+ ### 9.3 Check if it's data transfering
272
+ Use `property isDataTransfering: bool` to check if it's data transfering.
273
+ ```python
274
+ isDataTransfering = sensorProfile.isDataTransfering
275
+ ```
276
+
277
+ ## 10. Get battery level
278
+ Use `async def batteryPower() -> int` to get battery level. Please call after device in 'Ready' state.
279
+
280
+ ```python
281
+ batteryPower = await sensorProfile.batteryPower()
282
+
283
+ # batteryPower is battery level returned, value ranges from 0 to 100, 0 means out of battery, while 100 means full.
284
+ ```
285
+
286
+ Please check SimpleTest function in App
@@ -0,0 +1,4 @@
1
+ from .sensor_controller import *
2
+ from .sensor_data import *
3
+ from .sensor_device import *
4
+ from .sensor_profile import *