PCEVA,PC绝对领域,探寻真正的电脑知识
开启左侧

美商海盗船RGB灯光控制框架 cud_sdk_python 学习笔记(一)

[复制链接]
congrongdeyu 发表于 2020-4-17 16:02 | 显示全部楼层 |阅读模式
点击数:8127|回复数:2
本帖最后由 congrongdeyu 于 2020-4-27 11:16 编辑

美商海盗船更新 Python 语言的 SDK 版本,现在是 v0.3.0,我重新更新了下学习笔记。

SDK 发布地址:https://github.com/CorsairOfficial/cue-sdk-python

一、准备:

1、下载 iCUE 软件
https://www.corsair.com/zh/zh/downloads

2、安装 SDK
  1. # Windows
  2. $ py -3 -m pip install -U cuesdk
复制代码

二、使用

  1. # cue_sdk_python 学习笔记

  2. import time
  3. # 导入美商海盗船 cuesdk
  4. from cuesdk import CueSdk

  5. sdk = CueSdk()
  6. # 通过 sdk 连接设备
  7. sdk.connect()
  8. print("sdk.connect() result:", sdk.connect())
  9. # 输出内容: sdk.connect() result: True
  10. print('-----------------------------------------------------------------------------')

  11. # 获取所有设备
  12. print("sdk.get_devices() result:", sdk.get_devices())
  13. # 输出内容: sdk.get_devices() result: [STRAFE RGB, DARK CORE PRO SE]
  14. print('-----------------------------------------------------------------------------')

  15. # 获取所有设备数量
  16. print("sdk.get_device_count() result:", sdk.get_device_count())
  17. # 输出内容: sdk.get_device_count() result: 2
  18. print('-----------------------------------------------------------------------------')

  19. # 获取特定设备信息
  20. print("sdk.get_device_info() result:", sdk.get_device_info(0))
  21. # 输出内容: sdk.get_device_info() result: STRAFE RGB
  22. print('-----------------------------------------------------------------------------')

  23. # 获取某个字母键位的 led 信息
  24. print("get_led_id_for_key_name() result:")
  25. key_name = sdk.get_led_id_for_key_name('A')
  26. print(key_name)
  27. print('-----------------------------------------------------------------------------')
  28. # 输出内容:CorsairLedId.K_A

  29. # 获取特定设备的特定 led 灯光信息
  30. print("get_led_colors_by_device_index() result:")
  31. key_name = sdk.get_led_id_for_key_name('A')
  32. led_color = sdk.get_led_colors_by_device_index(0, [key_name])
  33. print(led_color)
  34. led_positions = sdk.get_led_positions_by_device_index(0)
  35. led_colors = sdk.get_led_colors_by_device_index(0, list(led_positions.keys()))
  36. print(led_colors)
  37. print('-----------------------------------------------------------------------------')

  38. # 获取所有设备的所有 led 信息
  39. print("get_led_positions_by_device_index() result:")
  40. device_count = sdk.get_device_count()
  41. for device_index in range(device_count):
  42.     led_positions = sdk.get_led_positions_by_device_index(device_index)
  43.     # 单个设备的所有 led 信息
  44.     print(sdk.get_device_info(device_index))
  45.     print(led_positions)
  46.     print('led_positions number:', len(led_positions))
  47. print('-----------------------------------------------------------------------------')
  48. # 输出内容:
  49. # get_led_positions_by_device_index() result:
  50. # STRAFE RGB
  51. # {<CorsairLedId.K_End: 89>: (327.0, 80.0), <CorsairLedId.K_PageDown: 90>: (346.0, 80.0), <CorsairLedId.K_RightShift: 91>: (267.0, 115.0)......
  52. # led_positions number: 107
  53. # DARK CORE PRO SE
  54. # {<CorsairLedId.M_1: 148>: (35.0, 100.0), <CorsairLedId.M_3: 150>: (35.0, 30.0)}
  55. # led_positions number: 2

  56. # def get_available_leds():
  57. #     leds = list()
  58. #     device_count = sdk.get_device_count()
  59. #     for device_index in range(device_count):
  60. #         led_positions = sdk.get_led_positions_by_device_index(device_index)
  61. #         leds.append(led_positions)
  62. #     return leds
  63. # print(get_available_leds())
  64. # print(len(get_available_leds()))

  65. # 设置特定设备的特定 led 色彩
  66. print("set_led_colors_buffer_by_device_index() result:")
  67. led_positions = sdk.get_led_positions_by_device_index(0)
  68. led_colors = sdk.get_led_colors_by_device_index(0, list(led_positions.keys()))
  69. for _ in range(2):
  70.     for corsair_led_id in led_colors:
  71.         led_colors[corsair_led_id] = (0, 100, 0)
  72.     sdk.set_led_colors_buffer_by_device_index(0, led_colors)
  73.     sdk.set_led_colors_flush_buffer()
  74.     time.sleep(25 / 1000)
  75. print('-----------------------------------------------------------------------------')
复制代码







石头 发表于 2020-4-21 06:55 | 显示全部楼层
太监了?
congrongdeyu  楼主| 发表于 2020-4-21 08:28 | 显示全部楼层
还没准备太监,更新会比较慢,哈哈。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部