Skip to content

Commit 244a879

Browse files
committed
Add example\dump_devices.py
1 parent c57981e commit 244a879

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

example/dump_devices.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from cuesdk import (CueSdk, CorsairDeviceFilter, CorsairDeviceType,
2+
CorsairError, CorsairSessionState, CorsairDeviceInfo)
3+
import sys
4+
5+
COLS = ["Device type", "Model name", "LED count", "Channel count"]
6+
COL_WIDTH = 28
7+
8+
9+
def hr():
10+
print("—" * COL_WIDTH * len(COLS))
11+
12+
13+
def print_device(device: CorsairDeviceInfo):
14+
print(f"{str(device.type)[18:]:{COL_WIDTH-2}} |"
15+
f" {device.model:{COL_WIDTH-3}} |"
16+
f" {device.led_count:{COL_WIDTH-3}} |"
17+
f" {device.channel_count:{COL_WIDTH-2}}")
18+
19+
20+
def main():
21+
sdk = CueSdk()
22+
23+
def on_state_changed(evt):
24+
print(evt.state)
25+
# the app must wait for CSS_Connected event before proceeding
26+
if evt.state == CorsairSessionState.CSS_Connected:
27+
details, err = sdk.get_session_details()
28+
print(details)
29+
30+
devices, err = sdk.get_devices(
31+
CorsairDeviceFilter(
32+
device_type_mask=CorsairDeviceType.CDT_All))
33+
if err == CorsairError.CE_Success and devices:
34+
hr()
35+
print("|".join([f"{col:^{COL_WIDTH-1}}" for col in COLS]))
36+
hr()
37+
for d in devices:
38+
device, err = sdk.get_device_info(d.device_id)
39+
if device:
40+
print_device(device)
41+
hr()
42+
else:
43+
print(err)
44+
45+
err = sdk.connect(on_state_changed)
46+
if err != CorsairError.CE_Success:
47+
print("\nERROR: Unable to connect to iCUE")
48+
print(err)
49+
sys.exit()
50+
51+
52+
if __name__ == "__main__":
53+
main()
54+
input() # wait for <Enter>

0 commit comments

Comments
 (0)