uwscli 0.1.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.
- uwscli/__init__.py +11 -0
- uwscli/cli.py +416 -0
- uwscli/lcd.py +594 -0
- uwscli/logging_utils.py +34 -0
- uwscli/structs.py +108 -0
- uwscli/system_usb.py +160 -0
- uwscli/usbutil.py +207 -0
- uwscli/wireless.py +362 -0
- uwscli-0.1.0.dist-info/METADATA +169 -0
- uwscli-0.1.0.dist-info/RECORD +14 -0
- uwscli-0.1.0.dist-info/WHEEL +5 -0
- uwscli-0.1.0.dist-info/entry_points.txt +2 -0
- uwscli-0.1.0.dist-info/licenses/LICENSE +21 -0
- uwscli-0.1.0.dist-info/top_level.txt +1 -0
uwscli/wireless.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"""2.4 GHz wireless fan controller helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import math
|
|
7
|
+
import time
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import List, Optional, Sequence, Tuple
|
|
10
|
+
|
|
11
|
+
from .structs import WirelessDeviceInfo, clamp_pwm_values
|
|
12
|
+
from .system_usb import find_devices_by_vid_pid
|
|
13
|
+
from .usbutil import USBEndpointDevice, USBError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
RF_SENDER_VID = 0x0416
|
|
19
|
+
RF_SENDER_PID = 0x8040
|
|
20
|
+
RF_RECEIVER_VID = 0x0416
|
|
21
|
+
RF_RECEIVER_PID = 0x8041
|
|
22
|
+
|
|
23
|
+
RF_GET_DEV_CMD = 0x10
|
|
24
|
+
RF_PACKET_HEADER = 0x10
|
|
25
|
+
RF_CHUNK_SIZE = 60
|
|
26
|
+
RF_PAYLOAD_SIZE = 240
|
|
27
|
+
RF_PAGE_STRIDE = 434
|
|
28
|
+
MAX_DEVICES_PER_PAGE = 10
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class WirelessError(RuntimeError):
|
|
32
|
+
"""Raised when an RF dongle interaction fails."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class WirelessSnapshot:
|
|
37
|
+
devices: List[WirelessDeviceInfo]
|
|
38
|
+
raw: bytes
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class WirelessTransceiver:
|
|
42
|
+
"""High level helper around the Uni Fan wireless USB dongle pair."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, timeout_ms: int = 1000) -> None:
|
|
45
|
+
try:
|
|
46
|
+
self._sender = USBEndpointDevice(
|
|
47
|
+
RF_SENDER_VID,
|
|
48
|
+
RF_SENDER_PID,
|
|
49
|
+
timeout_ms=timeout_ms,
|
|
50
|
+
)
|
|
51
|
+
except USBError as exc:
|
|
52
|
+
if find_devices_by_vid_pid(RF_SENDER_VID, RF_SENDER_PID):
|
|
53
|
+
raise WirelessError(
|
|
54
|
+
"Wireless sender detected but libusb access failed. Install libusb (e.g. `brew install libusb`).",
|
|
55
|
+
) from exc
|
|
56
|
+
raise WirelessError(str(exc)) from exc
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
self._receiver = USBEndpointDevice(
|
|
60
|
+
RF_RECEIVER_VID,
|
|
61
|
+
RF_RECEIVER_PID,
|
|
62
|
+
timeout_ms=timeout_ms,
|
|
63
|
+
)
|
|
64
|
+
except USBError as exc:
|
|
65
|
+
self._sender.close()
|
|
66
|
+
if find_devices_by_vid_pid(RF_RECEIVER_VID, RF_RECEIVER_PID):
|
|
67
|
+
raise WirelessError(
|
|
68
|
+
"Wireless receiver detected but libusb access failed. Install libusb (e.g. `brew install libusb`).",
|
|
69
|
+
) from exc
|
|
70
|
+
raise WirelessError(str(exc)) from exc
|
|
71
|
+
|
|
72
|
+
logger.debug("Opened wireless transceiver (timeout=%sms)", timeout_ms)
|
|
73
|
+
|
|
74
|
+
def close(self) -> None:
|
|
75
|
+
self._sender.close()
|
|
76
|
+
self._receiver.close()
|
|
77
|
+
logger.debug("Closed wireless transceiver")
|
|
78
|
+
|
|
79
|
+
def __enter__(self) -> "WirelessTransceiver":
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def __exit__(self, exc_type, exc, tb) -> None:
|
|
83
|
+
self.close()
|
|
84
|
+
|
|
85
|
+
def list_devices(self) -> WirelessSnapshot:
|
|
86
|
+
logger.debug("Requesting wireless device list")
|
|
87
|
+
page_count = 1
|
|
88
|
+
snapshot = self._fetch_page(page_count)
|
|
89
|
+
expected_pages = max(1, math.ceil(snapshot[0] / MAX_DEVICES_PER_PAGE))
|
|
90
|
+
if expected_pages != page_count:
|
|
91
|
+
snapshot = self._fetch_page(expected_pages)
|
|
92
|
+
device_count, payload = snapshot
|
|
93
|
+
devices = self._parse_devices(device_count, payload)
|
|
94
|
+
logger.debug("Discovered %d wireless device(s)", len(devices))
|
|
95
|
+
return WirelessSnapshot(devices=devices, raw=payload)
|
|
96
|
+
|
|
97
|
+
def set_pwm(
|
|
98
|
+
self,
|
|
99
|
+
mac: str,
|
|
100
|
+
pwm_values: Sequence[int],
|
|
101
|
+
*,
|
|
102
|
+
sequence_index: int = 1,
|
|
103
|
+
) -> None:
|
|
104
|
+
snapshot = self.list_devices()
|
|
105
|
+
target = next((dev for dev in snapshot.devices if dev.mac.lower() == mac.lower()), None)
|
|
106
|
+
if target is None:
|
|
107
|
+
raise WirelessError(f"Device with MAC {mac} not found")
|
|
108
|
+
if not target.is_bound:
|
|
109
|
+
raise WirelessError("Device is not bound to a master controller; cannot send PWM")
|
|
110
|
+
payload = bytearray(RF_PAYLOAD_SIZE)
|
|
111
|
+
payload[0] = 0x12
|
|
112
|
+
payload[1] = 0x10
|
|
113
|
+
payload[2:8] = _mac_to_bytes(target.mac)
|
|
114
|
+
payload[8:14] = _mac_to_bytes(target.master_mac)
|
|
115
|
+
payload[14] = target.rx_type
|
|
116
|
+
payload[15] = target.channel
|
|
117
|
+
payload[16] = sequence_index & 0xFF
|
|
118
|
+
pwm_tuple = clamp_pwm_values(pwm_values)
|
|
119
|
+
payload[17:21] = bytes(pwm_tuple)
|
|
120
|
+
logger.info(
|
|
121
|
+
"Sending PWM command to %s (channel=%s rx=%s): %s seq=%d",
|
|
122
|
+
mac,
|
|
123
|
+
target.channel,
|
|
124
|
+
target.rx_type,
|
|
125
|
+
pwm_tuple,
|
|
126
|
+
sequence_index,
|
|
127
|
+
)
|
|
128
|
+
self._send_rf_data(target.channel, target.rx_type, payload)
|
|
129
|
+
|
|
130
|
+
def bind_device(
|
|
131
|
+
self,
|
|
132
|
+
mac: str,
|
|
133
|
+
*,
|
|
134
|
+
master_mac: Optional[str] = None,
|
|
135
|
+
rx_type: Optional[int] = None,
|
|
136
|
+
) -> WirelessDeviceInfo:
|
|
137
|
+
snapshot = self.list_devices()
|
|
138
|
+
target = next((dev for dev in snapshot.devices if dev.mac.lower() == mac.lower()), None)
|
|
139
|
+
if target is None:
|
|
140
|
+
raise WirelessError(f"Device with MAC {mac} not found")
|
|
141
|
+
if target.is_bound:
|
|
142
|
+
raise WirelessError("Device is already bound")
|
|
143
|
+
|
|
144
|
+
if master_mac is None:
|
|
145
|
+
master_mac = next(
|
|
146
|
+
(dev.master_mac for dev in snapshot.devices if dev.is_bound),
|
|
147
|
+
None,
|
|
148
|
+
)
|
|
149
|
+
if not master_mac or set(master_mac.split(":")) == {"00"}:
|
|
150
|
+
raise WirelessError(
|
|
151
|
+
"Unable to infer master MAC. Provide one with --master-mac (format aa:bb:cc:dd:ee:ff).",
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if rx_type is None:
|
|
155
|
+
used = {dev.rx_type for dev in snapshot.devices if dev.is_bound and dev.rx_type > 0}
|
|
156
|
+
for candidate in range(1, 16):
|
|
157
|
+
if candidate not in used:
|
|
158
|
+
rx_type = candidate
|
|
159
|
+
break
|
|
160
|
+
else:
|
|
161
|
+
raise WirelessError("No free RX type slots available")
|
|
162
|
+
if not 0 < rx_type < 16:
|
|
163
|
+
raise WirelessError("rx_type must be in range 1-15")
|
|
164
|
+
|
|
165
|
+
channel = target.channel if target.channel else snapshot.devices[0].channel
|
|
166
|
+
pwm_tuple = clamp_pwm_values(target.pwm_values)
|
|
167
|
+
|
|
168
|
+
payload = bytearray(RF_PAYLOAD_SIZE)
|
|
169
|
+
payload[0] = 0x12
|
|
170
|
+
payload[1] = 0x10
|
|
171
|
+
payload[2:8] = _mac_to_bytes(target.mac)
|
|
172
|
+
payload[8:14] = _mac_to_bytes(master_mac)
|
|
173
|
+
payload[14] = rx_type
|
|
174
|
+
payload[15] = channel
|
|
175
|
+
payload[16] = 1
|
|
176
|
+
payload[17:21] = bytes(pwm_tuple)
|
|
177
|
+
self._send_rf_data(channel, target.rx_type or 0, payload)
|
|
178
|
+
time.sleep(0.1)
|
|
179
|
+
refreshed = self.list_devices()
|
|
180
|
+
updated = next((dev for dev in refreshed.devices if dev.mac.lower() == mac.lower()), None)
|
|
181
|
+
logger.info(
|
|
182
|
+
"Bind request sent for %s (channel=%s rx_type=%s master=%s)",
|
|
183
|
+
mac,
|
|
184
|
+
channel,
|
|
185
|
+
rx_type,
|
|
186
|
+
master_mac,
|
|
187
|
+
)
|
|
188
|
+
return updated or target
|
|
189
|
+
|
|
190
|
+
def unbind_device(self, mac: str) -> WirelessDeviceInfo:
|
|
191
|
+
snapshot = self.list_devices()
|
|
192
|
+
target = next((dev for dev in snapshot.devices if dev.mac.lower() == mac.lower()), None)
|
|
193
|
+
if target is None:
|
|
194
|
+
raise WirelessError(f"Device with MAC {mac} not found")
|
|
195
|
+
if not target.is_bound:
|
|
196
|
+
raise WirelessError("Device is already unbound")
|
|
197
|
+
|
|
198
|
+
channel = target.channel if target.channel else snapshot.devices[0].channel
|
|
199
|
+
pwm_tuple = clamp_pwm_values(target.pwm_values)
|
|
200
|
+
|
|
201
|
+
payload = bytearray(RF_PAYLOAD_SIZE)
|
|
202
|
+
payload[0] = 0x12
|
|
203
|
+
payload[1] = 0x10
|
|
204
|
+
payload[2:8] = _mac_to_bytes(target.mac)
|
|
205
|
+
payload[8:14] = bytes(6)
|
|
206
|
+
payload[14] = 0
|
|
207
|
+
payload[15] = channel
|
|
208
|
+
payload[16] = 0
|
|
209
|
+
payload[17:21] = bytes(pwm_tuple)
|
|
210
|
+
self._send_rf_data(channel, target.rx_type, payload)
|
|
211
|
+
time.sleep(0.1)
|
|
212
|
+
refreshed = self.list_devices()
|
|
213
|
+
updated = next((dev for dev in refreshed.devices if dev.mac.lower() == mac.lower()), None)
|
|
214
|
+
logger.info("Unbind request sent for %s", mac)
|
|
215
|
+
return updated or target
|
|
216
|
+
|
|
217
|
+
def set_pwm_sync(self, mac: str, enable: bool, fallback_pwm: int = 100) -> None:
|
|
218
|
+
snapshot = self.list_devices()
|
|
219
|
+
target = next((dev for dev in snapshot.devices if dev.mac.lower() == mac.lower()), None)
|
|
220
|
+
if target is None:
|
|
221
|
+
raise WirelessError(f"Device with MAC {mac} not found")
|
|
222
|
+
if not target.is_bound:
|
|
223
|
+
raise WirelessError("Device is not bound")
|
|
224
|
+
|
|
225
|
+
if enable:
|
|
226
|
+
pwm_values = (6, 6, 6, 6)
|
|
227
|
+
else:
|
|
228
|
+
pwm_values = clamp_pwm_values([fallback_pwm] * 4)
|
|
229
|
+
logger.debug(
|
|
230
|
+
"Setting PWM sync for %s (mode=%s, fallback=%d)",
|
|
231
|
+
mac,
|
|
232
|
+
"enable" if enable else "disable",
|
|
233
|
+
fallback_pwm,
|
|
234
|
+
)
|
|
235
|
+
self.set_pwm(mac, pwm_values)
|
|
236
|
+
|
|
237
|
+
def _fetch_page(self, page_count: int) -> Tuple[int, bytes]:
|
|
238
|
+
command = bytearray(64)
|
|
239
|
+
command[0] = RF_GET_DEV_CMD
|
|
240
|
+
command[1] = page_count & 0xFF
|
|
241
|
+
self._receiver.write(command)
|
|
242
|
+
total_len = RF_PAGE_STRIDE * page_count
|
|
243
|
+
buffer = bytearray()
|
|
244
|
+
request_size = 512
|
|
245
|
+
while len(buffer) < total_len:
|
|
246
|
+
try:
|
|
247
|
+
chunk = self._receiver.read(request_size)
|
|
248
|
+
except USBError as exc:
|
|
249
|
+
message = str(exc).lower()
|
|
250
|
+
if "overflow" in message and request_size < 2048:
|
|
251
|
+
request_size *= 2
|
|
252
|
+
continue
|
|
253
|
+
raise
|
|
254
|
+
if not chunk:
|
|
255
|
+
break
|
|
256
|
+
buffer.extend(chunk)
|
|
257
|
+
if len(chunk) < request_size:
|
|
258
|
+
break
|
|
259
|
+
if not buffer:
|
|
260
|
+
raise WirelessError("RF receiver returned no data")
|
|
261
|
+
buffer = buffer[:total_len]
|
|
262
|
+
if not buffer or buffer[0] != RF_GET_DEV_CMD:
|
|
263
|
+
raise WirelessError(f"Unexpected RF response header 0x{buffer[0]:02x}")
|
|
264
|
+
device_count = buffer[1]
|
|
265
|
+
return device_count, bytes(buffer)
|
|
266
|
+
|
|
267
|
+
def _parse_devices(self, count: int, payload: bytes) -> List[WirelessDeviceInfo]:
|
|
268
|
+
devices: List[WirelessDeviceInfo] = []
|
|
269
|
+
offset = 4
|
|
270
|
+
for _ in range(count):
|
|
271
|
+
if offset + 42 > len(payload):
|
|
272
|
+
break
|
|
273
|
+
record = payload[offset : offset + 42]
|
|
274
|
+
if record[41] != 28:
|
|
275
|
+
offset += 42
|
|
276
|
+
continue
|
|
277
|
+
mac = _bytes_to_mac(record[0:6])
|
|
278
|
+
master_mac = _bytes_to_mac(record[6:12])
|
|
279
|
+
channel = record[12]
|
|
280
|
+
rx_type = record[13]
|
|
281
|
+
dev_type = record[18]
|
|
282
|
+
fan_num = record[19] if record[19] < 10 else record[19] - 10
|
|
283
|
+
fan_pwm = tuple(record[36:40])
|
|
284
|
+
fan_rpm = tuple(
|
|
285
|
+
(record[28 + i * 2] << 8) | record[29 + i * 2]
|
|
286
|
+
for i in range(4)
|
|
287
|
+
)
|
|
288
|
+
cmd_seq = record[40]
|
|
289
|
+
devices.append(
|
|
290
|
+
WirelessDeviceInfo(
|
|
291
|
+
mac=mac,
|
|
292
|
+
master_mac=master_mac,
|
|
293
|
+
channel=channel,
|
|
294
|
+
rx_type=rx_type,
|
|
295
|
+
device_type=dev_type,
|
|
296
|
+
fan_count=fan_num,
|
|
297
|
+
pwm_values=fan_pwm,
|
|
298
|
+
fan_rpm=fan_rpm,
|
|
299
|
+
command_sequence=cmd_seq,
|
|
300
|
+
raw=record,
|
|
301
|
+
),
|
|
302
|
+
)
|
|
303
|
+
offset += 42
|
|
304
|
+
return devices
|
|
305
|
+
|
|
306
|
+
def _send_rf_data(self, channel: int, rx: int, payload: bytes) -> None:
|
|
307
|
+
if len(payload) != RF_PAYLOAD_SIZE:
|
|
308
|
+
raise WirelessError(f"RF payload must be {RF_PAYLOAD_SIZE} bytes")
|
|
309
|
+
chunk_index = 0
|
|
310
|
+
sequence = 0
|
|
311
|
+
while chunk_index < len(payload):
|
|
312
|
+
chunk = payload[chunk_index : chunk_index + RF_CHUNK_SIZE]
|
|
313
|
+
if len(chunk) < RF_CHUNK_SIZE:
|
|
314
|
+
chunk = chunk + bytes(RF_CHUNK_SIZE - len(chunk))
|
|
315
|
+
packet = bytearray(64)
|
|
316
|
+
packet[0] = RF_PACKET_HEADER
|
|
317
|
+
packet[1] = sequence & 0xFF
|
|
318
|
+
packet[2] = channel & 0xFF
|
|
319
|
+
packet[3] = rx & 0xFF
|
|
320
|
+
packet[4 : 4 + RF_CHUNK_SIZE] = chunk
|
|
321
|
+
self._sender.write(packet)
|
|
322
|
+
chunk_index += RF_CHUNK_SIZE
|
|
323
|
+
sequence = (sequence + 1) & 0xFF
|
|
324
|
+
time.sleep(0.002)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def run_pwm_sync_loop(mac_addrs, *, enable: bool, fallback_pwm: int) -> None:
|
|
328
|
+
macs = [m.lower() for m in mac_addrs]
|
|
329
|
+
logger.info(
|
|
330
|
+
"Starting PWM sync loop for %d device(s) (%s)",
|
|
331
|
+
len(macs),
|
|
332
|
+
"enable" if enable else f"disable fallback={fallback_pwm}",
|
|
333
|
+
)
|
|
334
|
+
try:
|
|
335
|
+
while True:
|
|
336
|
+
with WirelessTransceiver() as tx:
|
|
337
|
+
snapshot = tx.list_devices()
|
|
338
|
+
targets = [dev for dev in snapshot.devices if dev.mac.lower() in macs]
|
|
339
|
+
if not targets:
|
|
340
|
+
logger.debug("PWM sync loop found no targets; sleeping")
|
|
341
|
+
time.sleep(1)
|
|
342
|
+
continue
|
|
343
|
+
for dev in targets:
|
|
344
|
+
if enable:
|
|
345
|
+
tx.set_pwm_sync(dev.mac, enable=True)
|
|
346
|
+
else:
|
|
347
|
+
tx.set_pwm_sync(dev.mac, enable=False, fallback_pwm=fallback_pwm)
|
|
348
|
+
time.sleep(1)
|
|
349
|
+
except KeyboardInterrupt:
|
|
350
|
+
logger.info("PWM sync loop interrupted by user")
|
|
351
|
+
return
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _bytes_to_mac(raw: bytes) -> str:
|
|
355
|
+
return ":".join(f"{b:02x}" for b in raw)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _mac_to_bytes(mac: str) -> bytes:
|
|
359
|
+
parts = mac.split(":")
|
|
360
|
+
if len(parts) != 6:
|
|
361
|
+
raise WirelessError(f"Invalid MAC address '{mac}'")
|
|
362
|
+
return bytes(int(part, 16) for part in parts)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uwscli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Uni-Wireless-Sync: wireless control toolkit for TL LCD fan hubs
|
|
5
|
+
Author: Study Hsueh
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Study Hsueh
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/phstudy/tlv2-lcd
|
|
28
|
+
Project-URL: Issues, https://github.com/phstudy/tlv2-lcd/issues
|
|
29
|
+
Keywords: lian-li,uni-fan,wireless,lcd
|
|
30
|
+
Classifier: Development Status :: 3 - Alpha
|
|
31
|
+
Classifier: Environment :: Console
|
|
32
|
+
Classifier: Intended Audience :: System Administrators
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: MacOS
|
|
35
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
36
|
+
Classifier: Programming Language :: Python
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB)
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: hidapi>=0.14
|
|
46
|
+
Requires-Dist: pyusb>=1.2
|
|
47
|
+
Requires-Dist: pycryptodomex>=3.17
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
51
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
52
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
53
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
54
|
+
Provides-Extra: images
|
|
55
|
+
Requires-Dist: Pillow>=10.0; extra == "images"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
# UWS CLI
|
|
59
|
+
|
|
60
|
+
Warning: This is an unofficial implementation; use at your own risk.
|
|
61
|
+
|
|
62
|
+
## Overview
|
|
63
|
+
|
|
64
|
+
UWS CLI provides command-line utilities for managing Uni Fan Wireless controllers, L-Wireless receivers, and LCD panels. Each command re-opens the required USB or RF device so no background daemon is left running, and lower-level HID/USB errors are surfaced directly to simplify scripting.
|
|
65
|
+
|
|
66
|
+
## Supported Hardware
|
|
67
|
+
|
|
68
|
+
- UNI FAN TL wireless LCD panels
|
|
69
|
+
- UNI FAN TL wireless fan hubs (non-LCD)
|
|
70
|
+
|
|
71
|
+
Other Uni Fan series are currently not supported.
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
- Discover TL LCD USB devices and 2.4 GHz wireless fan controllers.
|
|
76
|
+
- Query LCD firmware and handshake data.
|
|
77
|
+
- Send JPEG frames or apply control settings (mode, brightness, rotation) to the LCD.
|
|
78
|
+
- Keep the wireless TL LCD awake by emitting periodic handshakes.
|
|
79
|
+
- List wireless fan hubs with metadata (MAC, master MAC, channel, device type, fan speeds, PWM targets).
|
|
80
|
+
- Send one-shot PWM commands to TL wireless fans over the 2.4 GHz dongle.
|
|
81
|
+
- Bind or unbind wireless hubs against the active master controller.
|
|
82
|
+
- Toggle motherboard PWM sync mode for one hub or every bound hub.
|
|
83
|
+
|
|
84
|
+
## Roadmap
|
|
85
|
+
|
|
86
|
+
- Broadcast static RGB payloads to wireless hubs (CLI command not yet implemented).
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install uwscli
|
|
92
|
+
# optional image helpers
|
|
93
|
+
pip install uwscli[images]
|
|
94
|
+
|
|
95
|
+
python -m venv .venv
|
|
96
|
+
source .venv/bin/activate
|
|
97
|
+
pip install -e .
|
|
98
|
+
# or include dev extras
|
|
99
|
+
pip install -e .[dev]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Usage Examples
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Enumerate connected devices
|
|
106
|
+
uws lcd list
|
|
107
|
+
uws fan list
|
|
108
|
+
|
|
109
|
+
# Display operations
|
|
110
|
+
uws lcd info --serial <usb-serial>
|
|
111
|
+
uws lcd send-jpg --serial <usb-serial> --file assets/sample_lcd.jpg
|
|
112
|
+
uws lcd keep-alive --serial <usb-serial> --interval 5
|
|
113
|
+
|
|
114
|
+
# Fan hub operations
|
|
115
|
+
uws fan set-fan --mac aa:bb:cc:dd:ee:ff --pwm 120
|
|
116
|
+
uws fan bind --mac aa:bb:cc:dd:ee:ff
|
|
117
|
+
uws fan unbind --mac aa:bb:cc:dd:ee:ff
|
|
118
|
+
uws fan pwm-sync --all --enable
|
|
119
|
+
uws fan pwm-sync --mac aa:bb:cc:dd:ee:ff --disable --fallback-pwm 120
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`uws lcd list` prints JSON rows that include a `serial` field—copy that value when invoking other LCD subcommands.
|
|
123
|
+
|
|
124
|
+
## Command Reference
|
|
125
|
+
|
|
126
|
+
- `uws lcd list` – enumerate TL LCD devices and show their USB serial numbers.
|
|
127
|
+
- `uws lcd info --serial <usb-serial>` – read firmware and handshake data.
|
|
128
|
+
- `uws lcd send-jpg --serial <usb-serial> --file <image.jpg>` – stream a JPEG asset.
|
|
129
|
+
- `uws lcd keep-alive --serial <usb-serial> [--interval seconds]` – emit periodic handshakes to prevent the wireless panel from dimming.
|
|
130
|
+
- `uws lcd control --serial <usb-serial> [--mode show-jpg|show-app-sync|lcd-test] [--index N] [--brightness 0-100] [--fps N] [--rotation 0|90|180|270] [--test-color R,G,B]` – send an `LCDControlSetting` payload.
|
|
131
|
+
- `uws fan list` – fetch a snapshot of bound wireless devices via the RF receiver.
|
|
132
|
+
- `uws fan set-fan --mac <aa:bb:..> --pwm <0-255>` – send a single shot PWM update to the matching wireless hub using the RF sender.
|
|
133
|
+
- `uws fan pwm-sync --all|--mac` – enable or disable motherboard PWM sync for bound hubs.
|
|
134
|
+
|
|
135
|
+
## Dependencies
|
|
136
|
+
|
|
137
|
+
- `hidapi` (via `hid`) for TL LCD HID access.
|
|
138
|
+
- `pyusb` for the RF sender/receiver WinUSB endpoints.
|
|
139
|
+
- `pycryptodomex` for the DES-CBC transport used by the wireless LCD hub.
|
|
140
|
+
- `Pillow` is optional for JPEG frame validation.
|
|
141
|
+
|
|
142
|
+
Each command expects the TL LCD USB display (vendor 0x04FC or 0x1CBE) and the wireless transmitter/receiver pair (vendor 0x0416) to be attached when the command executes.
|
|
143
|
+
|
|
144
|
+
## Linux udev Permissions
|
|
145
|
+
|
|
146
|
+
Grant non-root access to the TL wireless dongles by adding `/etc/udev/rules.d/99-tl-wireless.rules` with:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
# Winbond SLV3RX_V1.6 (receiver)
|
|
150
|
+
SUBSYSTEM=="usb", ATTR{idVendor}=="0416", ATTR{idProduct}=="8041", MODE="0666", GROUP="plugdev"
|
|
151
|
+
SUBSYSTEM=="usb_device", ATTR{idVendor}=="0416", ATTR{idProduct}=="8041", MODE="0666", GROUP="plugdev"
|
|
152
|
+
SUBSYSTEM=="usb_interface", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="8041", MODE="0666", GROUP="plugdev"
|
|
153
|
+
|
|
154
|
+
# Winbond SLV3TX_V1.6 (transmitter)
|
|
155
|
+
SUBSYSTEM=="usb", ATTR{idVendor}=="0416", ATTR{idProduct}=="8040", MODE="0666", GROUP="plugdev"
|
|
156
|
+
SUBSYSTEM=="usb_device", ATTR{idVendor}=="0416", ATTR{idProduct}=="8040", MODE="0666", GROUP="plugdev"
|
|
157
|
+
SUBSYSTEM=="usb_interface", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="8040", MODE="0666", GROUP="plugdev"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Reload the rules and replug the dongles:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
sudo udevadm control --reload
|
|
164
|
+
sudo udevadm trigger
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
Released under the MIT License. See `LICENSE` for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
uwscli/__init__.py,sha256=O9SzwBVDdaUFR8ukpXo1k-9A4JwpPOfvfVUPf1kQA6Q,129
|
|
2
|
+
uwscli/cli.py,sha256=Y6_P9QzgCMcwdZ-7FK23g0xsI0z_L4cQhI7TlDlaKrs,16690
|
|
3
|
+
uwscli/lcd.py,sha256=K29UilGGsZbXG8KQCFhbR4-Ltmz1JqTN_SL2eYaswq4,22488
|
|
4
|
+
uwscli/logging_utils.py,sha256=JAIPDILP1_fdgqcB8gxYSa4r71W1joyktsJLMb1S3XI,966
|
|
5
|
+
uwscli/structs.py,sha256=RmWsOl2qxNCt1mldYb2yg0iDOd8ZPq8pM57z5yH0XTY,3191
|
|
6
|
+
uwscli/system_usb.py,sha256=SB383D2Pb8M5ux0IPpwBj4ic1LkI9h-8y4G9Blbjljo,4921
|
|
7
|
+
uwscli/usbutil.py,sha256=3dHJZ41Qlx9ZrmIAp0uhJaiYClj1uyqC9TSKuZqjNN4,7965
|
|
8
|
+
uwscli/wireless.py,sha256=YJVzZpzRYpqNt7Hzq6VDn5eJh1bGnDx4O6MqdwDfPMw,13121
|
|
9
|
+
uwscli-0.1.0.dist-info/licenses/LICENSE,sha256=gQUKWsddC1ZcIJMoFxKrXhp5ezoJh2CqYdjoailytg4,1067
|
|
10
|
+
uwscli-0.1.0.dist-info/METADATA,sha256=ra_6si4xZOnMS1WTR02U3vqSkKci05D5mpm8WDHnVO8,7045
|
|
11
|
+
uwscli-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
uwscli-0.1.0.dist-info/entry_points.txt,sha256=c1XOfeO1zl-kQNaKIUkuomgvlzWAfKjQO29gxiRGT0E,40
|
|
13
|
+
uwscli-0.1.0.dist-info/top_level.txt,sha256=IfLvSjDLQ0e-YCxzWukncrfxINWCmwk_oq4fIJiKL-M,7
|
|
14
|
+
uwscli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Study Hsueh
|
|
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 @@
|
|
|
1
|
+
uwscli
|