smartusbhub 1.0.0__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,756 @@
1
+ Metadata-Version: 2.4
2
+ Name: smartusbhub
3
+ Version: 1.0.0
4
+ Summary: A Python library for SmartUSBHub that provides per-port power and data control, voltage and current monitoring, and manual plug/unplug simulation—designed for development, testing, and device management.
5
+ Author-email: Jasonzhang <embeddedtec@outlook.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/MrzhangF1ghter/smartusbhub
8
+ Project-URL: Issues, https://github.com/MrzhangF1ghter/smartusbhub/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # SmartUSBHub python library
17
+
18
+ [简体中文](./README_cn.md)
19
+
20
+ ![view1](assets/view1.png)**This document applies to model:** SmartUSBHub_V1.3a
21
+
22
+ **Last updated on:** June 24, 2025
23
+
24
+
25
+
26
+ ## Introduction
27
+
28
+ Before using, please familiarize yourself with SmartUSBHub. For details, see the [smartusbhub_user_guide](https://github.com/MrzhangF1ghter/smartusbhub/blob/main/document/smartusbhub_user_guide.md)
29
+
30
+
31
+
32
+ The Smart USB Hub offers per-port power and data control, voltage/current sensing, and manual plug/unplug simulation—designed for development, testing, and device management.
33
+
34
+ 1. **Standard USB 2.0 Data Transfer**: Utilizes a USB 2.0 hub chip with MTT technology. Each port supports up to 480 Mbps (USB 2.0 high-speed), allowing it to function as a normal USB hub.
35
+
36
+ 2. **Programmable USB Port Switching**
37
+
38
+ - Independently control **VBUS power** and **D+/D− data lines** for each downstream port
39
+ - Simulates manual hot-plug behavior via button or serial command
40
+
41
+ 3. **Integrated Voltage and Current Monitoring**
42
+
43
+ - Each port supports real-time sensing of **voltage** and **current** for power analysis and device diagnostics
44
+
45
+ 4. **Software-Controllable & Multi-Platform Compatible**
46
+
47
+ - USB CDC-based serial command interface, provide Python libraries for quick control
48
+ - Supports on Windows, macOS, Linux platforms, no need additional drivers
49
+
50
+ 5. **Dual Operating Modes**
51
+
52
+ - **Normal Mode**: all ports can operate independently
53
+ - **Interlock Mode**: only one port is active at a time
54
+ - Each port supports customizable **power-on defaults** and **power-loss state retention**
55
+
56
+ 6. **Robust Hardware Interfaces**
57
+
58
+ - 1x USB-C upstream, 4x USB-A USB2.0 downstream, 1x serial control port, 1x auxiliary power input
59
+ - Supports up to 5V 4A per port, with overvoltage, overcurrent, reverse current, and ESD protection
60
+
61
+ 7. **Topology Support for Scalable Deployment**
62
+
63
+ - Supports hierarchical topologies with data/control port aggregation
64
+ - Each hub can be assigned a unique address for large-scale setups
65
+
66
+ 8. **Upgradeable and Secure**
67
+
68
+ - OTA firmware upgrade support
69
+ - Access control features planned for future firmware releases
70
+
71
+
72
+
73
+ > [!NOTE]
74
+ >
75
+ > If you don't want to control the SmartUSBHub by using the python library, you can refer the most simplest control demo: [simple_serial.py](./examples/simple_serial.py)
76
+
77
+
78
+
79
+ ## Environment Setup
80
+
81
+ ### Get the Latest Library
82
+
83
+ Clone [this](https://github.com/MrzhangF1ghter/smartusbhub) repository to your local project, assuming your project folder is named `my_project`:
84
+
85
+ ```shell
86
+ cd my_project
87
+ git clone https://github.com/MrzhangF1ghter/smartusbhub.git
88
+ ```
89
+
90
+ Library structure:
91
+
92
+ ```shell
93
+ .
94
+ ├── README.md # Documentation
95
+ ├── examples # Demo examples
96
+ ├── apps # Precompiled demo binaries
97
+ ├── requirements.txt # Dependency list
98
+ └── smartusbhub.py # Core functionality source code
99
+ ```
100
+
101
+
102
+
103
+ ### Setup Virtual Environment
104
+
105
+ Create a Python virtual environment (recommended):
106
+ `python -m venv venv`
107
+
108
+ 1. Activate the Python virtual environment:
109
+
110
+ - On Windows:
111
+
112
+ `.\venv\Scripts\activate.bat`
113
+
114
+ - On Unix:
115
+
116
+ `source ./venv/bin/activate`
117
+
118
+ 2. Install dependencies:
119
+ `pip install -r requirements.txt`
120
+
121
+ 3. Connect the included USB-A to USB-C data cable to the `Command Port`, and plug the other end into the host’s USB port. Once connected, the host will recognize the device as follows:
122
+
123
+ - On Windows: `COMx`
124
+ - On Linux: `/dev/ttyACMx` or `/dev/cu.usbmodemx`
125
+ - On macOS: `/dev/cu.usbmodemx`
126
+
127
+ > [!NOTE]
128
+ >
129
+ > In addition to connecting the `Command Port`, you must also connect the `USB upstream port` for USB data transfer.
130
+ >
131
+ > ![connection_guide](assets/connection_guide.png)
132
+
133
+
134
+
135
+ ### Run Examples
136
+
137
+ `smartusbhub` Python library includes several usage examples in the `examples` directory:
138
+
139
+ - `power_control_example`:Demonstrates how to control the power supply of a specified port.
140
+ - `dataline_control_example`:Demonstrates how to toggle the USB differential signal line switch of a specified port for data connect/disconnect while keeping power enabled.
141
+ - `voltage_monitor_example`:Demonstrates how to retrieve the voltage value of a specified port.
142
+ - `current_monitor_example`:Demonstrates how to retrieve the current value of a specified port.
143
+ - `setting_example`: Demonstrates how to configure parameters.
144
+ - `user_callback_example`:Demonstrates how to add user callbacks for specfic command.
145
+ - `oscilloscope`:A Qt GUI-based oscilloscope that allows control of channel power switching, as well as voltage and current acquisition.
146
+
147
+ ![oscilloscope](./assets/oscilloscope.png)
148
+
149
+ <center>Figure: Oscilloscope app</center>
150
+
151
+
152
+
153
+ To run a demo, execute the following commands:
154
+
155
+ - Activate the virtual environment:
156
+
157
+ - Linux/macOS:
158
+
159
+ ```
160
+ source ./venv/bin/activate
161
+ ```
162
+
163
+ - Windows :
164
+
165
+ ```shell
166
+ .\venv\Scripts\activate.bat
167
+ ```
168
+
169
+ - Navigate to the examples folder:
170
+
171
+ ```
172
+ cd ./examples/
173
+ ```
174
+
175
+ - Run a demo (for example):
176
+
177
+ ```shell
178
+ python oscilloscope.py
179
+ ```
180
+
181
+
182
+
183
+ ### Integrating with Your Project
184
+
185
+ You can integrate this library into your project by importing the smartusbhub module.
186
+
187
+ 1. Follow the configuration steps from the earlier sections (steps 1 through 5) to set up the environment.
188
+
189
+ 2. Import the smartusbhub library into your project:
190
+
191
+ ```python
192
+ import sys
193
+ sys.path.append('../')
194
+ from smartusbhub import SmartUSBHub
195
+ ```
196
+
197
+ 3. Initialize a `SmartUSBhub`instance:
198
+
199
+ - By automatically scanning and connecting to the device:
200
+
201
+ ```python
202
+ hub = SmartUSBHub.scan_and_connect()
203
+ ```
204
+
205
+ - By specifying the serial port to connect to the device:
206
+
207
+ ```python
208
+ hub = SmartUSBHub("serial port path")
209
+ Example:
210
+ hub = SmartUSBHub("/dev/cu.usbmodem132301")
211
+ ```
212
+
213
+
214
+
215
+ ## **User Interface**
216
+
217
+ ### **Device Connection**
218
+
219
+ #### `scan_and_connect()`
220
+
221
+ - **Description**: Scans for available Smart USB Hub devices and connects to the first one found.
222
+ - **Return Value**:
223
+
224
+ - SmartUSBHub instance (if a device is found), otherwise returns None.
225
+
226
+ - **Example**:
227
+
228
+ ```python
229
+ hub = SmartUSBHub.scan_and_connect()
230
+ ```
231
+
232
+ #### `connect(port)`
233
+
234
+ - **Description**: Connects to the specified Smart USB Hub device.
235
+
236
+ - **Parameters:**
237
+
238
+ - [port](str): The serial port name to connect to.
239
+
240
+ - **Example:**
241
+
242
+ ```python
243
+ hub.connect("/dev/cu.usbmodem132301")
244
+ ```
245
+
246
+
247
+
248
+ ### **Device Disconnection**
249
+
250
+ #### `disconnect()`
251
+
252
+ - **Description**: Disconnects the current Smart USB Hub device.
253
+
254
+ - **Example:**
255
+
256
+ ```python
257
+ hub.disconnect()
258
+ ```
259
+
260
+
261
+
262
+ ### **Channel Power Control**
263
+
264
+ #### `set_channel_power(*channels, state)`
265
+
266
+ - **Description**: Sets the power state of the specified channel(s).
267
+
268
+ - **Parameters**:
269
+ - `*channels` (int): The channel(s) to control.
270
+ - state (int): `1` to turn the power,`0` to turn the power off.
271
+
272
+ - **Return Value**:
273
+
274
+ - bool: Returns `True` if the command is successful, otherwise `False`.
275
+
276
+ - **Example**:
277
+
278
+ ```python
279
+ hub.set_channel_power(1, 2, state=1)
280
+ ```
281
+
282
+
283
+
284
+ ### Getting Channel Power Status
285
+
286
+ #### `get_channel_power_status(*channels)`
287
+
288
+ - **Description**: Queries the power status of the specified channel(s).
289
+ - **Parameters**:
290
+
291
+ - `*channels` (int): The channel(s) to query.
292
+ - **Return Value**:
293
+ - `dict` or `int` or `None`: If querying multiple channels, returns a dictionary of channel statuses; if querying a single channel, returns that channel’s status; if a timeout occurs, returns `None`.
294
+ - **Example**:
295
+ ```python
296
+ status = hub.get_channel_power_status(1, 2)
297
+ ```
298
+
299
+
300
+
301
+ ### Channel Power Interlock Control
302
+
303
+ #### `set_channel_power_interlock(channel)`
304
+
305
+ - **Description**: Sets the interlock mode for the specified channel or all channels.
306
+ - **Parameters**:
307
+
308
+ - channel (int or `None`): The channel to set. If None, all channels will be turned off.
309
+
310
+ - **Return Value**:
311
+
312
+ - bool: Returns True if the command is successful, otherwise False.
313
+
314
+ - **Example**:
315
+
316
+ ```python
317
+ hub.set_channel_power_interlock(1)
318
+ ```
319
+
320
+
321
+
322
+ ### Controlling Channel USB Data Line Switch
323
+
324
+ #### `set_channel_dataline(*channels, state)`
325
+
326
+ - **Description**: Sets the USB data line (D+ and D-) connection state for the specified channel(s).
327
+
328
+ - **Parameters**:
329
+ - `*channels` (int): The channel(s) to update.
330
+ - state (int): `1` to connect the D+ and D- lines, `0` to disconnect the D+ and D- lines.
331
+
332
+ - **Return Value**:
333
+
334
+ - bool: Returns `True` if the command is successful, otherwise `False`.
335
+
336
+ - **Example**:
337
+
338
+ Connect the data lines of channel 1:
339
+
340
+ ```python
341
+ hub.set_channel_dataline(1,state=1)
342
+ ```
343
+
344
+
345
+ ### Getting Channel USB Data Line Status
346
+ #### `get_channel_dataline_status(*channels)`
347
+ - **Description**: Queries the USB data line switch status of the specified channel(s).
348
+
349
+ - **Parameters**:
350
+ - `*channels` (int): The channel(s) to query.
351
+
352
+ - **Return Value**:
353
+ - `dict` or `None`: A dictionary containing each channel’s data line status; if a timeout occurs, returns `None`.
354
+
355
+ - **Example**:
356
+
357
+ Get the data line connection status of channels 1 and 2:
358
+
359
+ ```python
360
+ status = hub.get_channel_dataline_status(1, 2)
361
+ ```
362
+
363
+
364
+
365
+ ### Getting Channel Voltage
366
+
367
+ #### `get_channel_voltage(channel)`
368
+
369
+ - **Description**: Queries the voltage of a single channel.
370
+ - **Parameters**:
371
+ - channel (int): The channel(s) to query.
372
+
373
+ - **Return Value**:
374
+ - `int` or `None`: The voltage value of the channel (in mV); if a timeout occurs, returns `None`.
375
+ - **Example**:
376
+
377
+ Get the voltage of channel 1:
378
+
379
+ ```python
380
+ voltage = hub.get_channel_voltage(1)
381
+ ```
382
+
383
+
384
+
385
+
386
+ ### Getting Channel Current
387
+
388
+ #### `get_channel_current(channel)`
389
+
390
+ - **Description**: Queries the current of a single channel.
391
+ - **Parameters**:
392
+
393
+ - channel (int): The channel(s) to query.
394
+
395
+ - **Return Value**:
396
+
397
+ - `int` or `None`: The current value of the channel (in mA); if a timeout occurs, returns `None`.
398
+ - **Example**:
399
+
400
+ Get the current of channel 1:
401
+
402
+ ```python
403
+ current = hub.get_channel_current(1)
404
+ ```
405
+
406
+
407
+
408
+ ### Setting Channel Power-On Default State
409
+
410
+ #### `set_default_power_status(*channels,enable,status)`
411
+
412
+ - **Description**: Sets the power-on default power state for the specified channel(s).
413
+
414
+ - **Parameters**:
415
+
416
+ - `*channels` (int): The channel(s) to configure.
417
+ - enable (int): `1` to enable using the default state, `0` to disable using the default state.
418
+ - status (int): `1` for default power ON, `0` for default power OFF.
419
+
420
+ - **Example**:
421
+
422
+ Channels 1, 2, 3, 4 default power ON at startup:
423
+
424
+ ```python
425
+ hub.set_default_dataline_status(1,2,3,4,enable=1,status=0)
426
+ ```
427
+
428
+ Channels 1, 2, 3, 4 do not use default values at startup:
429
+
430
+ ```python
431
+ hub.set_default_dataline_status(1,2,3,4,enable=0)
432
+ ```
433
+
434
+
435
+
436
+ ### **Getting Channel Power-On Default State**
437
+
438
+ #### `get_default_power_status(self,*channels)`
439
+
440
+ - **Description**: Queries the power-on default power state of one or multiple channels.
441
+
442
+ - **Parameters**:
443
+
444
+ - `*channels` (int): The channel(s) to query.
445
+
446
+ - **Return Value**:
447
+
448
+ - dict or None: A dictionary in the format {channel: {"enabled": enabled_flag, "value": state}}, where enabled is 0 (disabled) or 1 (enabled), and value is 0 (default OFF) or 1 (default ON).
449
+ - Returns None if a timeout occurs.
450
+
451
+ - **Example**:
452
+
453
+ Channels 1, 2, 3, 4 default power ON at startup:
454
+
455
+ ```python
456
+ hub.get_default_power_status(1,2,3,4)
457
+ ```
458
+
459
+ Returns:
460
+
461
+ ```python
462
+ {1: {'enabled': 0, 'value': 0}, 2: {'enabled': 0, 'value': 0}, 3: {'enabled': 0, 'value': 0}, 4: {'enabled': 0, 'value': 0}}
463
+ ```
464
+
465
+
466
+
467
+ ### Setting Channel USB Data Line Power-On Default State
468
+
469
+ #### `set_default_dataline_status(*channels,enable,status)`
470
+
471
+ - **Description**: Sets the power-on default state of the USB data line connection for the specified channel(s).
472
+
473
+ - **Parameters**:
474
+
475
+ - `*channels` (int): The channel(s) to configure.
476
+ - enable (int): `1` to enable using the default state, `0` to disable using the default state.
477
+ - status (int): `1` for default data line connected, `0` for default data line disconnected.
478
+
479
+ - **Return Value**:
480
+
481
+ - bool: Returns `True` if the command is successful, otherwise `False`.
482
+
483
+ - **Example**:
484
+
485
+ Channels 1, 2, 3, 4 default data line connected at startup:
486
+
487
+ ```python
488
+ hub.set_default_dataline_status(1,2,3,4,enable=1,status=1)
489
+ ```
490
+
491
+
492
+
493
+
494
+ ### Getting Channel USB Data Line Power-On Default State
495
+
496
+ #### `get_default_dataline_status(self,*channels)`
497
+
498
+ - **Description**: Queries the power-on default state of the USB data line connection for one or multiple channels.
499
+
500
+ - **Parameters**:
501
+
502
+ - `*channels` (int): The channel(s) to query.
503
+
504
+ - **Return Value**:
505
+
506
+ - `dict` or `None`: A dictionary in the format {channel: {"enabled": enabled_flag, "value": state}}, where enabled is 0 (disabled) or 1 (enabled), and value is 0 (default disconnected) or 1 (default connected).
507
+ - Returns `None` if a timeout occurs.
508
+
509
+ - **Example**:
510
+
511
+ Get the power-on default USB data line state of channels 1, 2, 3, 4:
512
+
513
+ ```python
514
+ hub.get_default_dataline_status(1,2,3,4)
515
+ ```
516
+
517
+ Returns:
518
+
519
+ ```python
520
+ {1: {'enabled': 0, 'value': 1}, 2: {'enabled': 0, 'value': 1}, 3: {'enabled': 0, 'value': 1}, 4: {'enabled': 0, 'value': 1}}
521
+ ```
522
+
523
+
524
+
525
+ ### Setting Button Control
526
+
527
+ #### `set_button_control(enable)`
528
+
529
+ - **Description**: Enables or disables the hub’s physical button.
530
+
531
+ - **Parameters**:
532
+
533
+ - enable (bool): `True` to enable the button, `False` to disable the button.
534
+
535
+ - **Return Value**:
536
+
537
+ - bool: Returns `True` if the command is successful, otherwise `False`.
538
+
539
+ - **Example**:
540
+
541
+ Enable the button:
542
+
543
+ ```python
544
+ hub.set_button_control(True)
545
+ ```
546
+
547
+
548
+
549
+ ### Getting Button Control Status
550
+
551
+ #### `get_button_control_status()`
552
+
553
+ - **Description**: Queries whether the hub’s physical button is enabled.
554
+ - **Return Value**:
555
+ - `int` or `None`: `1` if enabled, `0` if disabled. Returns None if no response.
556
+ - **Example**:
557
+
558
+ Check if the button is enabled:
559
+
560
+ ```python
561
+ status = hub.get_button_control_status()
562
+ ```
563
+
564
+
565
+
566
+ ### Setting Device Operating Mode
567
+
568
+ #### `set_operate_mode(mode)`
569
+
570
+ - **Description**: Sets the device’s operating mode.
571
+ - **Parameters**:
572
+
573
+ - mode (int): Operating mode (0 for normal mode, 1 for interlock mode).
574
+
575
+ - **Return Value**:
576
+ - bool: Returns `True` if the command is successful, otherwise `False`.
577
+
578
+ - **注意:**
579
+ - In interlock mode, control can only be done using interlock commands.
580
+
581
+ - **Example**:
582
+
583
+ Set the device to normal mode:
584
+
585
+ ```python
586
+ hub.set_operate_mode(0)
587
+ ```
588
+
589
+
590
+
591
+ ### Set Device Address
592
+
593
+ #### `set_device_address(address)`
594
+
595
+ - **Description**: The device address is used to identify and distinguish each hub when multiple hubs are connected.
596
+
597
+ - **Parameter**:
598
+
599
+ - `int`: The address is user-defined and should be within the range `0x0000 - 0xFFFF`.
600
+
601
+ - **Return Value**:
602
+
603
+ - `int` or `None`: Returns `1` if successful, `0` if failed, or `None` if no response.
604
+
605
+ - **Note**:
606
+
607
+ - When a `SmartUSBHub` instance is created, the device address is automatically retrieved. Different instances can be distinguished by their unique addresses.
608
+
609
+ - **Example**:
610
+
611
+ Set the device address to `0x0001`:
612
+
613
+ ```python
614
+ hub.set_device_address(0x0001)
615
+
616
+
617
+
618
+ ### Get Device Address
619
+
620
+ #### `get_device_address()`
621
+
622
+ - **Description**: Retrieves the address of the connected device.
623
+
624
+ - **Return Value**:
625
+
626
+ - `int` or `None`: The device address, or `None` if no response is received.
627
+
628
+ - **Example**:
629
+
630
+ Query the device address:
631
+
632
+ ```python
633
+ device_address = hub.get_device_address()
634
+ ```
635
+
636
+
637
+
638
+ ### Getting Device Operating Mode
639
+
640
+ #### `get_operate_mode()`
641
+
642
+ - **Description**: Queries the device’s current operating mode.
643
+
644
+ - **Return Value**:
645
+ - `int` or `None`: The current operating mode. Returns `None` if no response.
646
+
647
+ - **Example**:
648
+
649
+ Check the device’s operating mode:
650
+
651
+ ```python
652
+ mode = hub.get_operate_mode()
653
+ ```
654
+
655
+
656
+
657
+ ### Getting Device Information
658
+
659
+ #### `get_device_info()`
660
+
661
+ - **Description**: Retrieves the hub’s ID, hardware version, firmware version, operating mode, and button control status.
662
+ - **Return Value**:
663
+ - `dict`: A dictionary containing the device information.
664
+ - **Example**:
665
+ ```python
666
+ info = hub.get_device_info()
667
+ print(info)
668
+ ```
669
+
670
+
671
+
672
+ ### Getting Firmware Version
673
+
674
+ #### `get_firmware_version()`
675
+
676
+ - **Description**: Queries the device’s firmware version.
677
+ - **Return Value**:
678
+ - `int` or `None`: The firmware version. Returns None if no response.
679
+ - **Example**:
680
+ ```python
681
+ firmware_version = hub.get_firmware_version()
682
+ ```
683
+
684
+
685
+
686
+ ### Getting Hardware Version
687
+
688
+ #### `get_hardware_version()`
689
+
690
+ - **Description**: Queries the device’s hardware version.
691
+ - **Return Value**:
692
+ - `int` or `None`: The hardware version. Returns `None` if no response.
693
+ - **Example**:
694
+ ```python
695
+ hardware_version = hub.get_hardware_version()
696
+ ```
697
+
698
+
699
+
700
+ ### Registering User Callback
701
+
702
+ #### `register_callback(cmd, callback)`
703
+
704
+ - **Description**: Registers a user callback function for a specified command. When the device returns an ACK for that command, the callback function will be triggered.
705
+
706
+ - **Parameters**:
707
+
708
+ - cmd (int): The command for which to register the callback.
709
+ - callback (function): The callback function to execute when the command’s ACK is received. The callback function should accept two parameters:
710
+ - channel (int): The channel number that triggered the callback.
711
+ - status (int): The status value of that channel.
712
+
713
+ - **Return Value:**
714
+
715
+ - (None)
716
+
717
+ - **Notes**:
718
+
719
+ - If cmd is not in the supported command list, a warning will be logged and the callback will not be registered.
720
+
721
+
722
+
723
+ | CMD | **Meaning** |
724
+ | :------------------------------ | :------------------------------------------- |
725
+ | CMD_GET_CHANNEL_POWER_STATUS | Get channel power status |
726
+ | CMD_SET_CHANNEL_POWER | Control channel power |
727
+ | CMD_SET_CHANNEL_POWER_INTERLOCK | Control channel power interlock |
728
+ | CMD_SET_CHANNEL_DATALINE | Control channel USB data line switch |
729
+ | CMD_GET_CHANNEL_DATALINE_STATUS | Get channel USB data line switch status |
730
+ | CMD_GET_CHANNEL_VOLTAGE | Get channel voltage |
731
+ | CMD_GET_CHANNEL_CURRENT | Get channel current |
732
+ | CMD_SET_BUTTON_CONTROL | Enable/disable button control |
733
+ | CMD_GET_BUTTON_CONTROL_STATUS | Get button control status |
734
+ | CMD_SET_DEFAULT_POWER_STATUS | Set channel default power status |
735
+ | CMD_GET_DEFAULT_POWER_STATUS | Get channel default power status |
736
+ | CMD_SET_DEFAULT_DATALINE_STATUS | Set channel default data line status |
737
+ | CMD_GET_DEFAULT_DATALINE_STATUS | Get channel default data line status |
738
+ | CMD_SET_AUTO_RESTORE | Enable/disable power-loss auto restore |
739
+ | CMD_GET_AUTO_RESTORE_STATUS | Get power-loss auto restore status |
740
+ | CMD_SET_OPERATE_MODE | Set device operating mode (normal/interlock) |
741
+ | CMD_GET_OPERATE_MODE | Get device operating mode |
742
+ | CMD_FACTORY_RESET | Restore factory settings |
743
+ | CMD_GET_FIRMWARE_VERSION | Get firmware version |
744
+ | CMD_GET_HARDWARE_VERSION | Get hardware version |
745
+
746
+ - **Example**:
747
+
748
+ Set a button press callback; when the button is pressed, a callback is triggered:
749
+
750
+ ```python
751
+ def button_press_callback(channel, status):
752
+ print("Button press detected on channel", channel, "with power status", status)
753
+
754
+ hub.register_callback(CMD_GET_CHANNEL_POWER_STATUS, button_press_callback)
755
+ ```
756
+