@openmouse/protocol 0.21.0 → 0.23.0
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.
- package/dist/coolermaster/index.d.ts +166 -0
- package/dist/coolermaster/index.d.ts.map +1 -0
- package/dist/coolermaster/index.js +475 -0
- package/dist/coolermaster/index.js.map +1 -0
- package/dist/drivers/coolermaster/hid.d.ts +39 -0
- package/dist/drivers/coolermaster/hid.d.ts.map +1 -0
- package/dist/drivers/coolermaster/hid.js +479 -0
- package/dist/drivers/coolermaster/hid.js.map +1 -0
- package/dist/drivers/endgame/egg-op1-hid.d.ts +13 -8
- package/dist/drivers/endgame/egg-op1-hid.d.ts.map +1 -1
- package/dist/drivers/endgame/egg-op1-hid.js +49 -36
- package/dist/drivers/endgame/egg-op1-hid.js.map +1 -1
- package/dist/drivers/fater/hid.d.ts +22 -0
- package/dist/drivers/fater/hid.d.ts.map +1 -0
- package/dist/drivers/fater/hid.js +81 -0
- package/dist/drivers/fater/hid.js.map +1 -0
- package/dist/drivers/keychron/launcher-mouse.d.ts +126 -0
- package/dist/drivers/keychron/launcher-mouse.d.ts.map +1 -0
- package/dist/drivers/keychron/launcher-mouse.js +397 -0
- package/dist/drivers/keychron/launcher-mouse.js.map +1 -0
- package/dist/drivers/keychron/mouse-1k-hid.d.ts +78 -0
- package/dist/drivers/keychron/mouse-1k-hid.d.ts.map +1 -0
- package/dist/drivers/keychron/mouse-1k-hid.js +403 -0
- package/dist/drivers/keychron/mouse-1k-hid.js.map +1 -0
- package/dist/drivers/keychron/mouse-8k-hid.d.ts +136 -0
- package/dist/drivers/keychron/mouse-8k-hid.d.ts.map +1 -0
- package/dist/drivers/keychron/mouse-8k-hid.js +754 -0
- package/dist/drivers/keychron/mouse-8k-hid.js.map +1 -0
- package/dist/drivers/logitech/bolt.d.ts +4 -1
- package/dist/drivers/logitech/bolt.d.ts.map +1 -1
- package/dist/drivers/logitech/bolt.js +6 -1
- package/dist/drivers/logitech/bolt.js.map +1 -1
- package/dist/drivers/logitech/hidpp.d.ts.map +1 -1
- package/dist/drivers/logitech/hidpp.js +13 -5
- package/dist/drivers/logitech/hidpp.js.map +1 -1
- package/dist/drivers/mouse-types.d.ts +1 -1
- package/dist/drivers/mouse-types.d.ts.map +1 -1
- package/dist/drivers/razer/hid.d.ts +36 -1
- package/dist/drivers/razer/hid.d.ts.map +1 -1
- package/dist/drivers/razer/hid.js +191 -1
- package/dist/drivers/razer/hid.js.map +1 -1
- package/dist/drivers/registry.d.ts +5 -2
- package/dist/drivers/registry.d.ts.map +1 -1
- package/dist/drivers/registry.js +11 -2
- package/dist/drivers/registry.js.map +1 -1
- package/dist/drivers/vendors.d.ts +5 -1
- package/dist/drivers/vendors.d.ts.map +1 -1
- package/dist/drivers/vendors.js +19 -4
- package/dist/drivers/vendors.js.map +1 -1
- package/dist/endgame-gear/op1.d.ts +13 -7
- package/dist/endgame-gear/op1.d.ts.map +1 -1
- package/dist/endgame-gear/op1.js +36 -13
- package/dist/endgame-gear/op1.js.map +1 -1
- package/dist/fater/index.d.ts +62 -0
- package/dist/fater/index.d.ts.map +1 -0
- package/dist/fater/index.js +94 -0
- package/dist/fater/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/keychron/index.d.ts +44 -0
- package/dist/keychron/index.d.ts.map +1 -1
- package/dist/keychron/index.js +82 -0
- package/dist/keychron/index.js.map +1 -1
- package/dist/razer/codec.d.ts +70 -8
- package/dist/razer/codec.d.ts.map +1 -1
- package/dist/razer/codec.js +148 -10
- package/dist/razer/codec.js.map +1 -1
- package/dist/razer/devices.d.ts +18 -0
- package/dist/razer/devices.d.ts.map +1 -1
- package/dist/razer/devices.js +12 -3
- package/dist/razer/devices.js.map +1 -1
- package/package.json +9 -1
- package/dist/drivers/keychron/m6-hid.d.ts +0 -81
- package/dist/drivers/keychron/m6-hid.d.ts.map +0 -1
- package/dist/drivers/keychron/m6-hid.js +0 -486
- package/dist/drivers/keychron/m6-hid.js.map +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cooler Master HID protocol codec.
|
|
3
|
+
*
|
|
4
|
+
* Reverse-engineered from Cooler Master MasterPlus+ v1.9.6 (CMUOT.dll/pdb,
|
|
5
|
+
* MM711PerformanceWid.dll/pdb, CfgFile.dll/pdb) and verified against a physical
|
|
6
|
+
* Cooler Master MM711 wired gaming mouse (VID 0x2516, PID 0x0101, MI_01).
|
|
7
|
+
*
|
|
8
|
+
* All control traffic uses raw 64-byte HID output/input reports on report ID 0x00
|
|
9
|
+
* (total 65 bytes on the wire including Report ID 0x00).
|
|
10
|
+
*
|
|
11
|
+
* Reference captures and ground truth fixtures:
|
|
12
|
+
* `captures/coolermaster-mm711/`
|
|
13
|
+
*/
|
|
14
|
+
export declare const COOLERMASTER_VENDOR_ID = 9494;
|
|
15
|
+
export declare const COOLERMASTER_MM711_PRODUCT_ID = 257;
|
|
16
|
+
export declare const COOLERMASTER_USAGE_PAGE = 65280;
|
|
17
|
+
export declare const COOLERMASTER_USAGE = 1;
|
|
18
|
+
export declare const COOLERMASTER_REPORT_ID = 0;
|
|
19
|
+
export declare const COOLERMASTER_PAYLOAD_SIZE = 64;
|
|
20
|
+
export declare const COOLERMASTER_REPORT_SIZE = 65;
|
|
21
|
+
export declare const COOLERMASTER_PRODUCT_IDS: readonly [257];
|
|
22
|
+
export declare const COOLERMASTER_PRODUCT_NAMES: ReadonlyMap<number, string>;
|
|
23
|
+
export declare const COOLERMASTER_POLLING_RATES: readonly number[];
|
|
24
|
+
export declare const COOLERMASTER_DPI_MIN = 100;
|
|
25
|
+
export declare const COOLERMASTER_DPI_MAX = 16000;
|
|
26
|
+
export declare const COOLERMASTER_DPI_STEP = 100;
|
|
27
|
+
export declare const COOLERMASTER_DPI_STAGE_COUNT = 7;
|
|
28
|
+
export declare const COOLERMASTER_DPI_OPTIONS: readonly number[];
|
|
29
|
+
export declare const COOLERMASTER_CMD_HANDSHAKE_1 = 65;
|
|
30
|
+
export declare const COOLERMASTER_CMD_HANDSHAKE_2 = 128;
|
|
31
|
+
export declare const COOLERMASTER_CMD_READ = 82;
|
|
32
|
+
export declare const COOLERMASTER_CMD_WRITE = 81;
|
|
33
|
+
export declare const COOLERMASTER_SUB_PERFORMANCE = 64;
|
|
34
|
+
export declare const COOLERMASTER_SUB_DPI_LEVEL = 155;
|
|
35
|
+
export declare const COOLERMASTER_SUB_POLLING = 240;
|
|
36
|
+
export declare const COOLERMASTER_SUB_DEBOUNCE = 16;
|
|
37
|
+
export declare const COOLERMASTER_SUB_EFFECT_MODE = 40;
|
|
38
|
+
export declare const COOLERMASTER_SUB_GENERAL_EFFECT = 43;
|
|
39
|
+
export declare const COOLERMASTER_SUB_CUSTOM_EFFECT = 168;
|
|
40
|
+
export declare const COOLERMASTER_LIGHTING_MODE_STATIC = 0;
|
|
41
|
+
export declare const COOLERMASTER_LIGHTING_MODE_BREATH = 1;
|
|
42
|
+
export declare const COOLERMASTER_LIGHTING_MODE_COLOR_CYCLE = 2;
|
|
43
|
+
export declare const COOLERMASTER_LIGHTING_MODE_INDICATOR = 4;
|
|
44
|
+
export declare const COOLERMASTER_LIGHTING_MODE_CUSTOM = 176;
|
|
45
|
+
export declare const COOLERMASTER_LIGHTING_MODE_OFF = 254;
|
|
46
|
+
export declare const COOLERMASTER_LIGHTING_ZONES: readonly ["Scroll wheel", "Logo"];
|
|
47
|
+
export type CoolerMasterLightingZone = (typeof COOLERMASTER_LIGHTING_ZONES)[number];
|
|
48
|
+
export interface CoolerMasterRgbColor {
|
|
49
|
+
r: number;
|
|
50
|
+
g: number;
|
|
51
|
+
b: number;
|
|
52
|
+
}
|
|
53
|
+
export declare const COOLERMASTER_BREATHING_SPEED_MAP: Readonly<Record<number, number>>;
|
|
54
|
+
export declare const COOLERMASTER_COLOR_CYCLE_SPEED_MAP: Readonly<Record<number, number>>;
|
|
55
|
+
/** Polling rate code mapping (matches CMUOT toInnerPollingRate / bInterval ms). */
|
|
56
|
+
export declare const COOLERMASTER_POLLING_RATE_MAP: Readonly<Record<number, number>>;
|
|
57
|
+
export declare const COOLERMASTER_POLLING_CODE_MAP: Readonly<Record<number, number>>;
|
|
58
|
+
export declare function coolermasterEncodePollingCode(hz: number): number;
|
|
59
|
+
export declare function coolermasterDecodePollingRateCode(code: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Encodes a DPI value into the raw hardware byte code:
|
|
62
|
+
* formula from CMUOT: (raw_code + 1) * 100 = DPI => raw_code = Math.round(dpi / 100) - 1.
|
|
63
|
+
*/
|
|
64
|
+
export declare function coolermasterEncodeDpi(dpi: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Decodes a raw hardware byte code to DPI: (raw_code + 1) * 100.
|
|
67
|
+
*/
|
|
68
|
+
export declare function coolermasterDecodeDpi(code: number): number;
|
|
69
|
+
/** Builds the 64-byte handshake request [0x41, 0x80, ...0x00]. */
|
|
70
|
+
export declare function coolermasterEncodeHandshake(): Uint8Array;
|
|
71
|
+
/** Builds the 64-byte get polling rate request [0x52, 0xF0, ...0x00]. */
|
|
72
|
+
export declare function coolermasterEncodeGetPollingRate(): Uint8Array;
|
|
73
|
+
/** Builds the 64-byte set polling rate command [0x51, 0xF0, 0x00, 0x00, code, ...0x00]. */
|
|
74
|
+
export declare function coolermasterEncodeSetPollingRate(hz: number): Uint8Array;
|
|
75
|
+
/** Decodes the polling rate response [0x52, 0xF0, 0x00, 0x00, code, ...]. */
|
|
76
|
+
export declare function coolermasterDecodePollingRate(source: Uint8Array | DataView): number;
|
|
77
|
+
/** Builds the 64-byte get DPI level request [0x52, 0x9B, ...0x00]. */
|
|
78
|
+
export declare function coolermasterEncodeGetDpiLevel(): Uint8Array;
|
|
79
|
+
export interface CoolerMasterDpiLevel {
|
|
80
|
+
activeDpiStage: number;
|
|
81
|
+
stageOrder: number[];
|
|
82
|
+
}
|
|
83
|
+
/** Decodes DPI level reply [0x52, 0x9B, 0x00, 0x00, 0x00, activeStage, ...order]. */
|
|
84
|
+
export declare function coolermasterDecodeDpiLevel(source: Uint8Array | DataView): CoolerMasterDpiLevel;
|
|
85
|
+
/** Builds the 64-byte get performance request [0x52, 0x40, ...0x00]. */
|
|
86
|
+
export declare function coolermasterEncodeGetPerformance(): Uint8Array;
|
|
87
|
+
export interface CoolerMasterPerformance {
|
|
88
|
+
activeDpiStage: number;
|
|
89
|
+
stageCount: number;
|
|
90
|
+
dpiStages: number[];
|
|
91
|
+
dpiStagesY: number[];
|
|
92
|
+
currentDpi: number;
|
|
93
|
+
currentDpiY: number;
|
|
94
|
+
angleTuning: number;
|
|
95
|
+
angleSnapping: boolean;
|
|
96
|
+
liftOffDistance: "Low" | "High";
|
|
97
|
+
pixelThreshold: number;
|
|
98
|
+
minSqRun: number;
|
|
99
|
+
rawPayload: Uint8Array;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Decodes the 64-byte performance block returned by 0x52 0x40.
|
|
103
|
+
*/
|
|
104
|
+
export declare function coolermasterDecodePerformance(source: Uint8Array | DataView): CoolerMasterPerformance;
|
|
105
|
+
export interface CoolerMasterPerformanceUpdate {
|
|
106
|
+
activeDpiStage?: number;
|
|
107
|
+
stageCount?: number;
|
|
108
|
+
dpiStages?: readonly number[];
|
|
109
|
+
dpiStagesY?: readonly number[];
|
|
110
|
+
angleTuning?: number;
|
|
111
|
+
angleSnapping?: boolean;
|
|
112
|
+
liftOffDistance?: "Low" | "High";
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds the 64-byte write performance packet (0x51 0x40 ...), preserving
|
|
116
|
+
* existing values from baseFrame or defaults when not explicitly modified.
|
|
117
|
+
*/
|
|
118
|
+
export declare function coolermasterEncodeSetPerformance(update: CoolerMasterPerformanceUpdate, baseFrame?: Uint8Array): Uint8Array;
|
|
119
|
+
/** Builds the 64-byte get debounce request [0x52, 0x10, ...0x00]. */
|
|
120
|
+
export declare function coolermasterEncodeGetDebounce(): Uint8Array;
|
|
121
|
+
/** Decodes debounce ms from [0x52, 0x10, ...]. Offset 12 carries debounce ms. */
|
|
122
|
+
export declare function coolermasterDecodeDebounce(source: Uint8Array | DataView): number;
|
|
123
|
+
/** Builds the 64-byte set debounce command [0x51, 0x10, ...]. */
|
|
124
|
+
export declare function coolermasterEncodeSetDebounce(debounceMs: number, baseFrame?: Uint8Array): Uint8Array;
|
|
125
|
+
export declare function coolermasterDecodeBreathingSpeed(wireVal: number): number;
|
|
126
|
+
export declare function coolermasterDecodeColorCycleSpeed(wireVal: number): number;
|
|
127
|
+
/** Parses #rrggbb into RGB components (defaulting to 255, 0, 0). */
|
|
128
|
+
export declare function coolermasterParseHexColor(color: string | null | undefined): CoolerMasterRgbColor;
|
|
129
|
+
/** Formats RGB components into #rrggbb. */
|
|
130
|
+
export declare function coolermasterToHexColor(rgb: CoolerMasterRgbColor): string;
|
|
131
|
+
/** Builds the 64-byte get effect mode request [0x52, 0x28, ...0x00]. */
|
|
132
|
+
export declare function coolermasterEncodeGetEffectMode(): Uint8Array;
|
|
133
|
+
/** Decodes active effect mode ID from [0x52, 0x28, ...]. Offset 4 carries mode ID. */
|
|
134
|
+
export declare function coolermasterDecodeEffectMode(source: Uint8Array | DataView): number;
|
|
135
|
+
/** Builds the 64-byte set effect mode command [0x51, 0x28, 0x00, 0x00, modeId, ...]. */
|
|
136
|
+
export declare function coolermasterEncodeSetEffectMode(modeId: number): Uint8Array;
|
|
137
|
+
/** Builds the 64-byte get general effect request [0x52, 0x2b, 0x00, 0x00, modeId, ...]. */
|
|
138
|
+
export declare function coolermasterEncodeGetGeneralEffect(modeId: number): Uint8Array;
|
|
139
|
+
export interface CoolerMasterGeneralEffect {
|
|
140
|
+
modeId: number;
|
|
141
|
+
speedCode: number;
|
|
142
|
+
random: boolean;
|
|
143
|
+
brightness: number;
|
|
144
|
+
color: CoolerMasterRgbColor;
|
|
145
|
+
}
|
|
146
|
+
/** Decodes general effect parameters from [0x52, 0x2b, ...]. */
|
|
147
|
+
export declare function coolermasterDecodeGeneralEffect(source: Uint8Array | DataView): CoolerMasterGeneralEffect;
|
|
148
|
+
/** Builds the 64-byte set general effect command [0x51, 0x2b, ...]. */
|
|
149
|
+
export declare function coolermasterEncodeSetGeneralEffect(config: {
|
|
150
|
+
modeId: number;
|
|
151
|
+
speedCode?: number;
|
|
152
|
+
random?: boolean;
|
|
153
|
+
brightness?: number;
|
|
154
|
+
color?: CoolerMasterRgbColor;
|
|
155
|
+
}): Uint8Array;
|
|
156
|
+
/** Builds the 64-byte get custom effect request [0x52, 0xa8, ...0x00]. */
|
|
157
|
+
export declare function coolermasterEncodeGetCustomEffect(): Uint8Array;
|
|
158
|
+
export interface CoolerMasterCustomEffect {
|
|
159
|
+
wheel: CoolerMasterRgbColor;
|
|
160
|
+
logo: CoolerMasterRgbColor;
|
|
161
|
+
}
|
|
162
|
+
/** Decodes custom per-zone RGB colors from [0x52, 0xa8, ...]. */
|
|
163
|
+
export declare function coolermasterDecodeCustomEffect(source: Uint8Array | DataView): CoolerMasterCustomEffect;
|
|
164
|
+
/** Builds the 64-byte set custom effect command [0x51, 0xa8, 0x00, 0x00, R0, G0, B0, R1, G1, B1, ...]. */
|
|
165
|
+
export declare function coolermasterEncodeSetCustomEffect(wheel: CoolerMasterRgbColor, logo: CoolerMasterRgbColor): Uint8Array;
|
|
166
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/coolermaster/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,sBAAsB,OAAS,CAAC;AAC7C,eAAO,MAAM,6BAA6B,MAAS,CAAC;AAEpD,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,kBAAkB,IAAS,CAAC;AACzC,eAAO,MAAM,sBAAsB,IAAO,CAAC;AAC3C,eAAO,MA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AAM,CAAC;IACpB,KAAK,CAAC,EAAE,oBAAoB,CAAC;CAC9B,GAAG,UAAU,CAcb;AAED,0EAA0E;AAC1E,wBAAgB,iCAAiC,IAAI,UAAU,CAK9D;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,IAAI,EAAE,oBAAoB,CAAC;CAC5B;AAED,iEAAiE;AACjE,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,UAAU,GAAG,QAAQ,GAC5B,wBAAwB,CAsB1B;AAED,0GAA0G;AAC1G,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,oBAAoB,EAC3B,IAAI,EAAE,oBAAoB,GACzB,UAAU,CAWZ"}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cooler Master HID protocol codec.
|
|
3
|
+
*
|
|
4
|
+
* Reverse-engineered from Cooler Master MasterPlus+ v1.9.6 (CMUOT.dll/pdb,
|
|
5
|
+
* MM711PerformanceWid.dll/pdb, CfgFile.dll/pdb) and verified against a physical
|
|
6
|
+
* Cooler Master MM711 wired gaming mouse (VID 0x2516, PID 0x0101, MI_01).
|
|
7
|
+
*
|
|
8
|
+
* All control traffic uses raw 64-byte HID output/input reports on report ID 0x00
|
|
9
|
+
* (total 65 bytes on the wire including Report ID 0x00).
|
|
10
|
+
*
|
|
11
|
+
* Reference captures and ground truth fixtures:
|
|
12
|
+
* `captures/coolermaster-mm711/`
|
|
13
|
+
*/
|
|
14
|
+
export const COOLERMASTER_VENDOR_ID = 0x2516;
|
|
15
|
+
export const COOLERMASTER_MM711_PRODUCT_ID = 0x0101;
|
|
16
|
+
export const COOLERMASTER_USAGE_PAGE = 0xff00;
|
|
17
|
+
export const COOLERMASTER_USAGE = 0x0001;
|
|
18
|
+
export const COOLERMASTER_REPORT_ID = 0x00;
|
|
19
|
+
export const COOLERMASTER_PAYLOAD_SIZE = 64;
|
|
20
|
+
export const COOLERMASTER_REPORT_SIZE = 65;
|
|
21
|
+
export const COOLERMASTER_PRODUCT_IDS = [
|
|
22
|
+
COOLERMASTER_MM711_PRODUCT_ID,
|
|
23
|
+
];
|
|
24
|
+
export const COOLERMASTER_PRODUCT_NAMES = new Map([
|
|
25
|
+
[COOLERMASTER_MM711_PRODUCT_ID, "Cooler Master MM711"],
|
|
26
|
+
]);
|
|
27
|
+
export const COOLERMASTER_POLLING_RATES = [125, 250, 500, 1000];
|
|
28
|
+
export const COOLERMASTER_DPI_MIN = 100;
|
|
29
|
+
export const COOLERMASTER_DPI_MAX = 16000;
|
|
30
|
+
export const COOLERMASTER_DPI_STEP = 100;
|
|
31
|
+
export const COOLERMASTER_DPI_STAGE_COUNT = 7;
|
|
32
|
+
export const COOLERMASTER_DPI_OPTIONS = Array.from({ length: 160 }, (_, i) => (i + 1) * 100);
|
|
33
|
+
// Protocol command bytes
|
|
34
|
+
export const COOLERMASTER_CMD_HANDSHAKE_1 = 0x41;
|
|
35
|
+
export const COOLERMASTER_CMD_HANDSHAKE_2 = 0x80;
|
|
36
|
+
export const COOLERMASTER_CMD_READ = 0x52;
|
|
37
|
+
export const COOLERMASTER_CMD_WRITE = 0x51;
|
|
38
|
+
export const COOLERMASTER_SUB_PERFORMANCE = 0x40;
|
|
39
|
+
export const COOLERMASTER_SUB_DPI_LEVEL = 0x9b;
|
|
40
|
+
export const COOLERMASTER_SUB_POLLING = 0xf0;
|
|
41
|
+
export const COOLERMASTER_SUB_DEBOUNCE = 0x10;
|
|
42
|
+
export const COOLERMASTER_SUB_EFFECT_MODE = 0x28;
|
|
43
|
+
export const COOLERMASTER_SUB_GENERAL_EFFECT = 0x2b;
|
|
44
|
+
export const COOLERMASTER_SUB_CUSTOM_EFFECT = 0xa8;
|
|
45
|
+
// Lighting modes
|
|
46
|
+
export const COOLERMASTER_LIGHTING_MODE_STATIC = 0x00;
|
|
47
|
+
export const COOLERMASTER_LIGHTING_MODE_BREATH = 0x01;
|
|
48
|
+
export const COOLERMASTER_LIGHTING_MODE_COLOR_CYCLE = 0x02;
|
|
49
|
+
export const COOLERMASTER_LIGHTING_MODE_INDICATOR = 0x04;
|
|
50
|
+
export const COOLERMASTER_LIGHTING_MODE_CUSTOM = 0xb0;
|
|
51
|
+
export const COOLERMASTER_LIGHTING_MODE_OFF = 0xfe;
|
|
52
|
+
export const COOLERMASTER_LIGHTING_ZONES = ["Scroll wheel", "Logo"];
|
|
53
|
+
export const COOLERMASTER_BREATHING_SPEED_MAP = {
|
|
54
|
+
1: 60, // 0x3c
|
|
55
|
+
2: 55, // 0x37
|
|
56
|
+
3: 49, // 0x31
|
|
57
|
+
4: 44, // 0x2c
|
|
58
|
+
5: 38, // 0x26
|
|
59
|
+
};
|
|
60
|
+
export const COOLERMASTER_COLOR_CYCLE_SPEED_MAP = {
|
|
61
|
+
1: 50, // 0x32
|
|
62
|
+
2: 45, // 0x2d
|
|
63
|
+
3: 40, // 0x28
|
|
64
|
+
4: 35, // 0x23
|
|
65
|
+
5: 30, // 0x1e
|
|
66
|
+
};
|
|
67
|
+
/** Polling rate code mapping (matches CMUOT toInnerPollingRate / bInterval ms). */
|
|
68
|
+
export const COOLERMASTER_POLLING_RATE_MAP = {
|
|
69
|
+
1000: 1, // 1 ms
|
|
70
|
+
500: 2, // 2 ms
|
|
71
|
+
250: 4, // 4 ms
|
|
72
|
+
125: 8, // 8 ms
|
|
73
|
+
};
|
|
74
|
+
export const COOLERMASTER_POLLING_CODE_MAP = {
|
|
75
|
+
1: 1000,
|
|
76
|
+
2: 500,
|
|
77
|
+
4: 250,
|
|
78
|
+
8: 125,
|
|
79
|
+
};
|
|
80
|
+
export function coolermasterEncodePollingCode(hz) {
|
|
81
|
+
const code = COOLERMASTER_POLLING_RATE_MAP[hz];
|
|
82
|
+
if (code === undefined) {
|
|
83
|
+
throw new RangeError(`Unsupported Cooler Master polling rate: ${hz} Hz`);
|
|
84
|
+
}
|
|
85
|
+
return code;
|
|
86
|
+
}
|
|
87
|
+
export function coolermasterDecodePollingRateCode(code) {
|
|
88
|
+
const hz = COOLERMASTER_POLLING_CODE_MAP[code];
|
|
89
|
+
if (hz === undefined) {
|
|
90
|
+
throw new RangeError(`Unknown Cooler Master polling rate code: 0x${code.toString(16)}`);
|
|
91
|
+
}
|
|
92
|
+
return hz;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Encodes a DPI value into the raw hardware byte code:
|
|
96
|
+
* formula from CMUOT: (raw_code + 1) * 100 = DPI => raw_code = Math.round(dpi / 100) - 1.
|
|
97
|
+
*/
|
|
98
|
+
export function coolermasterEncodeDpi(dpi) {
|
|
99
|
+
if (!Number.isFinite(dpi)) {
|
|
100
|
+
throw new RangeError("DPI must be a finite number");
|
|
101
|
+
}
|
|
102
|
+
const clamped = Math.max(COOLERMASTER_DPI_MIN, Math.min(COOLERMASTER_DPI_MAX, dpi));
|
|
103
|
+
const rounded = Math.round(clamped / COOLERMASTER_DPI_STEP) * COOLERMASTER_DPI_STEP;
|
|
104
|
+
return (rounded / 100) - 1;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Decodes a raw hardware byte code to DPI: (raw_code + 1) * 100.
|
|
108
|
+
*/
|
|
109
|
+
export function coolermasterDecodeDpi(code) {
|
|
110
|
+
return (code + 1) * 100;
|
|
111
|
+
}
|
|
112
|
+
function normalizePayload(source) {
|
|
113
|
+
const bytes = source instanceof Uint8Array
|
|
114
|
+
? source
|
|
115
|
+
: new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
116
|
+
if (bytes.length === COOLERMASTER_REPORT_SIZE && bytes[0] === COOLERMASTER_REPORT_ID) {
|
|
117
|
+
return bytes.subarray(1);
|
|
118
|
+
}
|
|
119
|
+
if (bytes.length === COOLERMASTER_PAYLOAD_SIZE) {
|
|
120
|
+
return bytes;
|
|
121
|
+
}
|
|
122
|
+
throw new RangeError(`Invalid Cooler Master report length: expected 64 or 65 bytes, got ${bytes.length}`);
|
|
123
|
+
}
|
|
124
|
+
/** Builds the 64-byte handshake request [0x41, 0x80, ...0x00]. */
|
|
125
|
+
export function coolermasterEncodeHandshake() {
|
|
126
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
127
|
+
buf[0] = COOLERMASTER_CMD_HANDSHAKE_1;
|
|
128
|
+
buf[1] = COOLERMASTER_CMD_HANDSHAKE_2;
|
|
129
|
+
return buf;
|
|
130
|
+
}
|
|
131
|
+
/** Builds the 64-byte get polling rate request [0x52, 0xF0, ...0x00]. */
|
|
132
|
+
export function coolermasterEncodeGetPollingRate() {
|
|
133
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
134
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
135
|
+
buf[1] = COOLERMASTER_SUB_POLLING;
|
|
136
|
+
return buf;
|
|
137
|
+
}
|
|
138
|
+
/** Builds the 64-byte set polling rate command [0x51, 0xF0, 0x00, 0x00, code, ...0x00]. */
|
|
139
|
+
export function coolermasterEncodeSetPollingRate(hz) {
|
|
140
|
+
const code = coolermasterEncodePollingCode(hz);
|
|
141
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
142
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
143
|
+
buf[1] = COOLERMASTER_SUB_POLLING;
|
|
144
|
+
buf[2] = 0x00;
|
|
145
|
+
buf[3] = 0x00;
|
|
146
|
+
buf[4] = code;
|
|
147
|
+
return buf;
|
|
148
|
+
}
|
|
149
|
+
/** Decodes the polling rate response [0x52, 0xF0, 0x00, 0x00, code, ...]. */
|
|
150
|
+
export function coolermasterDecodePollingRate(source) {
|
|
151
|
+
const payload = normalizePayload(source);
|
|
152
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
153
|
+
payload[1] !== COOLERMASTER_SUB_POLLING) {
|
|
154
|
+
throw new Error(`Invalid Cooler Master polling reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
155
|
+
}
|
|
156
|
+
return coolermasterDecodePollingRateCode(payload[4]);
|
|
157
|
+
}
|
|
158
|
+
/** Builds the 64-byte get DPI level request [0x52, 0x9B, ...0x00]. */
|
|
159
|
+
export function coolermasterEncodeGetDpiLevel() {
|
|
160
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
161
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
162
|
+
buf[1] = COOLERMASTER_SUB_DPI_LEVEL;
|
|
163
|
+
return buf;
|
|
164
|
+
}
|
|
165
|
+
/** Decodes DPI level reply [0x52, 0x9B, 0x00, 0x00, 0x00, activeStage, ...order]. */
|
|
166
|
+
export function coolermasterDecodeDpiLevel(source) {
|
|
167
|
+
const payload = normalizePayload(source);
|
|
168
|
+
if (payload[0] !== COOLERMASTER_CMD_READ || payload[1] !== COOLERMASTER_SUB_DPI_LEVEL) {
|
|
169
|
+
throw new Error("Invalid Cooler Master DPI level reply.");
|
|
170
|
+
}
|
|
171
|
+
const activeDpiStage = payload[5];
|
|
172
|
+
const stageOrder = [];
|
|
173
|
+
for (let i = 6; i < 13; i++) {
|
|
174
|
+
stageOrder.push(payload[i]);
|
|
175
|
+
}
|
|
176
|
+
return { activeDpiStage, stageOrder };
|
|
177
|
+
}
|
|
178
|
+
/** Builds the 64-byte get performance request [0x52, 0x40, ...0x00]. */
|
|
179
|
+
export function coolermasterEncodeGetPerformance() {
|
|
180
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
181
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
182
|
+
buf[1] = COOLERMASTER_SUB_PERFORMANCE;
|
|
183
|
+
return buf;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Decodes the 64-byte performance block returned by 0x52 0x40.
|
|
187
|
+
*/
|
|
188
|
+
export function coolermasterDecodePerformance(source) {
|
|
189
|
+
const payload = normalizePayload(source);
|
|
190
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
191
|
+
payload[1] !== COOLERMASTER_SUB_PERFORMANCE) {
|
|
192
|
+
throw new Error(`Invalid Cooler Master performance reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
193
|
+
}
|
|
194
|
+
const activeDpiStage = payload[4];
|
|
195
|
+
const stageCount = payload[5];
|
|
196
|
+
const dpiStages = [];
|
|
197
|
+
for (let i = 0; i < COOLERMASTER_DPI_STAGE_COUNT; i++) {
|
|
198
|
+
dpiStages.push(coolermasterDecodeDpi(payload[6 + i]));
|
|
199
|
+
}
|
|
200
|
+
const dpiStagesY = [];
|
|
201
|
+
for (let i = 0; i < COOLERMASTER_DPI_STAGE_COUNT; i++) {
|
|
202
|
+
dpiStagesY.push(coolermasterDecodeDpi(payload[13 + i]));
|
|
203
|
+
}
|
|
204
|
+
const currentDpi = dpiStages[activeDpiStage] ?? dpiStages[0];
|
|
205
|
+
const currentDpiY = dpiStagesY[activeDpiStage] ?? dpiStagesY[0];
|
|
206
|
+
// Angle tuning is signed int8 at offset 27 (-30 to +30 degrees)
|
|
207
|
+
const rawAngleTune = payload[27];
|
|
208
|
+
const angleTuning = (rawAngleTune << 24) >> 24;
|
|
209
|
+
// Offset 28: bit 0 is angle snapping (0=off, 1=on)
|
|
210
|
+
// bits 1..2: if (byte & 6) == 6 => High LOD, else Low LOD
|
|
211
|
+
const flags = payload[28];
|
|
212
|
+
const angleSnapping = (flags & 0x01) === 0x01;
|
|
213
|
+
const liftOffDistance = (flags & 0x06) === 0x06 ? "High" : "Low";
|
|
214
|
+
const pixelThreshold = payload[29];
|
|
215
|
+
const minSqRun = payload[30];
|
|
216
|
+
return {
|
|
217
|
+
activeDpiStage,
|
|
218
|
+
stageCount,
|
|
219
|
+
dpiStages,
|
|
220
|
+
dpiStagesY,
|
|
221
|
+
currentDpi,
|
|
222
|
+
currentDpiY,
|
|
223
|
+
angleTuning,
|
|
224
|
+
angleSnapping,
|
|
225
|
+
liftOffDistance,
|
|
226
|
+
pixelThreshold,
|
|
227
|
+
minSqRun,
|
|
228
|
+
rawPayload: new Uint8Array(payload),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Builds the 64-byte write performance packet (0x51 0x40 ...), preserving
|
|
233
|
+
* existing values from baseFrame or defaults when not explicitly modified.
|
|
234
|
+
*/
|
|
235
|
+
export function coolermasterEncodeSetPerformance(update, baseFrame) {
|
|
236
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
237
|
+
if (baseFrame) {
|
|
238
|
+
const base = normalizePayload(baseFrame);
|
|
239
|
+
buf.set(base);
|
|
240
|
+
}
|
|
241
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
242
|
+
buf[1] = COOLERMASTER_SUB_PERFORMANCE;
|
|
243
|
+
if (update.activeDpiStage !== undefined) {
|
|
244
|
+
if (update.activeDpiStage < 0 || update.activeDpiStage >= COOLERMASTER_DPI_STAGE_COUNT) {
|
|
245
|
+
throw new RangeError(`Active DPI stage must be 0-${COOLERMASTER_DPI_STAGE_COUNT - 1}`);
|
|
246
|
+
}
|
|
247
|
+
buf[4] = update.activeDpiStage;
|
|
248
|
+
}
|
|
249
|
+
if (update.stageCount !== undefined) {
|
|
250
|
+
buf[5] = update.stageCount;
|
|
251
|
+
}
|
|
252
|
+
else if (!baseFrame) {
|
|
253
|
+
buf[5] = COOLERMASTER_DPI_STAGE_COUNT;
|
|
254
|
+
}
|
|
255
|
+
if (update.dpiStages) {
|
|
256
|
+
for (let i = 0; i < update.dpiStages.length && i < COOLERMASTER_DPI_STAGE_COUNT; i++) {
|
|
257
|
+
buf[6 + i] = coolermasterEncodeDpi(update.dpiStages[i]);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (update.dpiStagesY) {
|
|
261
|
+
for (let i = 0; i < update.dpiStagesY.length && i < COOLERMASTER_DPI_STAGE_COUNT; i++) {
|
|
262
|
+
buf[13 + i] = coolermasterEncodeDpi(update.dpiStagesY[i]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else if (update.dpiStages && !baseFrame) {
|
|
266
|
+
for (let i = 0; i < update.dpiStages.length && i < COOLERMASTER_DPI_STAGE_COUNT; i++) {
|
|
267
|
+
buf[13 + i] = coolermasterEncodeDpi(update.dpiStages[i]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (update.angleTuning !== undefined) {
|
|
271
|
+
const clamped = Math.max(-30, Math.min(30, update.angleTuning));
|
|
272
|
+
buf[27] = clamped & 0xff;
|
|
273
|
+
}
|
|
274
|
+
let currentFlags = buf[28];
|
|
275
|
+
if (update.angleSnapping !== undefined) {
|
|
276
|
+
currentFlags = update.angleSnapping ? (currentFlags | 0x01) : (currentFlags & ~0x01);
|
|
277
|
+
}
|
|
278
|
+
if (update.liftOffDistance !== undefined) {
|
|
279
|
+
if (update.liftOffDistance === "High") {
|
|
280
|
+
currentFlags = (currentFlags & ~0x06) | 0x06;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
currentFlags = (currentFlags & ~0x06) | 0x02;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
buf[28] = currentFlags;
|
|
287
|
+
if (!baseFrame) {
|
|
288
|
+
buf[29] = 0x0a; // default pixel threshold 10
|
|
289
|
+
buf[30] = 0x06; // default min_sq_run 6
|
|
290
|
+
}
|
|
291
|
+
return buf;
|
|
292
|
+
}
|
|
293
|
+
/** Builds the 64-byte get debounce request [0x52, 0x10, ...0x00]. */
|
|
294
|
+
export function coolermasterEncodeGetDebounce() {
|
|
295
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
296
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
297
|
+
buf[1] = COOLERMASTER_SUB_DEBOUNCE;
|
|
298
|
+
return buf;
|
|
299
|
+
}
|
|
300
|
+
/** Decodes debounce ms from [0x52, 0x10, ...]. Offset 12 carries debounce ms. */
|
|
301
|
+
export function coolermasterDecodeDebounce(source) {
|
|
302
|
+
const payload = normalizePayload(source);
|
|
303
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
304
|
+
payload[1] !== COOLERMASTER_SUB_DEBOUNCE) {
|
|
305
|
+
throw new Error(`Invalid Cooler Master debounce reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
306
|
+
}
|
|
307
|
+
return payload[12];
|
|
308
|
+
}
|
|
309
|
+
/** Builds the 64-byte set debounce command [0x51, 0x10, ...]. */
|
|
310
|
+
export function coolermasterEncodeSetDebounce(debounceMs, baseFrame) {
|
|
311
|
+
if (!Number.isInteger(debounceMs) || debounceMs < 1 || debounceMs > 32) {
|
|
312
|
+
throw new RangeError("Cooler Master debounce time must be an integer between 1 and 32 ms.");
|
|
313
|
+
}
|
|
314
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
315
|
+
if (baseFrame) {
|
|
316
|
+
buf.set(normalizePayload(baseFrame));
|
|
317
|
+
}
|
|
318
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
319
|
+
buf[1] = COOLERMASTER_SUB_DEBOUNCE;
|
|
320
|
+
buf[12] = debounceMs;
|
|
321
|
+
buf[16] = debounceMs;
|
|
322
|
+
return buf;
|
|
323
|
+
}
|
|
324
|
+
export function coolermasterDecodeBreathingSpeed(wireVal) {
|
|
325
|
+
let bestLevel = 3;
|
|
326
|
+
let bestDiff = Infinity;
|
|
327
|
+
for (const [lvlStr, val] of Object.entries(COOLERMASTER_BREATHING_SPEED_MAP)) {
|
|
328
|
+
const diff = Math.abs(val - wireVal);
|
|
329
|
+
if (diff < bestDiff) {
|
|
330
|
+
bestDiff = diff;
|
|
331
|
+
bestLevel = Number(lvlStr);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return bestLevel;
|
|
335
|
+
}
|
|
336
|
+
export function coolermasterDecodeColorCycleSpeed(wireVal) {
|
|
337
|
+
let bestLevel = 3;
|
|
338
|
+
let bestDiff = Infinity;
|
|
339
|
+
for (const [lvlStr, val] of Object.entries(COOLERMASTER_COLOR_CYCLE_SPEED_MAP)) {
|
|
340
|
+
const diff = Math.abs(val - wireVal);
|
|
341
|
+
if (diff < bestDiff) {
|
|
342
|
+
bestDiff = diff;
|
|
343
|
+
bestLevel = Number(lvlStr);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return bestLevel;
|
|
347
|
+
}
|
|
348
|
+
/** Parses #rrggbb into RGB components (defaulting to 255, 0, 0). */
|
|
349
|
+
export function coolermasterParseHexColor(color) {
|
|
350
|
+
if (!color || !color.startsWith("#")) {
|
|
351
|
+
return { r: 255, g: 0, b: 0 };
|
|
352
|
+
}
|
|
353
|
+
const clean = color.slice(1);
|
|
354
|
+
if (clean.length === 6) {
|
|
355
|
+
return {
|
|
356
|
+
r: Number.parseInt(clean.slice(0, 2), 16) || 0,
|
|
357
|
+
g: Number.parseInt(clean.slice(2, 4), 16) || 0,
|
|
358
|
+
b: Number.parseInt(clean.slice(4, 6), 16) || 0,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return { r: 255, g: 0, b: 0 };
|
|
362
|
+
}
|
|
363
|
+
/** Formats RGB components into #rrggbb. */
|
|
364
|
+
export function coolermasterToHexColor(rgb) {
|
|
365
|
+
const hexByte = (n) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, "0");
|
|
366
|
+
return `#${hexByte(rgb.r)}${hexByte(rgb.g)}${hexByte(rgb.b)}`;
|
|
367
|
+
}
|
|
368
|
+
/** Builds the 64-byte get effect mode request [0x52, 0x28, ...0x00]. */
|
|
369
|
+
export function coolermasterEncodeGetEffectMode() {
|
|
370
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
371
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
372
|
+
buf[1] = COOLERMASTER_SUB_EFFECT_MODE;
|
|
373
|
+
return buf;
|
|
374
|
+
}
|
|
375
|
+
/** Decodes active effect mode ID from [0x52, 0x28, ...]. Offset 4 carries mode ID. */
|
|
376
|
+
export function coolermasterDecodeEffectMode(source) {
|
|
377
|
+
const payload = normalizePayload(source);
|
|
378
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
379
|
+
payload[1] !== COOLERMASTER_SUB_EFFECT_MODE) {
|
|
380
|
+
throw new Error(`Invalid Cooler Master effect mode reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
381
|
+
}
|
|
382
|
+
return payload[4];
|
|
383
|
+
}
|
|
384
|
+
/** Builds the 64-byte set effect mode command [0x51, 0x28, 0x00, 0x00, modeId, ...]. */
|
|
385
|
+
export function coolermasterEncodeSetEffectMode(modeId) {
|
|
386
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
387
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
388
|
+
buf[1] = COOLERMASTER_SUB_EFFECT_MODE;
|
|
389
|
+
buf[4] = modeId & 0xff;
|
|
390
|
+
return buf;
|
|
391
|
+
}
|
|
392
|
+
/** Builds the 64-byte get general effect request [0x52, 0x2b, 0x00, 0x00, modeId, ...]. */
|
|
393
|
+
export function coolermasterEncodeGetGeneralEffect(modeId) {
|
|
394
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
395
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
396
|
+
buf[1] = COOLERMASTER_SUB_GENERAL_EFFECT;
|
|
397
|
+
buf[4] = modeId & 0xff;
|
|
398
|
+
return buf;
|
|
399
|
+
}
|
|
400
|
+
/** Decodes general effect parameters from [0x52, 0x2b, ...]. */
|
|
401
|
+
export function coolermasterDecodeGeneralEffect(source) {
|
|
402
|
+
const payload = normalizePayload(source);
|
|
403
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
404
|
+
payload[1] !== COOLERMASTER_SUB_GENERAL_EFFECT) {
|
|
405
|
+
throw new Error(`Invalid Cooler Master general effect reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
modeId: payload[4],
|
|
409
|
+
speedCode: payload[5],
|
|
410
|
+
random: (payload[6] & 0x80) !== 0,
|
|
411
|
+
brightness: payload[9],
|
|
412
|
+
color: {
|
|
413
|
+
r: payload[10],
|
|
414
|
+
g: payload[11],
|
|
415
|
+
b: payload[12],
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/** Builds the 64-byte set general effect command [0x51, 0x2b, ...]. */
|
|
420
|
+
export function coolermasterEncodeSetGeneralEffect(config) {
|
|
421
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
422
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
423
|
+
buf[1] = COOLERMASTER_SUB_GENERAL_EFFECT;
|
|
424
|
+
buf[4] = config.modeId & 0xff;
|
|
425
|
+
buf[5] = (config.speedCode ?? 0) & 0xff;
|
|
426
|
+
buf[6] = config.random ? 0xa0 : config.modeId === COOLERMASTER_LIGHTING_MODE_BREATH ? 0x20 : 0x00;
|
|
427
|
+
buf[7] = 0xff;
|
|
428
|
+
buf[8] = 0xff;
|
|
429
|
+
buf[9] = (config.brightness ?? 255) & 0xff;
|
|
430
|
+
buf[10] = (config.color?.r ?? 255) & 0xff;
|
|
431
|
+
buf[11] = (config.color?.g ?? 0) & 0xff;
|
|
432
|
+
buf[12] = (config.color?.b ?? 0) & 0xff;
|
|
433
|
+
return buf;
|
|
434
|
+
}
|
|
435
|
+
/** Builds the 64-byte get custom effect request [0x52, 0xa8, ...0x00]. */
|
|
436
|
+
export function coolermasterEncodeGetCustomEffect() {
|
|
437
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
438
|
+
buf[0] = COOLERMASTER_CMD_READ;
|
|
439
|
+
buf[1] = COOLERMASTER_SUB_CUSTOM_EFFECT;
|
|
440
|
+
return buf;
|
|
441
|
+
}
|
|
442
|
+
/** Decodes custom per-zone RGB colors from [0x52, 0xa8, ...]. */
|
|
443
|
+
export function coolermasterDecodeCustomEffect(source) {
|
|
444
|
+
const payload = normalizePayload(source);
|
|
445
|
+
if ((payload[0] !== COOLERMASTER_CMD_READ && payload[0] !== COOLERMASTER_CMD_WRITE) ||
|
|
446
|
+
payload[1] !== COOLERMASTER_SUB_CUSTOM_EFFECT) {
|
|
447
|
+
throw new Error(`Invalid Cooler Master custom effect reply: [0x${payload[0]?.toString(16)}, 0x${payload[1]?.toString(16)}]`);
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
wheel: {
|
|
451
|
+
r: payload[4],
|
|
452
|
+
g: payload[5],
|
|
453
|
+
b: payload[6],
|
|
454
|
+
},
|
|
455
|
+
logo: {
|
|
456
|
+
r: payload[7],
|
|
457
|
+
g: payload[8],
|
|
458
|
+
b: payload[9],
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
/** Builds the 64-byte set custom effect command [0x51, 0xa8, 0x00, 0x00, R0, G0, B0, R1, G1, B1, ...]. */
|
|
463
|
+
export function coolermasterEncodeSetCustomEffect(wheel, logo) {
|
|
464
|
+
const buf = new Uint8Array(COOLERMASTER_PAYLOAD_SIZE);
|
|
465
|
+
buf[0] = COOLERMASTER_CMD_WRITE;
|
|
466
|
+
buf[1] = COOLERMASTER_SUB_CUSTOM_EFFECT;
|
|
467
|
+
buf[4] = wheel.r & 0xff;
|
|
468
|
+
buf[5] = wheel.g & 0xff;
|
|
469
|
+
buf[6] = wheel.b & 0xff;
|
|
470
|
+
buf[7] = logo.r & 0xff;
|
|
471
|
+
buf[8] = logo.g & 0xff;
|
|
472
|
+
buf[9] = logo.b & 0xff;
|
|
473
|
+
return buf;
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=index.js.map
|