0x8070 · colorLedEffects
按区域控制 RGB 效果的引擎。它可枚举 LED 区域和效果、应用带持久化选项的效果,并同步效果时序。
colorLedEffects 是 Logitech 键盘和鼠标的按区域 RGB 引擎。每个 LED 区域报告位置和效果列表。效果索引只属于一个区域。
**规格:**Logitech HID++ 2.0 —— colorLedEffects(v7)。**交叉核对:**Logi Options+ 2.8(静态分析)、Solaar、G HUB(静态分析)。用于:键盘灯光。
函数参考
方法
| 函数 | HID++ fn | 签名 | 返回值 |
|---|---|---|---|
get_info | 0 | () | ColorLedInfo |
get_zone_info | 1 | (zone_index: u8) | ZoneInfo |
get_zone_effect_info | 2 | (zone_index: u8, zone_effect_index: u8) | ZoneEffectInfo |
set_zone_effect | 3 | (zone_index: u8, zone_effect_index: u8, params: [u8; ZONE_EFFECT_PARAM_COUNT], persistence: Persistence) | () |
get_nv_config | 4 | (capability: NvCapabilities) | NvConfig |
set_nv_config | 5 | (capability: NvCapabilities, state: NvCapabilityState, param1: u8, param2: u8) | () |
get_led_bin_info | 6 | (zone_index: u8, led_bin_index: LedBinIndex) | LedBinInfo |
get_sw_control | 7 | () | SwControlState |
set_sw_control | 8 | (control: SwControl, sync_events: bool) | () |
get_effect_settings | 9 | (zone_index: u8, source: PersistenceSource) | EffectSettings |
clear_effect_settings | 10 | (zone_index: u8) | () |
set_cycling_direction | 11 | (direction: CyclingDirection) | () |
get_current_color | 12 | (zone_index: u8) | Rgb |
synchronize_effect | 13 | (zone_index: u8, drift_value: i16) | () |
get_zone_effect | 14 | (zone_index: u8, source: PersistenceSource) | ZoneEffect |
set_led_bin_info | 15 | (info: &LedBinInfo) | LedBinInfo |
listen | — | (&self) | async_channel::Receiver<ColorLedEffectsEvent> |
除 listen 外,所有操作都是返回 Result<_, Hidpp20Error> 的 async fn。listen 由 EmittingFeature<ColorLedEffectsEvent> 提供。
类型
ZONE_EFFECT_PARAM_COUNT 的值为 10。
数据结构
| 类型 | 字段 | 说明 |
|---|---|---|
Rgb | red: u8、green: u8、blue: u8 | 每个颜色通道使用一个 8 位值。 |
ColorLedInfo | zone_count: u8、nv_capabilities: NvCapabilities、ext_capabilities: ExtCapabilities | 功能的全局信息。 |
ZoneInfo | zone_index: u8、location: LocationEffect、effects_number: u8、persistency: PersistencyCapabilities | 一个区域。使用 get_zone_effect_info 遍历 0..effects_number。 |
ZoneEffectInfo | zone_index: u8、zone_effect_index: u8、effect_id: EffectId、effect_capabilities: u16、effect_period: u16 | 一个效果。effect_capabilities 为 0 时使用 Raptor 兼容默认值。周期为 0 表示不可用。 |
ZoneEffect | zone_index: u8、zone_effect_index: u8、params: [u8; ZONE_EFFECT_PARAM_COUNT] | 已配置的效果及其原始参数。 |
EffectSettings | zone_index: u8、color: Rgb、period: u16、brightness: u8、param: u8 | 一个区域的已解码设置。 |
SwControlState | control: SwControl、sync_events: bool | LED 控制权和同步事件状态。 |
NvConfig | capability: NvCapabilities、state: NvCapabilityState、param1: u8、param2: u8 | 一个非易失能力项。 |
LedBinInfo | zone_index: u8、led_bin_index: LedBinIndex、red: u16、green: u16、blue: u16、white: u16 | LED 制造分档值。 |
这些结构中的所有时长和周期单位都是毫秒。effect_capabilities 保持原始位掩码,因为其位含义取决于 effect_id。
枚举
| 类型 | 变体 | 值 |
|---|---|---|
EffectId | Disabled、FixedColor、PulsingBreathingLegacy、Cycling、ColorWave、Starlight、LightOnPress、AudioVisualizer、BootUp、DemoMode、PulsingBreathingWaveform、Ripple | 按列出顺序为 0~11。AudioVisualizer 为保留值。 |
LocationEffect | Primary、Logo、LeftSide、RightSide、Combined、Primary1、Primary2、Primary3、Primary4、Primary5、Primary6 | 按列出顺序为 1~11。 |
Persistence | Volatile、VolatileAndNonVolatile、NonVolatileOnly | 0、1、2。仅 RAM;RAM 加 EEPROM;仅 EEPROM。 |
PersistenceSource | Ram、Eeprom | 0、1。 |
SwControl | Firmware、Software | 0、1。 |
CyclingDirection | Clockwise、Anticlockwise | 0、1。 |
LedBinIndex | BinValueBrightness、BinValueColor、CalibrationFactors、Brightness、ColorimetricX、ColorimetricY | 按列出顺序为 0~5。 |
NvCapabilityState | NoChange、Enabled、Disabled | 0、1、2。NoChange 是只读哨兵值,并假定功能已启用。 |
位标志
| 类型 | 标志 | 位 | 含义 |
|---|---|---|---|
NvCapabilities | BOOT_UP_EFFECT | 1 << 0 | 可配置开机效果。 |
NvCapabilities | DEMO | 1 << 1 | 支持演示模式。 |
NvCapabilities | USER_DEMO_MODE | 1 << 2 | 支持用户演示模式。 |
ExtCapabilities | GET_ZONE_EFFECT | 1 << 0 | 支持 get_zone_effect。 |
ExtCapabilities | NO_GET_EFFECT_SETTINGS | 1 << 1 | 不支持 get_effect_settings。 |
ExtCapabilities | SET_LED_BIN_INFO | 1 << 2 | 支持 set_led_bin_info。 |
ExtCapabilities | MONOCHROME_ONLY | 1 << 3 | 只支持单色效果。 |
ExtCapabilities | NO_SYNCHRONIZE_EFFECT | 1 << 4 | 不支持同步校正和同步事件。 |
PersistencyCapabilities | ALWAYS_ON | 1 << 0 | 区域可持久保存常亮状态。 |
PersistencyCapabilities | ALWAYS_OFF | 1 << 1 | 区域可持久保存常灭状态。 |
PersistencyCapabilities | ON_THEN_OFF | 1 << 2 | 区域可持久保存先亮后灭状态。 |
PersistencyCapabilities::empty() 表示区域不支持持久化。
事件
ColorLedEffectsFeature 实现 EmittingFeature<ColorLedEffectsEvent>。
| 变体 | 字段 | 说明 |
|---|---|---|
SyncEffect | zone_index: u8、effect_counter: u16 | 周期效果到达同步点。0xff 指向所有区域。计数器单位为毫秒。 |
线格式
以下偏移量均为 payload 字节。短请求携带 3 个字节。长请求携带 16 个字节。以下每个多字节值均为 BE。
get_info(fn 0)
请求:[0x00, 0x00, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_count | 区域数量。 |
| 1–2 | nv_capabilities | NvCapabilities,BE u16。 |
| 3–4 | ext_capabilities | ExtCapabilities,BE u16。 |
get_zone_info(fn 1)
请求:[zone_index, 0x00, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 回显。OpenLogi 要求它与请求值相同。 |
| 1–2 | location | LocationEffect,BE u16。 |
| 3 | effects_number | 此区域的效果数量。 |
| 4 | persistency | PersistencyCapabilities。 |
OpenLogi 要求长回复。短回复或索引不匹配时,OpenLogi 返回 UnsupportedResponse。
get_zone_effect_info(fn 2)
请求:[zone_index, zone_effect_index, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 回复回显。 |
| 1 | zone_effect_index | 回复回显。 |
| 2–3 | effect_id | EffectId,BE u16。 |
| 4–5 | effect_capabilities | 效果专属位掩码,BE u16。 |
| 6–7 | effect_period | 周期,单位为毫秒,BE u16;零表示不可用。 |
set_zone_effect(fn 3)
**请求:**长请求,16 个字节。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 目标区域。 |
| 1 | zone_effect_index | 此区域中的效果序号。 |
| 2–11 | params | 10 个效果专属字节。FixedColor 使用字节 2–4 存放红、绿、蓝。 |
| 12 | persistence | Persistence 值。 |
| 13–15 | 填充 | OpenLogi 写入 0x00。 |
封装等待确认,并丢弃确认 payload。
get_nv_config(fn 4)
请求:[cap_hi, cap_lo, 0x00]。能力值是一个 NvCapabilities 位,采用 BE u16。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0–1 | capability | 回显的 NvCapabilities,BE u16。 |
| 2 | state | NvCapabilityState。 |
| 3 | param1 | 能力专属字节。 |
| 4 | param2 | 能力专属字节。 |
OpenLogi 要求请求值恰好设置一个能力位。
set_nv_config(fn 5)
**请求:**长请求,16 个字节。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0–1 | capability | 一个 NvCapabilities 位,BE u16。 |
| 2 | state | NvCapabilityState。 |
| 3 | param1 | 能力专属字节。 |
| 4 | param2 | 能力专属字节。 |
| 5–15 | 填充 | OpenLogi 写入 0x00。 |
封装等待确认,并丢弃确认 payload。
get_led_bin_info(fn 6)
请求:[zone_index, led_bin_index, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 回复回显。 |
| 1 | led_bin_index | LedBinIndex。 |
| 2–3 | red | BE u16。 |
| 4–5 | green | BE u16。 |
| 6–7 | blue | BE u16。 |
| 8–9 | white | BE u16。 |
get_sw_control(fn 7)
请求:[0x00, 0x00, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | control | SwControl:0 为固件,1 为软件。 |
| 1 | sync_events | 零为 false。任何非零值为 true。 |
set_sw_control(fn 8)
请求:[control, sync_events, 0x00]。sync_events 为 0 或 1。
封装等待确认,并丢弃确认 payload。同步事件选择不保存到 EEPROM。
get_effect_settings(fn 9)
请求:[zone_index, source, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 回复回显。 |
| 1–3 | color | 红、绿、蓝字节。 |
| 4–5 | period | 毫秒,BE u16。 |
| 6 | brightness | 原始亮度字节。 |
| 7 | param | 效果专属字节。 |
当 NO_GET_EFFECT_SETTINGS 置位时,此函数不可用。
clear_effect_settings(fn 10)
请求:[zone_index, 0x00, 0x00]。
封装等待确认,并丢弃确认 payload。该操作将区域恢复为默认模式。
set_cycling_direction(fn 11)
请求:[direction, 0x00, 0x00]。Clockwise 为 0。Anticlockwise 为 1。
封装等待确认,并丢弃确认 payload。
get_current_color(fn 12)
请求:[zone_index, 0x00, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | / | OpenLogi 忽略此字节。 |
| 1–3 | Rgb | 红、绿、蓝字节。 |
synchronize_effect(fn 13)
**请求:**长请求,16 个字节。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 0xff 指向所有区域。 |
| 1 | 保留 | OpenLogi 写入 0x00。 |
| 2–3 | drift_value | 毫秒,BE i16。 |
| 4–15 | 填充 | OpenLogi 写入 0x00。 |
此函数仅在启用同步事件时有效。当 NO_SYNCHRONIZE_EFFECT 置位时,它不可用。
get_zone_effect(fn 14)
请求:[zone_index, source, 0x00]。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 回复回显。 |
| 1 | zone_effect_index | 回复中的效果序号。 |
| 2–11 | params | 10 个效果专属字节。 |
只有 GET_ZONE_EFFECT 置位时,此函数才可用。
set_led_bin_info(fn 15)
**请求:**长请求,16 个字节。
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 目标区域。 |
| 1 | led_bin_index | LedBinIndex。 |
| 2–3 | red | BE u16。 |
| 4–5 | green | BE u16。 |
| 6–7 | blue | BE u16。 |
| 8–9 | white | BE u16。 |
| 10–15 | 填充 | OpenLogi 写入 0x00。 |
回复使用 get_led_bin_info 的布局。OpenLogi 解码并返回这些回显值。
SyncEffect 事件(事件 fn 0)
| 字节 | 字段 | 备注 |
|---|---|---|
| 0 | zone_index | 0xff 指向所有区域。 |
| 1–2 | effect_counter | 时序位置,单位为毫秒,BE u16。 |
OpenLogi 的用法
自动键盘灯光路径先尝试 0x8070,再尝试 0x8071、0x8081 和 0x8080。该路径只写入易失固定颜色效果。代理会在键盘重新连接时应用已保存的颜色,而不是每次选色都写入 EEPROM。
从 v0.8.14 开始,PR #1758 会在每个已枚举区域中查找 EffectId::FixedColor。该路径写入发现的效果索引,而不是 EffectId 值。区域没有该效果时会跳过该区域。没有任何目标时会回退到下一个灯光路径。
该写入器目前只枚举前 4 个报告的区域。当 zone_count 为零或 get_zone_info 被拒绝时,它还会为区域 0..4 使用旧版效果索引 1。这些兼容回退仍可能写入错误效果或遗漏区域。
生产灯光路径只使用函数 0~3。该路径不获取此功能的软件控制权,也不调用 NV 配置、同步或其他仅限 v1 的函数。用户界面入口是键盘灯光标签页。
未确认的细节
版本门控函数
Options+ 2.8 只在功能版本至少为 1 时调用函数 4、5、7、8 和 13。G HUB 静态分析也标明存在功能版本检查。OpenLogi 从版本 0 注册同一个封装,且这些调用没有运行时门控。
版本条件有静态分析支持,但提供的证据没有硬件抓包。静态颜色界面不调用这些函数。封装调用方必须接受版本 0 返回错误的可能性。
Rust 用法
use hidpp::feature::color_led_effects::{
ColorLedEffectsFeature, EffectId, Persistence, ZONE_EFFECT_PARAM_COUNT,
};
use hidpp::protocol::v20::Hidpp20Error;
async fn set_red(feature: &ColorLedEffectsFeature) -> Result<(), Hidpp20Error> {
let mut params = [0_u8; ZONE_EFFECT_PARAM_COUNT];
params[..3].copy_from_slice(&[0xff, 0x00, 0x00]);
let device = feature.get_info().await?;
for zone in 0..device.zone_count {
let zone_info = feature.get_zone_info(zone).await?;
for effect in 0..zone_info.effects_number {
let info = feature.get_zone_effect_info(zone, effect).await?;
if info.effect_id == EffectId::FixedColor {
feature
.set_zone_effect(zone, effect, params, Persistence::Volatile)
.await?;
break;
}
}
}
Ok(())
}