gea-pushbutton-hmi 1.0.0__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.
- gea_pushbutton_hmi-1.0.0/PKG-INFO +562 -0
- gea_pushbutton_hmi-1.0.0/README.md +508 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/__init__.py +67 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/cli.py +101 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/commands/base.py +13 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/commands/color.py +228 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/commands/control_mode.py +29 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/commands/luminosity.py +69 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/commands/system_config.py +33 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/core/constants.py +127 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/core/device_manager.py +170 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/core/exceptions.py +21 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/core/protocol.py +187 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/examples/basic_usage.py +171 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/examples/color_effect.py +57 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/examples/color_transition.py +175 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/examples/quick_example.py +151 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/examples/quick_start.py +47 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/models/device_state.py +23 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi/py.typed +0 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/PKG-INFO +562 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/SOURCES.txt +27 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/dependency_links.txt +1 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/entry_points.txt +6 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/requires.txt +21 -0
- gea_pushbutton_hmi-1.0.0/gea_pushbutton_hmi.egg-info/top_level.txt +1 -0
- gea_pushbutton_hmi-1.0.0/pyproject.toml +82 -0
- gea_pushbutton_hmi-1.0.0/setup.cfg +4 -0
- gea_pushbutton_hmi-1.0.0/setup.py +4 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gea-pushbutton-hmi
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Industrial RS-485 driver library for PB-DEV-HMI push-button LED light controllers (firmware 4.1+, PIC24FV)
|
|
5
|
+
Author-email: BASIT AKRAM <basit.akram@gaengineering.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gea-engineering/gea-pushbutton-hmi
|
|
8
|
+
Project-URL: Documentation, https://github.com/gea-engineering/gea-pushbutton-hmi#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/gea-engineering/gea-pushbutton-hmi
|
|
10
|
+
Project-URL: Changelog, https://github.com/gea-engineering/gea-pushbutton-hmi/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/gea-engineering/gea-pushbutton-hmi/issues
|
|
12
|
+
Keywords: pushbutton,led,hmi,rs485,uart,pic24fv,lighting-control,serial,industrial,modbus-alternative,driver
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Manufacturing
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
18
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Operating System :: MacOS
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
28
|
+
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
|
|
29
|
+
Classifier: Topic :: System :: Hardware :: Hardware Drivers
|
|
30
|
+
Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB)
|
|
31
|
+
Classifier: Typing :: Typed
|
|
32
|
+
Classifier: Environment :: Console
|
|
33
|
+
Classifier: Environment :: Win32 (MS Windows)
|
|
34
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
35
|
+
Requires-Python: >=3.9
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
Requires-Dist: pyserial>=3.5
|
|
38
|
+
Provides-Extra: gui
|
|
39
|
+
Requires-Dist: PyQt5>=5.15.0; extra == "gui"
|
|
40
|
+
Provides-Extra: excel
|
|
41
|
+
Requires-Dist: pandas>=1.5; extra == "excel"
|
|
42
|
+
Requires-Dist: openpyxl>=3.1; extra == "excel"
|
|
43
|
+
Provides-Extra: all
|
|
44
|
+
Requires-Dist: PyQt5>=5.15.0; extra == "all"
|
|
45
|
+
Requires-Dist: pandas>=1.5; extra == "all"
|
|
46
|
+
Requires-Dist: openpyxl>=3.1; extra == "all"
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
49
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
50
|
+
Requires-Dist: ruff; extra == "dev"
|
|
51
|
+
Requires-Dist: mypy; extra == "dev"
|
|
52
|
+
Requires-Dist: build; extra == "dev"
|
|
53
|
+
Requires-Dist: twine; extra == "dev"
|
|
54
|
+
|
|
55
|
+
# Push Button Light Control API (PB_API)
|
|
56
|
+
|
|
57
|
+
A high-level Python API for controlling Push Button Light controller devices with PIC24FV16KM202 microcontroller using custom UART protocol. This library provides an intuitive interface for LED color and luminosity control in industrial and automation applications.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
🎨 Intuitive Color Control - Set LED colors using named presets or custom RGB values
|
|
61
|
+
|
|
62
|
+
💡 Luminosity Management - Control brightness with presets and smooth fading
|
|
63
|
+
|
|
64
|
+
🔄 Multiple Control Modes - Support for UART, Switch, Analog, and PWM modes
|
|
65
|
+
|
|
66
|
+
📡 Multi-Device Support - Control individual devices or broadcast to all
|
|
67
|
+
|
|
68
|
+
🔒 Thread-Safe - Safe for use in GUI applications and multi-threaded environments
|
|
69
|
+
|
|
70
|
+
⚡ Event-Driven - Callback system for asynchronous responses
|
|
71
|
+
|
|
72
|
+
🛡️ Robust Error Handling - Comprehensive error reporting and recovery
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
### From PyPI (Recommended)
|
|
77
|
+
|
|
78
|
+
$ pip install push-button-light-control
|
|
79
|
+
|
|
80
|
+
### From Source
|
|
81
|
+
|
|
82
|
+
https://pypi.org/project/push-button-light-control/#push_button_light_control-1.1.3.tar.gz
|
|
83
|
+
|
|
84
|
+
Extract push_button_light_control-1.1.3.tar.gz
|
|
85
|
+
|
|
86
|
+
$ cd push_button_light_control-1.1.3
|
|
87
|
+
|
|
88
|
+
$ pip install -e .
|
|
89
|
+
|
|
90
|
+
# 🚀 Quick Start
|
|
91
|
+
|
|
92
|
+
This example provides a complete demonstration of how to connect, control, and test your Push Button Light device using the PushButtonLightControl API.
|
|
93
|
+
It covers connection setup, control mode configuration, LED color sequencing, brightness adjustment, and built-in luminosity presets.
|
|
94
|
+
|
|
95
|
+
## Basic Usage
|
|
96
|
+
|
|
97
|
+
from pb_api import PushButtonLightControl
|
|
98
|
+
|
|
99
|
+
## Initialize and connect
|
|
100
|
+
|
|
101
|
+
pb = PushButtonLightControl('COM3') # Replace with your COM port
|
|
102
|
+
|
|
103
|
+
pb.connect()
|
|
104
|
+
|
|
105
|
+
## Set all LEDs to white at 50% brightness
|
|
106
|
+
|
|
107
|
+
device_ID = 1
|
|
108
|
+
|
|
109
|
+
pb.color.set_all_leds_color(device_ID, 'WHITE')
|
|
110
|
+
|
|
111
|
+
pb.luminosity.set_all_luminosity(device_ID, 50)
|
|
112
|
+
|
|
113
|
+
## Disconnect when done
|
|
114
|
+
|
|
115
|
+
pb.disconnect()
|
|
116
|
+
|
|
117
|
+
## Complete Example
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
#!/usr/bin/env python3
|
|
121
|
+
"""
|
|
122
|
+
Basic usage example for Push Button Light Control API
|
|
123
|
+
Fixed connection and error handling
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
import time
|
|
127
|
+
import sys
|
|
128
|
+
import os
|
|
129
|
+
|
|
130
|
+
# Add parent directory to path for local development
|
|
131
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
132
|
+
|
|
133
|
+
from pb_api import PushButtonLightControl, CTRL_UART, CTRL_SW_LUMIN, LED_UR, LED_UL, LED_LR, LED_LL
|
|
134
|
+
|
|
135
|
+
def main():
|
|
136
|
+
print("Starting Push Button Light Control Demo")
|
|
137
|
+
print("=" * 40)
|
|
138
|
+
|
|
139
|
+
# Initialize API with longer timeout
|
|
140
|
+
pb = PushButtonLightControl('COM6', timeout=3.0) # Change port as needed
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
# Connect to device
|
|
144
|
+
print("1. Connecting to device...")
|
|
145
|
+
if pb.connect():
|
|
146
|
+
print("✓ Connected successfully!")
|
|
147
|
+
else:
|
|
148
|
+
print("✗ Connection failed, but continuing anyway...")
|
|
149
|
+
# Don't return - try to continue
|
|
150
|
+
|
|
151
|
+
# Small delay after connection
|
|
152
|
+
time.sleep(1.0)
|
|
153
|
+
|
|
154
|
+
# Set to UART control mode
|
|
155
|
+
print("\n2. Setting UART control mode...")
|
|
156
|
+
try:
|
|
157
|
+
success = pb.control_mode.set_control_mode(1, CTRL_UART)
|
|
158
|
+
time.sleep(0.3)
|
|
159
|
+
if success:
|
|
160
|
+
print("✓ Control mode set successfully")
|
|
161
|
+
else:
|
|
162
|
+
print("⚠ Control mode setting may have failed, continuing...")
|
|
163
|
+
except Exception as e:
|
|
164
|
+
print(f"⚠ Control mode error: {e}, continuing...")
|
|
165
|
+
|
|
166
|
+
pb.color.set_all_leds_color(1, 'OFF')
|
|
167
|
+
time.sleep(0.3)
|
|
168
|
+
pb.luminosity.set_all_luminosity(1, 0)
|
|
169
|
+
time.sleep(1.0)
|
|
170
|
+
|
|
171
|
+
# Set LED colors
|
|
172
|
+
print("\n3. Setting LED colors...")
|
|
173
|
+
|
|
174
|
+
try:
|
|
175
|
+
pb.luminosity.set_all_luminosity(1, 100)
|
|
176
|
+
time.sleep(0.3)
|
|
177
|
+
|
|
178
|
+
pb.color.set_led_color(1, LED_UR, 'GREEN')
|
|
179
|
+
print("✓ UR LED set to GREEN")
|
|
180
|
+
time.sleep(0.2)
|
|
181
|
+
|
|
182
|
+
pb.color.set_led_color(1, LED_UL, 'ORANGE')
|
|
183
|
+
print("✓ UL LED set to ORANGE")
|
|
184
|
+
time.sleep(0.2)
|
|
185
|
+
|
|
186
|
+
pb.color.set_led_color(1, LED_LL, 'RED')
|
|
187
|
+
print("✓ LL LED set to RED")
|
|
188
|
+
time.sleep(0.2)
|
|
189
|
+
|
|
190
|
+
pb.color.set_led_color(1, LED_LR, 'MAGENTA')
|
|
191
|
+
print("✓ LR LED set to MAGENTA")
|
|
192
|
+
time.sleep(0.2)
|
|
193
|
+
|
|
194
|
+
pb.color.set_led_color(1, LED_UR, 'GREEN')
|
|
195
|
+
print("✓ UR LED set to GREEN")
|
|
196
|
+
time.sleep(0.2)
|
|
197
|
+
|
|
198
|
+
pb.color.set_led_color(1, LED_UL, 'ORANGE')
|
|
199
|
+
print("✓ UL LED set to ORANGE")
|
|
200
|
+
time.sleep(0.2)
|
|
201
|
+
|
|
202
|
+
pb.color.set_led_color(1, LED_LL, 'RED')
|
|
203
|
+
print("✓ LL LED set to RED")
|
|
204
|
+
time.sleep(0.2)
|
|
205
|
+
|
|
206
|
+
pb.color.set_led_color(1, LED_LR, 'MAGENTA')
|
|
207
|
+
print("✓ LR LED set to MAGENTA")
|
|
208
|
+
time.sleep(0.2)
|
|
209
|
+
|
|
210
|
+
print("\nSetting LED luminosity...")
|
|
211
|
+
|
|
212
|
+
# Set all LEDs to same color and brightness
|
|
213
|
+
pb.color.set_all_leds_color(1, 'BLUE')
|
|
214
|
+
time.sleep(0.2)
|
|
215
|
+
|
|
216
|
+
pb.color.set_all_leds_color(1, 'RED')
|
|
217
|
+
time.sleep(0.2)
|
|
218
|
+
|
|
219
|
+
pb.color.set_all_leds_color(1, 'GREEN')
|
|
220
|
+
time.sleep(0.2)
|
|
221
|
+
|
|
222
|
+
except Exception as e:
|
|
223
|
+
print(f"⚠ Color setting error: {e}")
|
|
224
|
+
|
|
225
|
+
# Set luminosity
|
|
226
|
+
print("\n4. Setting luminosity to MAX...")
|
|
227
|
+
try:
|
|
228
|
+
pb.color.set_all_leds_color(1, 'WHITE')
|
|
229
|
+
time.sleep(0.2)
|
|
230
|
+
pb.luminosity.set_all_luminosity(1, 100)
|
|
231
|
+
print("✓ Luminosity set to 100%")
|
|
232
|
+
time.sleep(0.2)
|
|
233
|
+
except Exception as e:
|
|
234
|
+
print(f"⚠ Luminosity error: {e}")
|
|
235
|
+
|
|
236
|
+
# Test presets
|
|
237
|
+
print("\n5. Testing presets...")
|
|
238
|
+
presets = ["DAY", "NIGHT", "OFF"]
|
|
239
|
+
|
|
240
|
+
for preset in presets:
|
|
241
|
+
try:
|
|
242
|
+
pb.luminosity.set_luminosity_preset(1, preset)
|
|
243
|
+
print(f"✓ Preset {preset} set")
|
|
244
|
+
time.sleep(0.5)
|
|
245
|
+
except Exception as e:
|
|
246
|
+
print(f"⚠ Preset {preset} error: {e}")
|
|
247
|
+
|
|
248
|
+
print("\n" + "=" * 40)
|
|
249
|
+
print("Demo completed!")
|
|
250
|
+
|
|
251
|
+
except Exception as e:
|
|
252
|
+
print(f"\n💥 Demo failed with exception: {e}")
|
|
253
|
+
import traceback
|
|
254
|
+
traceback.print_exc()
|
|
255
|
+
finally:
|
|
256
|
+
pb.disconnect()
|
|
257
|
+
print("Disconnected from device")
|
|
258
|
+
|
|
259
|
+
if __name__ == "__main__":
|
|
260
|
+
main()
|
|
261
|
+
|
|
262
|
+
# ▶️ Running the Example
|
|
263
|
+
|
|
264
|
+
After installation:
|
|
265
|
+
|
|
266
|
+
## Run the quick start demo
|
|
267
|
+
|
|
268
|
+
$ python -m pb_api.examples.quick_start
|
|
269
|
+
|
|
270
|
+
# 📘 API Overview
|
|
271
|
+
|
|
272
|
+
The following table describes the key variables, constants, and methods used in the example:
|
|
273
|
+
|
|
274
|
+
| **Element** | **Description** |
|
|
275
|
+
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
276
|
+
| `PushButtonLightControl` | Main API class for connecting and communicating with the Push Button Light device. |
|
|
277
|
+
| `'COM6'` | Serial port name. Replace with your actual port (e.g. `'COM3'` on Windows or `'/dev/ttyUSB0'` on Linux). |
|
|
278
|
+
| `timeout=3.0` | Response timeout for device communication (in seconds). |
|
|
279
|
+
| `CTRL_UART` | Control mode constant for UART (software-controlled) operation. |
|
|
280
|
+
| `LED_UR`, `LED_UL`, `LED_LR`, `LED_LL` | LED position constants: Upper Right, Upper Left, Lower Right, Lower Left. |
|
|
281
|
+
| `pb.connect(com_port, baudrate)` | Opens a serial connection to the device. Returns `True` on success. |
|
|
282
|
+
| `pb.control_mode.set_control_mode(device_id, CTRL_UART)` | Sets device ID `1` to UART control mode. |
|
|
283
|
+
| `pb.color.set_led_color(device_id, led_name, led_color)` | Sets individual LED color by device ID, LED position, and color name. |
|
|
284
|
+
| `pb.color.set_all_leds_color(device_id, led_color)` | Sets all LEDs on a device (or all devices) to the same color. |
|
|
285
|
+
| `pb.luminosity.set_all_luminosity(device_id, lumin_val)` | Adjusts brightness (0–100%) for all LEDs. |
|
|
286
|
+
| `pb.luminosity.set_luminosity_preset(device_id, lumin_preset)` | Applies a predefined brightness preset: `"DAY"`, `"NIGHT"`, `"OFF"`, or `"MAX"`. |
|
|
287
|
+
| `register_callback(event, callback)` | Registers a callback function to handle specific events such as responses or errors. |
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
## Predefined color presets
|
|
291
|
+
|
|
292
|
+
"OFF", "RED", "GREEN", "BLUE", "WHITE", "ORANGE", "MAGENTA", "CYAN"
|
|
293
|
+
|
|
294
|
+
## Predefined luminosity levels
|
|
295
|
+
|
|
296
|
+
"OFF" # 0%
|
|
297
|
+
"NIGHT" # 20% (e.g., 20fL)
|
|
298
|
+
"DAY" # 50% (e.g., 150fL)
|
|
299
|
+
"MAX" # 100%
|
|
300
|
+
|
|
301
|
+
# Detailed Usage Guide
|
|
302
|
+
|
|
303
|
+
# 1. Connecting to Devices
|
|
304
|
+
|
|
305
|
+
from pb_api import PushButtonLightControl
|
|
306
|
+
|
|
307
|
+
## Basic connection
|
|
308
|
+
|
|
309
|
+
pb = PushButtonLightControl('COM3')
|
|
310
|
+
|
|
311
|
+
pb.connect()
|
|
312
|
+
|
|
313
|
+
## With custom baudrate and timeout
|
|
314
|
+
|
|
315
|
+
pb = PushButtonLightControl('COM3', timeout=2.0)
|
|
316
|
+
|
|
317
|
+
pb.connect()
|
|
318
|
+
|
|
319
|
+
## Check connection status
|
|
320
|
+
|
|
321
|
+
if pb.is_connected():
|
|
322
|
+
|
|
323
|
+
print("Device connected")
|
|
324
|
+
|
|
325
|
+
# 2. Setting Control Modes
|
|
326
|
+
|
|
327
|
+
from pb_api import CTRL_UART, CTRL_SW_LUMIN, CTRL_SW_AN0, CTRL_SW_PWM
|
|
328
|
+
|
|
329
|
+
## Set UART mode (full software control)
|
|
330
|
+
|
|
331
|
+
pb.control_mode.set_control_mode(1, CTRL_UART)
|
|
332
|
+
|
|
333
|
+
## Set Switch + Luminance mode
|
|
334
|
+
|
|
335
|
+
pb.control_mode.set_control_mode(1, CTRL_SW_LUMIN)
|
|
336
|
+
|
|
337
|
+
## Set Switch + Analog mode
|
|
338
|
+
|
|
339
|
+
pb.control_mode.set_control_mode(1, CTRL_SW_AN0)
|
|
340
|
+
|
|
341
|
+
## Set Switch + PWM mode
|
|
342
|
+
|
|
343
|
+
pb.control_mode.set_control_mode(1, CTRL_SW_PWM)
|
|
344
|
+
|
|
345
|
+
# 3. Color Control
|
|
346
|
+
|
|
347
|
+
## Using Color Presets
|
|
348
|
+
|
|
349
|
+
### Set individual LED colors
|
|
350
|
+
|
|
351
|
+
pb.color.set_led_color(1, 0, 'RED') # UR LED - Red
|
|
352
|
+
|
|
353
|
+
pb.color.set_led_color(1, 1, 'GREEN') # UL LED - Green
|
|
354
|
+
|
|
355
|
+
pb.color.set_led_color(1, 2, 'BLUE') # LR LED - Blue
|
|
356
|
+
|
|
357
|
+
pb.color.set_led_color(1, 3, 'WHITE') # LL LED - White
|
|
358
|
+
|
|
359
|
+
### Set all LEDs to same color
|
|
360
|
+
|
|
361
|
+
pb.color.set_all_leds_color(1, 'WHITE')
|
|
362
|
+
|
|
363
|
+
### Broadcast to all devices
|
|
364
|
+
|
|
365
|
+
pb.color.set_all_leds_color(0, 'BLUE') # 0 = broadcast ID
|
|
366
|
+
|
|
367
|
+
### Set custom RGB color (values 0-100)
|
|
368
|
+
|
|
369
|
+
pb.color.set_custom_rgb_color(1, 0, red=100, green=50, blue=25) # UR LED
|
|
370
|
+
|
|
371
|
+
# 4. Luminosity Control
|
|
372
|
+
|
|
373
|
+
## Basic Brightness Control
|
|
374
|
+
|
|
375
|
+
### Set individual LED brightness
|
|
376
|
+
|
|
377
|
+
pb.luminosity.set_led_luminosity(1, 0, 100) # UR LED - 100%
|
|
378
|
+
|
|
379
|
+
pb.luminosity.set_led_luminosity(1, 1, 75) # UL LED - 75%
|
|
380
|
+
|
|
381
|
+
pb.luminosity.set_led_luminosity(1, 2, 50) # LR LED - 50%
|
|
382
|
+
|
|
383
|
+
pb.luminosity.set_led_luminosity(1, 3, 25) # LL LED - 25%
|
|
384
|
+
|
|
385
|
+
### Set all LEDs to same brightness
|
|
386
|
+
|
|
387
|
+
pb.luminosity.set_all_luminosity(1, 80) # All LEDs at 80%
|
|
388
|
+
|
|
389
|
+
### Turn off all LEDs (0% brightness)
|
|
390
|
+
|
|
391
|
+
pb.luminosity.set_all_luminosity(1, 0)
|
|
392
|
+
|
|
393
|
+
## Using Presets
|
|
394
|
+
|
|
395
|
+
### Use predefined luminosity levels
|
|
396
|
+
|
|
397
|
+
pb.luminosity.set_luminosity_preset(1, "NIGHT") # 20% brightness
|
|
398
|
+
|
|
399
|
+
pb.luminosity.set_luminosity_preset(1, "DAY") # 50% brightness
|
|
400
|
+
|
|
401
|
+
pb.luminosity.set_luminosity_preset(1, "MAX") # 100% brightness
|
|
402
|
+
|
|
403
|
+
pb.luminosity.set_luminosity_preset(1, "OFF") # 0% brightness
|
|
404
|
+
|
|
405
|
+
## Advanced Effects
|
|
406
|
+
|
|
407
|
+
### Smooth fade between brightness levels
|
|
408
|
+
|
|
409
|
+
pb.luminosity.fade_luminosity(1, 0, 100, steps=20, delay=0.05)
|
|
410
|
+
|
|
411
|
+
# 5. System Configuration
|
|
412
|
+
|
|
413
|
+
## Set luminosity presets for switch control mode
|
|
414
|
+
|
|
415
|
+
pb.system_config.set_luminosity_percentages(
|
|
416
|
+
|
|
417
|
+
device_id=1,
|
|
418
|
+
|
|
419
|
+
max_percent=100, # Maximum brightness
|
|
420
|
+
|
|
421
|
+
day_percent=50, # Daytime brightness
|
|
422
|
+
|
|
423
|
+
night_percent=20 # Nighttime brightness
|
|
424
|
+
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
## Using raw 12-bit values (0-4095)
|
|
428
|
+
|
|
429
|
+
pb.system_config.set_luminosity_presets(1, 4095, 2047, 819)
|
|
430
|
+
|
|
431
|
+
# 6. Event Handling and Callbacks
|
|
432
|
+
|
|
433
|
+
def response_handler(data):
|
|
434
|
+
|
|
435
|
+
"""Handle device responses"""
|
|
436
|
+
|
|
437
|
+
print(f"Device response: {data}")
|
|
438
|
+
|
|
439
|
+
def error_handler(data):
|
|
440
|
+
|
|
441
|
+
"""Handle errors"""
|
|
442
|
+
|
|
443
|
+
print(f"Error occurred: {data}")
|
|
444
|
+
|
|
445
|
+
def connection_handler():
|
|
446
|
+
|
|
447
|
+
"""Handle connection events"""
|
|
448
|
+
|
|
449
|
+
print("Device connected")
|
|
450
|
+
|
|
451
|
+
## Register callbacks
|
|
452
|
+
|
|
453
|
+
pb.register_callback('response_received', response_handler)
|
|
454
|
+
|
|
455
|
+
pb.register_callback('error', error_handler)
|
|
456
|
+
|
|
457
|
+
pb.register_callback('connected', connection_handler)
|
|
458
|
+
|
|
459
|
+
# 7. Multi-Device Management
|
|
460
|
+
|
|
461
|
+
## Control specific device
|
|
462
|
+
|
|
463
|
+
pb.color.set_led_color(1, 0, 'RED') # Device 1
|
|
464
|
+
|
|
465
|
+
pb.color.set_led_color(2, 0, 'GREEN') # Device 2
|
|
466
|
+
|
|
467
|
+
pb.color.set_led_color(3, 0, 'BLUE') # Device 3
|
|
468
|
+
|
|
469
|
+
## Broadcast to all devices (device ID 0)
|
|
470
|
+
|
|
471
|
+
pb.color.set_all_leds_color(0, 'WHITE')
|
|
472
|
+
|
|
473
|
+
pb.luminosity.set_all_luminosity(0, 50)
|
|
474
|
+
|
|
475
|
+
## LED Position Constants
|
|
476
|
+
|
|
477
|
+
from pb_api import LED_UR, LED_UL, LED_LR, LED_LL
|
|
478
|
+
|
|
479
|
+
## Use these constants for clear position references
|
|
480
|
+
|
|
481
|
+
pb.color.set_led_color(1, LED_UR, 'RED') # Upper Right
|
|
482
|
+
|
|
483
|
+
pb.color.set_led_color(1, LED_UL, 'GREEN') # Upper Left
|
|
484
|
+
|
|
485
|
+
pb.color.set_led_color(1, LED_LR, 'BLUE') # Lower Right
|
|
486
|
+
|
|
487
|
+
pb.color.set_led_color(1, LED_LL, 'WHITE') # Lower Left
|
|
488
|
+
|
|
489
|
+
## Error Handling
|
|
490
|
+
|
|
491
|
+
from pb_api import PushButtonError, CommunicationError, TimeoutError, DeviceError
|
|
492
|
+
|
|
493
|
+
try:
|
|
494
|
+
pb.connect()
|
|
495
|
+
|
|
496
|
+
pb.color.set_led_color(1, 0, 'RED')
|
|
497
|
+
|
|
498
|
+
except CommunicationError as e:
|
|
499
|
+
|
|
500
|
+
print(f"Connection failed: {e}")
|
|
501
|
+
|
|
502
|
+
except TimeoutError as e:
|
|
503
|
+
|
|
504
|
+
print(f"Device timeout: {e}")
|
|
505
|
+
|
|
506
|
+
except DeviceError as e:
|
|
507
|
+
|
|
508
|
+
print(f"Device error (Code: 0x{e.error_code:02x}): {e}")
|
|
509
|
+
|
|
510
|
+
except PushButtonError as e:
|
|
511
|
+
|
|
512
|
+
print(f"API error: {e}")
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
# Troubleshooting
|
|
516
|
+
|
|
517
|
+
## Common Issues
|
|
518
|
+
|
|
519
|
+
Device not found
|
|
520
|
+
|
|
521
|
+
Check COM port name
|
|
522
|
+
|
|
523
|
+
Verify device is connected and powered
|
|
524
|
+
|
|
525
|
+
Ensure no other application is using the port
|
|
526
|
+
|
|
527
|
+
Connection timeout
|
|
528
|
+
|
|
529
|
+
Check baudrate matches device configuration (usually 115200)
|
|
530
|
+
|
|
531
|
+
Verify cable connection
|
|
532
|
+
|
|
533
|
+
Check device power
|
|
534
|
+
|
|
535
|
+
Command not working
|
|
536
|
+
|
|
537
|
+
Ensure device is in UART mode
|
|
538
|
+
|
|
539
|
+
Check device ID is correct
|
|
540
|
+
|
|
541
|
+
Verify command parameters are within valid ranges
|
|
542
|
+
|
|
543
|
+
## Debug Mode
|
|
544
|
+
|
|
545
|
+
Enable debug output by setting environment variable:
|
|
546
|
+
|
|
547
|
+
export PB_API_DEBUG=1
|
|
548
|
+
|
|
549
|
+
# API Reference
|
|
550
|
+
|
|
551
|
+
## Documentation: GitHub Wiki
|
|
552
|
+
|
|
553
|
+
## Issues: GitHub Issues
|
|
554
|
+
|
|
555
|
+
### Email: basit.akram@gaenginering.com
|
|
556
|
+
|
|
557
|
+
## License
|
|
558
|
+
|
|
559
|
+
This project is licensed under the Public Domain MIT License - see the LICENSE file for details.
|
|
560
|
+
|
|
561
|
+
### Push Button Light Control API - Making LED control simple and intuitive for developers.
|
|
562
|
+
|