benchlab-pytools 3.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.
- benchlab/__init__.py +14 -0
- benchlab/__main__.py +21 -0
- benchlab/config/README.md +325 -0
- benchlab/config/__init__.py +9 -0
- benchlab/config/config_client.py +631 -0
- benchlab/config/config_manager.py +495 -0
- benchlab/config/config_tool.py +358 -0
- benchlab/config/diff.py +163 -0
- benchlab/config/examples/complete_config.json +56 -0
- benchlab/config/examples/rgb_lighting.json +24 -0
- benchlab/config/examples/simple_fan.json +32 -0
- benchlab/config/schema.py +138 -0
- benchlab/core/README.md +154 -0
- benchlab/core/__init__.py +78 -0
- benchlab/core/config.py +145 -0
- benchlab/core/datasource.py +1209 -0
- benchlab/core/datasource_manager.py +418 -0
- benchlab/core/device_registry.py +206 -0
- benchlab/core/discovery.py +92 -0
- benchlab/core/infrastructure.py +309 -0
- benchlab/core/process_manager.py +356 -0
- benchlab/core/retry.py +85 -0
- benchlab/core/shared_serial.py +235 -0
- benchlab/core/statistics.py +224 -0
- benchlab/csv_log/README.md +206 -0
- benchlab/csv_log/__init__.py +5 -0
- benchlab/csv_log/csv_logger_enhanced.py +416 -0
- benchlab/csv_log/message_batcher.py +361 -0
- benchlab/csv_log/requirements.txt +3 -0
- benchlab/csv_log/smart_retry.py +466 -0
- benchlab/graph/README.md +117 -0
- benchlab/graph/__init__.py +5 -0
- benchlab/graph/app.py +353 -0
- benchlab/graph/requirements.txt +2 -0
- benchlab/graph/runner.py +42 -0
- benchlab/graph/ui.py +288 -0
- benchlab/hwinfo/README.md +135 -0
- benchlab/hwinfo/__init__.py +5 -0
- benchlab/hwinfo/hwinfo_export.py +386 -0
- benchlab/hwinfo/requirements.txt +1 -0
- benchlab/launcher.py +387 -0
- benchlab/link/.env.EXAMPLE +10 -0
- benchlab/link/README.md +172 -0
- benchlab/link/__init__.py +1 -0
- benchlab/link/link_main.py +479 -0
- benchlab/main.py +462 -0
- benchlab/menu.py +729 -0
- benchlab/menu_classic.py +410 -0
- benchlab/mqtt/README.md +201 -0
- benchlab/mqtt/__init__.py +5 -0
- benchlab/mqtt/mqtt.config_template +2 -0
- benchlab/mqtt/mqtt_publisher.py +540 -0
- benchlab/mqtt/requirements.txt +3 -0
- benchlab/prefs.py +67 -0
- benchlab/restapi/.env.example +17 -0
- benchlab/restapi/__init__.py +5 -0
- benchlab/restapi/favicon.ico +0 -0
- benchlab/restapi/readme.md +202 -0
- benchlab/restapi/requirements.txt +5 -0
- benchlab/restapi/telemetry_api.py +808 -0
- benchlab/sources.py +515 -0
- benchlab/tools.py +147 -0
- benchlab/tui/README.md +266 -0
- benchlab/tui/__init__.py +5 -0
- benchlab/tui/config.py +477 -0
- benchlab/tui/requirements.txt +2 -0
- benchlab/tui/tui_core.py +1298 -0
- benchlab/tui/tui_main.py +418 -0
- benchlab/vu/README.md +64 -0
- benchlab/vu/VU-Server/NOTICE.md +13 -0
- benchlab/vu/VU-Server/README.md +80 -0
- benchlab/vu/VU-Server/Running_from_source_on_linux.md +97 -0
- benchlab/vu/VU-Server/__init__.py +0 -0
- benchlab/vu/VU-Server/assets/vu1_hello_world.png +0 -0
- benchlab/vu/VU-Server/community_applications.md +13 -0
- benchlab/vu/VU-Server/config.yaml +9 -0
- benchlab/vu/VU-Server/database.py +256 -0
- benchlab/vu/VU-Server/dial_driver.py +534 -0
- benchlab/vu/VU-Server/dials/Comms_Hub_Gauge.py +78 -0
- benchlab/vu/VU-Server/dials/Comms_Hub_Server.py +100 -0
- benchlab/vu/VU-Server/dials/__init__.py +0 -0
- benchlab/vu/VU-Server/dials/base_logger.py +100 -0
- benchlab/vu/VU-Server/installer/inc/icon.ico +0 -0
- benchlab/vu/VU-Server/installer/install.nsi +148 -0
- benchlab/vu/VU-Server/make_version.py +40 -0
- benchlab/vu/VU-Server/pylintrc +628 -0
- benchlab/vu/VU-Server/requirements.txt +9 -0
- benchlab/vu/VU-Server/serial_driver.py +244 -0
- benchlab/vu/VU-Server/server.py +670 -0
- benchlab/vu/VU-Server/server_config.py +255 -0
- benchlab/vu/VU-Server/server_dial_handler.py +334 -0
- benchlab/vu/VU-Server/vu_notifications.py +24 -0
- benchlab/vu/VU-Server/www/android-chrome-192x192.png +0 -0
- benchlab/vu/VU-Server/www/android-chrome-512x512.png +0 -0
- benchlab/vu/VU-Server/www/apple-touch-icon.png +0 -0
- benchlab/vu/VU-Server/www/assets/css/demo.css +291 -0
- benchlab/vu/VU-Server/www/assets/css/demo.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/demo.rtl.css +276 -0
- benchlab/vu/VU-Server/www/assets/css/demo.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.css +1084 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.css +1084 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.css +528 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.css +528 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.css +10 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.min.css +8 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.css +10 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.min.css +8 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.css +1504 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.css +1504 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.css +25813 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.min.css +13 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.rtl.css +25777 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.rtl.min.css +13 -0
- benchlab/vu/VU-Server/www/assets/css/theme.min.css +261 -0
- benchlab/vu/VU-Server/www/assets/img/header.png +0 -0
- benchlab/vu/VU-Server/www/assets/img/logo.png +0 -0
- benchlab/vu/VU-Server/www/assets/js/dark-theme.js +35 -0
- benchlab/vu/VU-Server/www/assets/js/dark-theme.min.js +9 -0
- benchlab/vu/VU-Server/www/assets/js/demo.js +132 -0
- benchlab/vu/VU-Server/www/assets/js/demo.min.js +9 -0
- benchlab/vu/VU-Server/www/assets/js/jquery.min.js +2 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.esm.js +7482 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.esm.min.js +15 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.js +7543 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.min.js +15 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_api.js +68 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_key_settings.js +167 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_keys.js +138 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_dial.js +179 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_home.js +60 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_root.js +125 -0
- benchlab/vu/VU-Server/www/favicon-16x16.png +0 -0
- benchlab/vu/VU-Server/www/favicon-32x32.png +0 -0
- benchlab/vu/VU-Server/www/favicon.ico +0 -0
- benchlab/vu/VU-Server/www/favicon.png +0 -0
- benchlab/vu/VU-Server/www/index.html +47 -0
- benchlab/vu/VU-Server/www/views/api_keys.html +151 -0
- benchlab/vu/VU-Server/www/views/dial.html +286 -0
- benchlab/vu/VU-Server/www/views/footer.html +27 -0
- benchlab/vu/VU-Server/www/views/header.html +86 -0
- benchlab/vu/VU-Server/www/views/key_settings.html +132 -0
- benchlab/vu/VU-Server/www/views/start.html +124 -0
- benchlab/vu/__init__.py +5 -0
- benchlab/vu/assets/Barlow-Bold.ttf +0 -0
- benchlab/vu/assets/bl_dial_144x200.png +0 -0
- benchlab/vu/assets/bl_logo_144x200.png +0 -0
- benchlab/vu/devices.py +166 -0
- benchlab/vu/requirements.txt +24 -0
- benchlab/vu/sensors.py +18 -0
- benchlab/vu/vu_dial.config_template +90 -0
- benchlab/vu/vu_logo_gen.py +97 -0
- benchlab/vu/vu_server.config_template +5 -0
- benchlab/vu/vu_server_config.py +40 -0
- benchlab/vu/vu_server_manager.py +192 -0
- benchlab/vu/vu_tui.py +919 -0
- benchlab/vu/vu_updater.py +540 -0
- benchlab/wigidash/README.md +182 -0
- benchlab/wigidash/__init__.py +5 -0
- benchlab/wigidash/assets/Inter-Bold.ttf +0 -0
- benchlab/wigidash/assets/Inter.ttf +0 -0
- benchlab/wigidash/assets/benchlab.png +0 -0
- benchlab/wigidash/benchlab_fleet.py +150 -0
- benchlab/wigidash/benchlab_graph.py +517 -0
- benchlab/wigidash/benchlab_overview.py +426 -0
- benchlab/wigidash/benchlab_telemetry.py +105 -0
- benchlab/wigidash/benchlab_ui.py +190 -0
- benchlab/wigidash/benchlab_utils.py +182 -0
- benchlab/wigidash/requirements.txt +9 -0
- benchlab/wigidash/wigidash_device.py +541 -0
- benchlab/wigidash/wigidash_manager.py +342 -0
- benchlab/wigidash/wigidash_session.py +355 -0
- benchlab/wigidash/wigidash_usb.py +247 -0
- benchlab/wigidash/wigidash_widget.py +88 -0
- benchlab_pytools-3.0.0.dist-info/METADATA +239 -0
- benchlab_pytools-3.0.0.dist-info/RECORD +184 -0
- benchlab_pytools-3.0.0.dist-info/WHEEL +4 -0
- benchlab_pytools-3.0.0.dist-info/entry_points.txt +2 -0
- benchlab_pytools-3.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Wigidash
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Wigidash is a Python-based telemetry dashboard for BENCHLAB devices, providing real-time and historical monitoring of sensors including voltage, current, power, and fans.
|
|
6
|
+
|
|
7
|
+
It automatically:
|
|
8
|
+
|
|
9
|
+
- Reads telemetry from connected BENCHLAB devices.
|
|
10
|
+
- Displays numeric data and fan metrics in an interactive dashboard.
|
|
11
|
+
- Plots historical data with timestamps.
|
|
12
|
+
- Allows touch or click interaction for metric selection and toggling.
|
|
13
|
+
- Handles multi-page navigation with headers, footers, and control buttons.
|
|
14
|
+
- Automatically scales graphs with support for negative and positive data.
|
|
15
|
+
- Ensures safe page transitions and prevents ghost touches.
|
|
16
|
+
|
|
17
|
+
Designed for engineers and system testers to monitor BENCHLAB telemetry effectively.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
| Feature | Description |
|
|
24
|
+
|---------|-------------|
|
|
25
|
+
| Real-time telemetry | Continuously updates sensor metrics on a live dashboard. |
|
|
26
|
+
| Historical graphing | Displays plots of previous data with timestamps or sample numbers. |
|
|
27
|
+
| Metric grouping | Automatically groups metrics by section: Power, Voltage, Current, Fans. |
|
|
28
|
+
| Fan metric handling | Supports Duty and RPM metrics with “All Duty” / “All RPM” toggles. |
|
|
29
|
+
| Touch-enabled UI | Allows metric selection and page navigation via touch or mouse. |
|
|
30
|
+
| Auto-scaled Y-axis | Graphs automatically scale with numeric data, including negative values. |
|
|
31
|
+
| Footer info panel | Shows device info, port, firmware version, and UID. |
|
|
32
|
+
| Page lifecycle management | Safely handles page start/stop and prevents input from other pages. |
|
|
33
|
+
| Graceful exit | Shutdown button or Ctrl+C closes the dashboard cleanly. |
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Install the required dependencies:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
pip install -r requirements.txt
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Dependencies include:
|
|
46
|
+
|
|
47
|
+
- Pillow
|
|
48
|
+
- Matplotlib
|
|
49
|
+
- NumPy
|
|
50
|
+
- pyserial
|
|
51
|
+
- pyusb
|
|
52
|
+
- libusb-package (Windows only — provides the libusb-1.0 backend pyusb needs)
|
|
53
|
+
- benchlab core modules
|
|
54
|
+
|
|
55
|
+
### Windows Setup
|
|
56
|
+
|
|
57
|
+
`pyusb` needs a `libusb-1.0` backend DLL, which isn't bundled with the `pyusb` pip package itself. `requirements.txt` includes `libusb-package`, which provides a prebuilt backend that `pyusb` auto-discovers — plain `pip install -r requirements.txt` in any standard Python environment (venv, system Python, etc.) is enough; no Anaconda/conda-forge install is required.
|
|
58
|
+
|
|
59
|
+
### Linux Setup
|
|
60
|
+
|
|
61
|
+
`pyusb` needs a working `libusb-1.0` backend and permission to access the WigiDash's USB device node as a non-root user.
|
|
62
|
+
|
|
63
|
+
1. Install libusb (relevant on minimal/ARM images, e.g. Raspberry Pi OS Lite, which may not ship it by default):
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
sudo apt install libusb-1.0-0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. Grant non-root USB access by creating `/etc/udev/rules.d/99-wigidash.rules`:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
SUBSYSTEM=="usb", ATTR{idVendor}=="28da", ATTR{idProduct}=="ef01", TAG+="uaccess"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then reload udev rules:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
sudo udevadm control --reload-rules && sudo udevadm trigger
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Without this rule, `pyusb` calls typically fail with an `Access denied (insufficient permissions)` USB error unless run as root. On startup, `scan_wigidash()` runs a best-effort check for this and logs an actionable warning (with the same rule text above) if it looks like access isn't set up — this is a diagnostic only, not a hard requirement check, since udev setups vary across distros.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Folder Structure
|
|
87
|
+
|
|
88
|
+
wigidash/
|
|
89
|
+
├─ README.md
|
|
90
|
+
├─ assets/ # Fonts, logos, and other UI resources
|
|
91
|
+
├─ __init__.py
|
|
92
|
+
├─ benchlab_fleet.py # Fleet selection UI
|
|
93
|
+
├─ benchlab_graph.py # Graph rendering and metric selection
|
|
94
|
+
├─ benchlab_overview.py # Overview page for system telemetry
|
|
95
|
+
├─ benchlab_telemetry.py # Data logging and historical telemetry handling
|
|
96
|
+
├─ benchlab_ui.py # Shared UI toolkit: theme, buttons, header/footer drawing
|
|
97
|
+
├─ benchlab_utils.py # Utilities for image display, logging, and device management
|
|
98
|
+
├─ wigidash_device.py # Device abstraction layer
|
|
99
|
+
├─ wigidash_manager.py # Top-level orchestrator: device discovery, session/telemetry management
|
|
100
|
+
├─ wigidash_session.py # Per-device UI session and page lifecycle
|
|
101
|
+
├─ wigidash_usb.py # USB communication layer
|
|
102
|
+
├─ wigidash_widget.py # Dashboard widget configuration
|
|
103
|
+
└─ requirements.txt
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
### Launch the Dashboard
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
python -m benchlab -wigidash
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
By default this connects via the `direct` (serial) data source. To use a different source, pass `--source` along with the matching connection flags:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
python -m benchlab -wigidash --source fastapi --api-url http://127.0.0.1:8000
|
|
120
|
+
python -m benchlab -wigidash --source mqtt --mqtt-broker localhost --mqtt-port 1883
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Supported `--source` values: `direct`, `fastapi`, `fastapi_custom` (via `DataSourceManager`, same as the other consumer tools).
|
|
124
|
+
|
|
125
|
+
Behavior:
|
|
126
|
+
|
|
127
|
+
- Detects all connected BENCHLAB devices via the selected data source.
|
|
128
|
+
- Displays the main overview page.
|
|
129
|
+
- Allows switching to the telemetry graph page for detailed metrics.
|
|
130
|
+
- Supports interactive metric selection and fan toggles.
|
|
131
|
+
- Updates the dashboard continuously until interrupted (`Ctrl+C`) or using the Shutdown button.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Developer Notes
|
|
136
|
+
|
|
137
|
+
### Page Lifecycle
|
|
138
|
+
|
|
139
|
+
- `start()` initializes the page and starts data updates.
|
|
140
|
+
- `stop()` stops updates and returns to overview.
|
|
141
|
+
- Touch input is filtered to only affect the active page.
|
|
142
|
+
- Optional 0.5-second delay prevents ghost touches during page transitions.
|
|
143
|
+
|
|
144
|
+
### Graphing
|
|
145
|
+
|
|
146
|
+
- Uses Matplotlib to plot numeric metrics over time.
|
|
147
|
+
- Graph Y-axis is automatically scaled; zero is the default minimum unless negative values are present.
|
|
148
|
+
- X-axis shows timestamps or sample numbers depending on history data availability.
|
|
149
|
+
- Legends and units are automatically generated from available metrics.
|
|
150
|
+
|
|
151
|
+
### Touch Handling
|
|
152
|
+
|
|
153
|
+
- `check_touch()` validates touches against active buttons.
|
|
154
|
+
- Supports toggling individual metrics or grouped fan metrics.
|
|
155
|
+
- Footer buttons execute callbacks such as `Shutdown` or returning to the overview page.
|
|
156
|
+
|
|
157
|
+
### Logging
|
|
158
|
+
|
|
159
|
+
- Logs page lifecycle events, metric updates, and touch interactions.
|
|
160
|
+
- Warnings for missing assets (fonts, logos) are logged.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Contributions are welcome! Please fork the repository and submit a pull request with clear descriptions of changes. Ensure your code follows existing style and passes all tests.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
This project is licensed under MIT License. See the LICENSE file for details.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## References
|
|
177
|
+
|
|
178
|
+
- [Pillow](https://pypi.org/project/Pillow/)
|
|
179
|
+
- [Matplotlib](https://matplotlib.org/)
|
|
180
|
+
- [NumPy](https://numpy.org/)
|
|
181
|
+
- [pyserial](https://pypi.org/project/pyserial/)
|
|
182
|
+
- [pyusb](https://pypi.org/project/pyusb/)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# benchlab_fleet.py
|
|
2
|
+
|
|
3
|
+
from PIL import Image, ImageDraw
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
from benchlab.wigidash.benchlab_ui import (
|
|
7
|
+
load_fonts, draw_header, draw_footer, bind_button, load_logo, UIButton
|
|
8
|
+
)
|
|
9
|
+
from benchlab.wigidash.benchlab_utils import (
|
|
10
|
+
display_image, get_logger, KeepAliveManager
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
logger = get_logger("BenchlabFleet")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BenchlabFleetSelect:
|
|
17
|
+
|
|
18
|
+
def __init__(self, wigidash, fleet_manager=None, wigi=None, on_exit=None):
|
|
19
|
+
self.wigidash = wigidash
|
|
20
|
+
self.wigi = wigi
|
|
21
|
+
self.running = False
|
|
22
|
+
self.selected_port = None
|
|
23
|
+
self.manager = fleet_manager
|
|
24
|
+
self.on_exit = on_exit
|
|
25
|
+
self.last_tap_time = 0
|
|
26
|
+
self.last_touch_time = 0
|
|
27
|
+
self.keepalive = KeepAliveManager(self.wigidash)
|
|
28
|
+
|
|
29
|
+
# Fonts and logo from central UI
|
|
30
|
+
self.ui_fonts = load_fonts()
|
|
31
|
+
self.ui_logo = load_logo()
|
|
32
|
+
|
|
33
|
+
# Build fleet cache
|
|
34
|
+
self.fleet_cache = []
|
|
35
|
+
if self.manager:
|
|
36
|
+
# Refresh the manager's device cache to ensure we have current data
|
|
37
|
+
self.manager.get_available_benchlabs(log_info=False)
|
|
38
|
+
|
|
39
|
+
for port, info in self.manager.benchlab_devices.items():
|
|
40
|
+
self.fleet_cache.append({
|
|
41
|
+
"port": port,
|
|
42
|
+
"uid": info.get("uid", "?"),
|
|
43
|
+
"firmware": info.get("firmware", "?"),
|
|
44
|
+
"in_use": info.get("in_use", False)
|
|
45
|
+
})
|
|
46
|
+
self.fleet = self.fleet_cache.copy()
|
|
47
|
+
|
|
48
|
+
# Footer buttons (centralized)
|
|
49
|
+
self.footer_btns = [
|
|
50
|
+
bind_button(
|
|
51
|
+
UIButton.SHUTDOWN,
|
|
52
|
+
self.manager.graceful_shutdown if self.manager else None)]
|
|
53
|
+
self.footer_hitboxes = []
|
|
54
|
+
|
|
55
|
+
# Fleet button layout
|
|
56
|
+
self.button_height = 60
|
|
57
|
+
self.button_margin = 20
|
|
58
|
+
self.header_height = 60
|
|
59
|
+
self.start_y = self.header_height + 20
|
|
60
|
+
|
|
61
|
+
# -------------------------------
|
|
62
|
+
# Page Lifecycle
|
|
63
|
+
# -------------------------------
|
|
64
|
+
def start(self):
|
|
65
|
+
logger.info("Starting FleetSelect page")
|
|
66
|
+
self.running = True
|
|
67
|
+
self.start_time = int(time.monotonic() * 1000)
|
|
68
|
+
|
|
69
|
+
# -------------------------------
|
|
70
|
+
# Touch Handling
|
|
71
|
+
# -------------------------------
|
|
72
|
+
|
|
73
|
+
def check_touch(self, touch):
|
|
74
|
+
if not getattr(self, "running", False):
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
now = int(time.monotonic() * 1000)
|
|
78
|
+
if now - self.last_touch_time < 150:
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
if touch is None or getattr(touch, "Type", 0) == 0:
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
x, y = getattr(touch, "X", 0), getattr(touch, "Y", 0)
|
|
85
|
+
|
|
86
|
+
# Ignore touches immediately after page start
|
|
87
|
+
if now - getattr(self, "start_time", now) < 500:
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
self.last_touch_time = now
|
|
91
|
+
|
|
92
|
+
# Footer buttons
|
|
93
|
+
for btn in self.footer_hitboxes:
|
|
94
|
+
if btn["x0"] <= x <= btn["x1"] and btn["y0"] <= y <= btn["y1"]:
|
|
95
|
+
logger.info(f"Footer button pressed: {btn['text']}")
|
|
96
|
+
if btn.get("callback"):
|
|
97
|
+
btn["callback"]()
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
# Fleet selection buttons
|
|
101
|
+
for idx, dev in enumerate(self.fleet):
|
|
102
|
+
y0 = self.start_y + idx * (self.button_height + self.button_margin)
|
|
103
|
+
y1 = y0 + self.button_height
|
|
104
|
+
if 50 <= x <= 966 and y0 <= y <= y1:
|
|
105
|
+
self.selected_port = dev["port"]
|
|
106
|
+
logger.info(
|
|
107
|
+
f"Fleet selection done on {
|
|
108
|
+
self.selected_port}, opening Overview.")
|
|
109
|
+
if self.manager and self.wigi:
|
|
110
|
+
self.manager.start_telemetry(self.selected_port, self.wigi)
|
|
111
|
+
|
|
112
|
+
self.running = False
|
|
113
|
+
break
|
|
114
|
+
|
|
115
|
+
# -------------------------------
|
|
116
|
+
# Rendering
|
|
117
|
+
# -------------------------------
|
|
118
|
+
def render_and_display(self):
|
|
119
|
+
img = self.render()
|
|
120
|
+
display_image(self.wigidash, img)
|
|
121
|
+
|
|
122
|
+
def render(self):
|
|
123
|
+
img = Image.new("RGB", (1016, 592), (0, 0, 0))
|
|
124
|
+
draw = ImageDraw.Draw(img)
|
|
125
|
+
|
|
126
|
+
# ---- Header ----
|
|
127
|
+
draw_header(
|
|
128
|
+
draw,
|
|
129
|
+
img,
|
|
130
|
+
self.ui_fonts,
|
|
131
|
+
"SELECT BENCHLAB DEVICE",
|
|
132
|
+
self.ui_logo)
|
|
133
|
+
|
|
134
|
+
# ---- Fleet Buttons ----
|
|
135
|
+
for idx, dev in enumerate(self.fleet):
|
|
136
|
+
y0 = self.start_y + idx * (self.button_height + self.button_margin)
|
|
137
|
+
y1 = y0 + self.button_height
|
|
138
|
+
draw.rectangle([50, y0, 966, y1], fill=(60, 60, 60),
|
|
139
|
+
outline=(200, 200, 200), width=2)
|
|
140
|
+
draw.text((60, y0 + 15),
|
|
141
|
+
f"Port: {dev['port']} | UID: {dev['uid']}",
|
|
142
|
+
fill=(255, 255, 255),
|
|
143
|
+
font=self.ui_fonts["title"])
|
|
144
|
+
|
|
145
|
+
# ---- Footer ----
|
|
146
|
+
info_text = f"Available BENCHLABs: {len(self.fleet)}"
|
|
147
|
+
self.footer_hitboxes = draw_footer(
|
|
148
|
+
draw, self.ui_fonts, info_text, self.footer_btns)
|
|
149
|
+
|
|
150
|
+
return img
|