@openmouse/protocol 0.48.1 → 0.50.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/README.md +1 -0
- package/dist/drivers/atk/hid.d.ts.map +1 -1
- package/dist/drivers/atk/hid.js +2 -2
- package/dist/drivers/atk/hid.js.map +1 -1
- package/dist/drivers/atk/products.d.ts +7 -0
- package/dist/drivers/atk/products.d.ts.map +1 -1
- package/dist/drivers/atk/products.js +19 -2
- package/dist/drivers/atk/products.js.map +1 -1
- package/dist/drivers/glorious/sinowealth-hid.d.ts +71 -0
- package/dist/drivers/glorious/sinowealth-hid.d.ts.map +1 -0
- package/dist/drivers/glorious/sinowealth-hid.js +388 -0
- package/dist/drivers/glorious/sinowealth-hid.js.map +1 -0
- package/dist/drivers/gwolves/products.d.ts +5 -0
- package/dist/drivers/gwolves/products.d.ts.map +1 -1
- package/dist/drivers/gwolves/products.js +14 -10
- package/dist/drivers/gwolves/products.js.map +1 -1
- package/dist/drivers/gwolves/xvi-hid.d.ts +1 -0
- package/dist/drivers/gwolves/xvi-hid.d.ts.map +1 -1
- package/dist/drivers/gwolves/xvi-hid.js +14 -7
- package/dist/drivers/gwolves/xvi-hid.js.map +1 -1
- package/dist/drivers/hitscan/xvi-hid.d.ts +110 -0
- package/dist/drivers/hitscan/xvi-hid.d.ts.map +1 -0
- package/dist/drivers/hitscan/xvi-hid.js +803 -0
- package/dist/drivers/hitscan/xvi-hid.js.map +1 -0
- package/dist/drivers/motospeed/hid.js +1 -1
- package/dist/drivers/motospeed/hid.js.map +1 -1
- package/dist/drivers/mouse-types.d.ts +16 -0
- package/dist/drivers/mouse-types.d.ts.map +1 -1
- package/dist/drivers/razer/hid.d.ts +0 -1
- package/dist/drivers/razer/hid.d.ts.map +1 -1
- package/dist/drivers/razer/hid.js +14 -9
- package/dist/drivers/razer/hid.js.map +1 -1
- package/dist/drivers/redragon/hid.d.ts +44 -63
- package/dist/drivers/redragon/hid.d.ts.map +1 -1
- package/dist/drivers/redragon/hid.js +207 -270
- package/dist/drivers/redragon/hid.js.map +1 -1
- package/dist/drivers/registry.d.ts +2 -1
- package/dist/drivers/registry.d.ts.map +1 -1
- package/dist/drivers/registry.js +10 -1
- package/dist/drivers/registry.js.map +1 -1
- package/dist/drivers/vendors.d.ts +8 -1
- package/dist/drivers/vendors.d.ts.map +1 -1
- package/dist/drivers/vendors.js +18 -4
- package/dist/drivers/vendors.js.map +1 -1
- package/dist/gearhub/index.d.ts +8 -0
- package/dist/gearhub/index.d.ts.map +1 -1
- package/dist/gearhub/index.js +18 -0
- package/dist/gearhub/index.js.map +1 -1
- package/dist/glorious-sinowealth/index.d.ts +165 -0
- package/dist/glorious-sinowealth/index.d.ts.map +1 -0
- package/dist/glorious-sinowealth/index.js +345 -0
- package/dist/glorious-sinowealth/index.js.map +1 -0
- package/dist/hitscan/index.d.ts +2 -0
- package/dist/hitscan/index.d.ts.map +1 -1
- package/dist/hitscan/index.js +2 -0
- package/dist/hitscan/index.js.map +1 -1
- package/dist/hitscan/xvi-inputs.d.ts +81 -0
- package/dist/hitscan/xvi-inputs.d.ts.map +1 -0
- package/dist/hitscan/xvi-inputs.js +393 -0
- package/dist/hitscan/xvi-inputs.js.map +1 -0
- package/dist/hitscan/xvi.d.ts +278 -0
- package/dist/hitscan/xvi.d.ts.map +1 -0
- package/dist/hitscan/xvi.js +773 -0
- package/dist/hitscan/xvi.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keychron/index.d.ts.map +1 -1
- package/dist/keychron/index.js +4 -0
- package/dist/keychron/index.js.map +1 -1
- package/dist/razer/codec.d.ts +3 -2
- package/dist/razer/codec.d.ts.map +1 -1
- package/dist/razer/codec.js +5 -4
- package/dist/razer/codec.js.map +1 -1
- package/dist/redragon/deprecated.d.ts +24 -0
- package/dist/redragon/deprecated.d.ts.map +1 -0
- package/dist/redragon/deprecated.js +54 -0
- package/dist/redragon/deprecated.js.map +1 -0
- package/dist/redragon/holtek.d.ts +127 -0
- package/dist/redragon/holtek.d.ts.map +1 -0
- package/dist/redragon/holtek.js +232 -0
- package/dist/redragon/holtek.js.map +1 -0
- package/dist/redragon/index.d.ts +9 -203
- package/dist/redragon/index.d.ts.map +1 -1
- package/dist/redragon/index.js +11 -430
- package/dist/redragon/index.js.map +1 -1
- package/dist/redragon/m612.d.ts +82 -0
- package/dist/redragon/m612.d.ts.map +1 -0
- package/dist/redragon/m612.js +166 -0
- package/dist/redragon/m612.js.map +1 -0
- package/dist/redragon/m724.d.ts +47 -0
- package/dist/redragon/m724.d.ts.map +1 -0
- package/dist/redragon/m724.js +107 -0
- package/dist/redragon/m724.js.map +1 -0
- package/package.json +5 -1
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REDRAGON_ACTIVE_PROFILE_ADDRESS, REDRAGON_BUTTON_BASES, REDRAGON_BUTTON_LENGTH, REDRAGON_COMMIT_CODES, REDRAGON_CONFIG_USAGE, REDRAGON_CONFIG_USAGE_PAGE, REDRAGON_M612_EFFECTS, REDRAGON_M612_LIGHTING_BLOCK_LENGTH, REDRAGON_M612_LIGHTING_EFFECT_ADDRESS, REDRAGON_M724_EFFECTS, REDRAGON_M724_LIGHTING_BLOCK_LENGTH, REDRAGON_MAX_TRANSFER, REDRAGON_MODELS, REDRAGON_POLLING_CODES, REDRAGON_POLLING_RATES, REDRAGON_PRODUCTS, REDRAGON_PRODUCT_IDS, REDRAGON_PROFILE_BASES, REDRAGON_PROFILE_COUNT, REDRAGON_PROFILE_SELECT_CODE, REDRAGON_REPORT_ID, REDRAGON_SLOT_LENGTH, REDRAGON_STAGE_COUNT, REDRAGON_VENDOR_ID, redragonDecodeRead, redragonEncodeCommit, redragonEncodeRead, redragonEncodeWrite, redragonM612EffectForBit, redragonM724EffectForBlock, redragonM724LightingAddress, redragonPollAddress, redragonSession, redragonSlotAddress, } from "@openmouse/protocol/redragon";
|
|
2
2
|
/** RDCfg gaps consecutive writes ~8-18 ms; stay well above that. */
|
|
3
3
|
const WRITE_DELAY_MS = 30;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
4
|
+
const LIFT_OFF_LEVELS = ["Low", "Medium", "High"];
|
|
5
|
+
/** RDCfg's three brightness positions as percentages. */
|
|
6
|
+
const BRIGHTNESS = [33, 67, 100];
|
|
7
|
+
/** Lighting speed 1 (slowest) to 8; the wire byte is `9 - speed`. */
|
|
8
|
+
const SPEEDS = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
9
|
+
/** M612 effects OpenMouse can show; FLASH has no matching lighting mode. */
|
|
10
|
+
const M612_MODES = [
|
|
11
|
+
["static", "Static"],
|
|
12
|
+
["breathing", "Breathing single"],
|
|
13
|
+
["spectrumBreathing", "Breathing random"],
|
|
14
|
+
["wave", "Wave"],
|
|
15
|
+
["off", "Off"],
|
|
16
|
+
];
|
|
17
|
+
/** True when the `0xFFA0:0x01` collection with feature report 2 is present at any depth. */
|
|
7
18
|
function hasConfigCollection(collections) {
|
|
8
19
|
return collections.some((collection) => (collection.usagePage === REDRAGON_CONFIG_USAGE_PAGE &&
|
|
9
20
|
collection.usage === REDRAGON_CONFIG_USAGE &&
|
|
10
21
|
(collection.featureReports ?? []).some((report) => report.reportId === REDRAGON_REPORT_ID)) ||
|
|
11
22
|
hasConfigCollection(collection.children ?? []));
|
|
12
23
|
}
|
|
24
|
+
const hex = (bytes) => Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join(" ");
|
|
13
25
|
/**
|
|
14
|
-
* Redragon K1NG 1K
|
|
26
|
+
* Redragon Holtek mice (K1NG 1K M724 `04d9:fc7a`, Predator M612 `04d9:fc61`)
|
|
27
|
+
* over WebHID.
|
|
15
28
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* therefore reports this session's last-written stages (or the factory
|
|
23
|
-
* table before any write) with `valuesVerified: false`, and the only
|
|
24
|
-
* hardware probe is the `FA FA` marker every `GET_FEATURE` echo carries.
|
|
29
|
+
* Both keep their settings in one flat memory on the `0xFFA0:0x01`
|
|
30
|
+
* collection (see `@openmouse/protocol/redragon`): every value shown is
|
|
31
|
+
* read from the mouse with `F2`, and every write runs inside the vendor
|
|
32
|
+
* bracket, is followed by the commit block, and is read back before it is
|
|
33
|
+
* reported as done. DPI stages, polling, buttons, and (on the M724)
|
|
34
|
+
* lighting live per onboard profile, so they follow the active profile.
|
|
25
35
|
*/
|
|
26
36
|
export class RedragonHidClient {
|
|
27
37
|
device;
|
|
38
|
+
model;
|
|
28
39
|
queue = Promise.resolve();
|
|
29
|
-
|
|
30
|
-
lastPollingHz = null;
|
|
40
|
+
/** Throws for a PID without a model descriptor; `isSupported` filters those out first. */
|
|
31
41
|
constructor(device) {
|
|
42
|
+
const model = REDRAGON_MODELS.get(device.productId);
|
|
43
|
+
if (!model)
|
|
44
|
+
throw new Error(`Redragon product 0x${device.productId.toString(16)} is not a supported Holtek mouse.`);
|
|
32
45
|
this.device = device;
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
if (new.target === RedragonHidClient &&
|
|
46
|
+
this.model = model;
|
|
47
|
+
// Compatibility: before the shared client, M612 devices built through
|
|
48
|
+
// this constructor were `RedragonM612HidClient` instances.
|
|
49
|
+
if (new.target === RedragonHidClient && model.model === "M612")
|
|
37
50
|
return new RedragonM612HidClient(device);
|
|
38
|
-
}
|
|
39
51
|
}
|
|
52
|
+
/** Holtek VID, a catalogued PID, and the config collection (the mouse and keyboard interfaces lack it). */
|
|
40
53
|
static isSupported(device) {
|
|
41
54
|
if (device.vendorId !== REDRAGON_VENDOR_ID)
|
|
42
55
|
return false;
|
|
@@ -48,7 +61,7 @@ export class RedragonHidClient {
|
|
|
48
61
|
return [...REDRAGON_POLLING_RATES];
|
|
49
62
|
}
|
|
50
63
|
getDpiOptions() {
|
|
51
|
-
return [
|
|
64
|
+
return [...this.model.dpi.labels];
|
|
52
65
|
}
|
|
53
66
|
async open() {
|
|
54
67
|
if (!this.device.opened)
|
|
@@ -61,172 +74,10 @@ export class RedragonHidClient {
|
|
|
61
74
|
async readStatus() {
|
|
62
75
|
return await this.run(async () => {
|
|
63
76
|
await this.open();
|
|
64
|
-
await this.probeConfigChannel();
|
|
65
|
-
const product = REDRAGON_PRODUCTS.get(this.device.productId);
|
|
66
|
-
// The firmware reports a generic "USB Gaming Mouse" product string,
|
|
67
|
-
// so prefer the catalog name whenever the PID is known.
|
|
68
|
-
const name = product ? `Redragon ${product.name}` : (this.device.productName?.trim() || "Redragon Mouse");
|
|
69
|
-
const stages = this.lastStages ?? [...FACTORY_STAGES];
|
|
70
|
-
return {
|
|
71
|
-
brand: "Redragon",
|
|
72
|
-
name,
|
|
73
|
-
ui: {
|
|
74
|
-
family: "redragon",
|
|
75
|
-
settingsReady: true,
|
|
76
|
-
valuesVerified: false,
|
|
77
|
-
hideUnsupportedPollingRates: true,
|
|
78
|
-
hideProcessingCard: true,
|
|
79
|
-
pollingNote: "The M724 never reports its polling rate; the value shown is this session's last write, or 1000 Hz before any write.",
|
|
80
|
-
statusNote: "The K1NG 1K never reports settings back; values shown are this session's last writes, or the factory table before any write.",
|
|
81
|
-
dpiStageEditor: {
|
|
82
|
-
maxStages: REDRAGON_PROFILE0_DPI_SUBCMDS.length,
|
|
83
|
-
countEditable: false,
|
|
84
|
-
minDpi: 50,
|
|
85
|
-
maxDpi: product?.maxDpi ?? 12400,
|
|
86
|
-
stepDpi: 50,
|
|
87
|
-
},
|
|
88
|
-
defaultDisplayName: `Redragon ${product?.name ?? "Mouse"}`,
|
|
89
|
-
},
|
|
90
|
-
batteryPercent: null,
|
|
91
|
-
batteryState: "Unknown",
|
|
92
|
-
dpi: stages[0] ?? FACTORY_STAGES[0],
|
|
93
|
-
dpiStages: stages,
|
|
94
|
-
pollingRateHz: this.lastPollingHz ?? DEFAULT_POLLING_HZ,
|
|
95
|
-
supportedPollingRates: this.supportedPollingRates,
|
|
96
|
-
activeProfile: null,
|
|
97
|
-
connectionType: "Wired",
|
|
98
|
-
liftOffDistance: null,
|
|
99
|
-
firmware: [],
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Writes the whole profile-1 DPI table in one vendor session bracket,
|
|
105
|
-
* closed by the commit block. Bisected live: RDCfg re-pushes the table on
|
|
106
|
-
* every Apply and the change is felt immediately; a lone slot write is
|
|
107
|
-
* stored but only takes effect at boot, and the trailing `F1` block is
|
|
108
|
-
* what activates it. Sibling stages come from this session's cache
|
|
109
|
-
* (factory table before any write): editing in RDCfg meanwhile makes the
|
|
110
|
-
* cache stale, exactly like any write-only driver.
|
|
111
|
-
*/
|
|
112
|
-
async setDpiStageValue(stage, dpi) {
|
|
113
|
-
if (!Number.isInteger(stage) || stage < 0 || stage >= REDRAGON_PROFILE0_DPI_SUBCMDS.length) {
|
|
114
|
-
throw new Error(`Redragon DPI stage ${stage} is out of range 0-4.`);
|
|
115
|
-
}
|
|
116
|
-
// Validates the DPI before anything is sent.
|
|
117
|
-
redragonEncodeDpiSlot(REDRAGON_PROFILE0, stage, dpi);
|
|
118
|
-
await this.run(async () => {
|
|
119
|
-
await this.open();
|
|
120
|
-
const next = [...(this.lastStages ?? FACTORY_STAGES)];
|
|
121
|
-
next[stage] = dpi;
|
|
122
|
-
await this.writeSession(async () => {
|
|
123
|
-
for (let level = 0; level < REDRAGON_PROFILE0_DPI_SUBCMDS.length; level++) {
|
|
124
|
-
await this.sendFrame(redragonEncodeDpiSlot(REDRAGON_PROFILE0, level, next[level]));
|
|
125
|
-
}
|
|
126
|
-
for (const code of REDRAGON_COMMIT_CODES) {
|
|
127
|
-
await this.sendFrame(redragonEncodeCommit(code));
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
this.lastStages = next;
|
|
131
|
-
});
|
|
132
|
-
return dpi;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Writes the polling rate inside the same session bracket + commit block
|
|
136
|
-
* as DPI writes (the vendor sends it mid-push; the trailing `F1` block is
|
|
137
|
-
* what activates writes, verified live for DPI).
|
|
138
|
-
*/
|
|
139
|
-
async setPollingRate(hz) {
|
|
140
|
-
const frame = redragonEncodePollingRate(hz);
|
|
141
|
-
await this.run(async () => {
|
|
142
|
-
await this.open();
|
|
143
|
-
await this.writeSession(async () => {
|
|
144
|
-
await this.sendFrame(frame);
|
|
145
|
-
for (const code of REDRAGON_COMMIT_CODES) {
|
|
146
|
-
await this.sendFrame(redragonEncodeCommit(code));
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
this.lastPollingHz = hz;
|
|
150
|
-
});
|
|
151
|
-
return hz;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* The `FA FA` echo every `GET_FEATURE` carries doubles as the proof that
|
|
155
|
-
* the granted interface is the config channel: the mouse and keyboard
|
|
156
|
-
* interfaces expose no feature report 2 at all. The marker is matched as
|
|
157
|
-
* the last two payload bytes so both WebHID framings (report id stripped
|
|
158
|
-
* or kept) validate.
|
|
159
|
-
*/
|
|
160
|
-
async probeConfigChannel() {
|
|
161
|
-
const view = await this.device.receiveFeatureReport(REDRAGON_REPORT_ID);
|
|
162
|
-
const echo = new Uint8Array(view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength));
|
|
163
|
-
console.debug("[redragon] feature2 echo", [...echo].map((b) => b.toString(16).padStart(2, "0")).join(" "));
|
|
164
|
-
const marker = echo.length >= 2 && echo[echo.length - 2] === 0xfa && echo[echo.length - 1] === 0xfa;
|
|
165
|
-
if (!marker) {
|
|
166
|
-
throw new Error(`The Redragon config channel answered ${echo.length} bytes without its FA FA marker (see console "[redragon] feature2 echo"). Add the device again and choose the entry backed by the vendor interface.`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async sendFrame(frame) {
|
|
170
|
-
await this.device.sendFeatureReport(REDRAGON_REPORT_ID, frame.slice(1).buffer);
|
|
171
|
-
await new Promise((resolve) => setTimeout(resolve, WRITE_DELAY_MS));
|
|
172
|
-
}
|
|
173
|
-
async sendSessionFrame(begin) {
|
|
174
|
-
await this.sendFrame(begin ? redragonHello() : redragonSession(false));
|
|
175
|
-
}
|
|
176
|
-
async writeSession(operation) {
|
|
177
|
-
await this.sendSessionFrame(true);
|
|
178
|
-
try {
|
|
179
|
-
await operation();
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
await this.sendSessionFrame(false);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async run(operation) {
|
|
186
|
-
const result = this.queue.then(operation, operation);
|
|
187
|
-
this.queue = result.then(() => undefined, () => undefined);
|
|
188
|
-
return await result;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/** RDCfg's button numbers, named for what each one is on the mouse. */
|
|
192
|
-
const M612_BUTTON_NAMES = [
|
|
193
|
-
"Left (1)", "Right (2)", "Wheel click (3)", "Fire (4)", "Button 5", "Button 6",
|
|
194
|
-
"Button 7", "Button 8", "Button 9", "Wheel up", "Wheel down",
|
|
195
|
-
];
|
|
196
|
-
/** RDCfg effects OpenMouse can show; FLASH has no matching lighting mode. */
|
|
197
|
-
const M612_MODES = [
|
|
198
|
-
["static", "Static"],
|
|
199
|
-
["breathing", "Breathing single"],
|
|
200
|
-
["spectrumBreathing", "Breathing random"],
|
|
201
|
-
["wave", "Wave"],
|
|
202
|
-
["off", "Off"],
|
|
203
|
-
];
|
|
204
|
-
/** RDCfg's three brightness positions as percentages. */
|
|
205
|
-
const M612_BRIGHTNESS = [33, 67, 100];
|
|
206
|
-
const M612_SPEEDS = Array.from({ length: REDRAGON_M612_LIGHTING_SPEEDS }, (_, index) => index + 1);
|
|
207
|
-
/**
|
|
208
|
-
* Redragon Predator M612 (`04d9:fc61`) WebHID control.
|
|
209
|
-
*
|
|
210
|
-
* Same Holtek transport as the M724, but the M612 answers `F2` reads (see
|
|
211
|
-
* `redragonEncodeRead`), so every value shown is read from the mouse and
|
|
212
|
-
* every write is read back before it is reported as done. Reads need no
|
|
213
|
-
* session bracket; writes use the vendor bracket and commit block.
|
|
214
|
-
*
|
|
215
|
-
* DPI stages live per onboard profile, so writes target whichever profile
|
|
216
|
-
* the mouse reports as active. DPI values snap to the positions RDCfg's
|
|
217
|
-
* slider offers and report its label for them.
|
|
218
|
-
*/
|
|
219
|
-
export class RedragonM612HidClient extends RedragonHidClient {
|
|
220
|
-
getDpiOptions() {
|
|
221
|
-
return [...REDRAGON_M612_DPI_LABELS];
|
|
222
|
-
}
|
|
223
|
-
async readStatus() {
|
|
224
|
-
return await this.run(async () => {
|
|
225
|
-
await this.open();
|
|
226
|
-
await this.probeConfigChannel();
|
|
227
77
|
const settings = await this.readSettings();
|
|
228
|
-
const product = REDRAGON_PRODUCTS.get(
|
|
229
|
-
const labels =
|
|
78
|
+
const product = REDRAGON_PRODUCTS.get(this.model.productId);
|
|
79
|
+
const labels = this.model.dpi.labels;
|
|
80
|
+
const liftOff = await this.readLiftOff();
|
|
230
81
|
return {
|
|
231
82
|
brand: "Redragon",
|
|
232
83
|
name: `Redragon ${product.name}`,
|
|
@@ -237,11 +88,11 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
237
88
|
hideUnsupportedPollingRates: true,
|
|
238
89
|
hideProcessingCard: true,
|
|
239
90
|
dpiStageEditor: {
|
|
240
|
-
maxStages:
|
|
91
|
+
maxStages: REDRAGON_STAGE_COUNT,
|
|
241
92
|
countEditable: false,
|
|
242
93
|
minDpi: labels[0],
|
|
243
94
|
maxDpi: labels[labels.length - 1],
|
|
244
|
-
stepDpi:
|
|
95
|
+
stepDpi: this.model.dpi.step,
|
|
245
96
|
},
|
|
246
97
|
defaultDisplayName: `Redragon ${product.name}`,
|
|
247
98
|
showAdvancedSection: true,
|
|
@@ -254,12 +105,13 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
254
105
|
pollingRateHz: settings.pollingHz,
|
|
255
106
|
supportedPollingRates: this.supportedPollingRates,
|
|
256
107
|
activeProfile: settings.profile + 1,
|
|
257
|
-
profileCount:
|
|
108
|
+
profileCount: REDRAGON_PROFILE_COUNT,
|
|
258
109
|
buttonMappings: await this.readButtonMappings(settings.profile),
|
|
259
|
-
buttonOptions: [...
|
|
260
|
-
lighting: await this.
|
|
110
|
+
buttonOptions: [...this.model.buttons.options],
|
|
111
|
+
lighting: this.model.lighting === "profile" ? await this.readProfileLighting(settings.profile) : await this.readEffectLighting(),
|
|
261
112
|
connectionType: "Wired",
|
|
262
|
-
liftOffDistance:
|
|
113
|
+
liftOffDistance: liftOff,
|
|
114
|
+
...(this.model.liftOffAddress === undefined ? {} : { supportedLiftOffDistances: [...LIFT_OFF_LEVELS] }),
|
|
263
115
|
firmware: [],
|
|
264
116
|
};
|
|
265
117
|
});
|
|
@@ -271,29 +123,28 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
271
123
|
*/
|
|
272
124
|
async setDpiStageValue(stage, dpi) {
|
|
273
125
|
// Validate both before anything is sent.
|
|
274
|
-
const code =
|
|
275
|
-
|
|
126
|
+
const code = this.model.dpi.encode(dpi);
|
|
127
|
+
redragonSlotAddress(0, stage);
|
|
276
128
|
return await this.run(async () => {
|
|
277
129
|
await this.open();
|
|
278
|
-
const address =
|
|
279
|
-
const slot = await this.readBytes(address,
|
|
130
|
+
const address = redragonSlotAddress(await this.readActiveProfile(), stage);
|
|
131
|
+
const slot = await this.readBytes(address, REDRAGON_SLOT_LENGTH);
|
|
280
132
|
await this.writeAndConfirm(address, [slot[0], code.value, code.range, code.value, code.range]);
|
|
281
133
|
return code.dpi;
|
|
282
134
|
});
|
|
283
135
|
}
|
|
284
136
|
/** Selects the active DPI stage of the active profile, as the DPI button does. */
|
|
285
137
|
async setActiveDpiStage(stage) {
|
|
286
|
-
if (!Number.isInteger(stage) || stage < 0 || stage >=
|
|
287
|
-
throw new Error(`Redragon
|
|
138
|
+
if (!Number.isInteger(stage) || stage < 0 || stage >= REDRAGON_STAGE_COUNT) {
|
|
139
|
+
throw new Error(`Redragon DPI stage ${stage} is outside 0-${REDRAGON_STAGE_COUNT - 1}.`);
|
|
288
140
|
}
|
|
289
141
|
return await this.run(async () => {
|
|
290
142
|
await this.open();
|
|
291
|
-
|
|
292
|
-
await this.writeAndConfirm(base, [stage]);
|
|
143
|
+
await this.writeAndConfirm(REDRAGON_PROFILE_BASES[await this.readActiveProfile()], [stage]);
|
|
293
144
|
return stage;
|
|
294
145
|
});
|
|
295
146
|
}
|
|
296
|
-
/** Rewrites the polling code, keeping the
|
|
147
|
+
/** Rewrites the active profile's polling code, keeping the byte after it. */
|
|
297
148
|
async setPollingRate(hz) {
|
|
298
149
|
const code = REDRAGON_POLLING_CODES[hz];
|
|
299
150
|
if (code === undefined) {
|
|
@@ -301,26 +152,30 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
301
152
|
}
|
|
302
153
|
return await this.run(async () => {
|
|
303
154
|
await this.open();
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
await this.writeAndConfirm(
|
|
155
|
+
const address = redragonPollAddress(await this.readActiveProfile());
|
|
156
|
+
const [, next] = await this.readBytes(address, 2);
|
|
157
|
+
await this.writeAndConfirm(address, [code, next]);
|
|
307
158
|
return hz;
|
|
308
159
|
});
|
|
309
160
|
}
|
|
310
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Switches the onboard profile (1-5) as RDCfg's MODE menu does: the profile
|
|
163
|
+
* byte outside any bracket, `F1 02 01`, then the commit block. Without the
|
|
164
|
+
* block the M724 stores the byte but keeps the old profile running.
|
|
165
|
+
*/
|
|
311
166
|
async setProfile(profile) {
|
|
312
|
-
if (!Number.isInteger(profile) || profile < 1 || profile >
|
|
313
|
-
throw new Error(`Redragon
|
|
167
|
+
if (!Number.isInteger(profile) || profile < 1 || profile > REDRAGON_PROFILE_COUNT) {
|
|
168
|
+
throw new Error(`Redragon profile ${profile} is outside 1-${REDRAGON_PROFILE_COUNT}.`);
|
|
314
169
|
}
|
|
315
170
|
await this.run(async () => {
|
|
316
171
|
await this.open();
|
|
317
|
-
const current = await this.readBytes(
|
|
172
|
+
const current = await this.readBytes(REDRAGON_ACTIVE_PROFILE_ADDRESS, 2);
|
|
318
173
|
const next = [profile - 1, current[1]];
|
|
319
|
-
await this.sendFrame(redragonEncodeWrite(
|
|
320
|
-
await this.sendFrame(redragonEncodeCommit(
|
|
174
|
+
await this.sendFrame(redragonEncodeWrite(REDRAGON_ACTIVE_PROFILE_ADDRESS, next));
|
|
175
|
+
await this.sendFrame(redragonEncodeCommit(REDRAGON_PROFILE_SELECT_CODE));
|
|
321
176
|
for (const code of REDRAGON_COMMIT_CODES)
|
|
322
177
|
await this.sendFrame(redragonEncodeCommit(code));
|
|
323
|
-
await this.confirm(
|
|
178
|
+
await this.confirm(REDRAGON_ACTIVE_PROFILE_ADDRESS, next);
|
|
324
179
|
});
|
|
325
180
|
}
|
|
326
181
|
/**
|
|
@@ -329,10 +184,10 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
329
184
|
* leave the mouse unable to click.
|
|
330
185
|
*/
|
|
331
186
|
async setButtonMapping(button, action) {
|
|
332
|
-
const slot =
|
|
187
|
+
const slot = this.model.buttons.names.indexOf(button);
|
|
333
188
|
if (slot < 0)
|
|
334
|
-
throw new Error(`The Redragon
|
|
335
|
-
const value =
|
|
189
|
+
throw new Error(`The Redragon ${this.model.model} has no button named "${button}".`);
|
|
190
|
+
const value = this.model.buttons.encode(action);
|
|
336
191
|
await this.run(async () => {
|
|
337
192
|
await this.open();
|
|
338
193
|
const profile = await this.readActiveProfile();
|
|
@@ -343,30 +198,67 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
343
198
|
throw new Error("Keep Left click on at least one button, or the mouse cannot click.");
|
|
344
199
|
}
|
|
345
200
|
}
|
|
346
|
-
await this.writeAndConfirm(
|
|
201
|
+
await this.writeAndConfirm(REDRAGON_BUTTON_BASES[profile] + this.model.buttons.offsets[slot], value);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** Sets the lift-off height (M724 only): Low, Medium, or High. */
|
|
205
|
+
async setLiftOffDistance(value) {
|
|
206
|
+
const address = this.model.liftOffAddress;
|
|
207
|
+
if (address === undefined)
|
|
208
|
+
throw new Error(`The Redragon ${this.model.model} has no lift-off setting.`);
|
|
209
|
+
const level = LIFT_OFF_LEVELS.indexOf(value);
|
|
210
|
+
if (level < 0)
|
|
211
|
+
throw new Error(`Redragon lift-off "${value}" is not Low, Medium, or High.`);
|
|
212
|
+
await this.run(async () => {
|
|
213
|
+
await this.open();
|
|
214
|
+
const [, next] = await this.readBytes(address, 2);
|
|
215
|
+
await this.writeAndConfirm(address, [level, next]);
|
|
347
216
|
});
|
|
217
|
+
return value;
|
|
348
218
|
}
|
|
349
219
|
/**
|
|
350
|
-
* Writes the
|
|
351
|
-
*
|
|
352
|
-
* the current effect shows is treated as unchanged, so switching
|
|
353
|
-
* keeps the target effect's own stored values.
|
|
220
|
+
* Writes the lighting. On the M612 that is the global effect selector and
|
|
221
|
+
* that effect's parameter block, where a colour, speed, or brightness equal
|
|
222
|
+
* to what the current effect shows is treated as unchanged, so switching
|
|
223
|
+
* effects keeps the target effect's own stored values. On the M724 it is
|
|
224
|
+
* the active profile's single block.
|
|
354
225
|
*/
|
|
355
226
|
async setLighting(lighting) {
|
|
227
|
+
const model = this.model.model;
|
|
228
|
+
if (lighting.speed != null && !SPEEDS.includes(lighting.speed)) {
|
|
229
|
+
throw new Error(`Redragon ${model} lighting speed ${lighting.speed} is outside 1-${SPEEDS.length}.`);
|
|
230
|
+
}
|
|
231
|
+
if (lighting.brightness != null && !BRIGHTNESS.includes(lighting.brightness)) {
|
|
232
|
+
throw new Error(`Redragon ${model} brightness ${lighting.brightness}% is not one of ${BRIGHTNESS.join(", ")}.`);
|
|
233
|
+
}
|
|
234
|
+
const rgb = lighting.color == null ? null : parseColor(lighting.color, model);
|
|
235
|
+
if (this.model.lighting === "profile") {
|
|
236
|
+
const info = REDRAGON_M724_EFFECTS.find((candidate) => candidate.name === lighting.mode);
|
|
237
|
+
if (!info)
|
|
238
|
+
throw new Error(`The Redragon ${model} has no "${lighting.mode}" lighting effect.`);
|
|
239
|
+
await this.run(async () => {
|
|
240
|
+
await this.open();
|
|
241
|
+
const address = redragonM724LightingAddress(await this.readActiveProfile());
|
|
242
|
+
const block = [...await this.readBytes(address, REDRAGON_M724_LIGHTING_BLOCK_LENGTH)];
|
|
243
|
+
block[4] = info.mode;
|
|
244
|
+
block[6] = info.kind;
|
|
245
|
+
if (info.color && rgb)
|
|
246
|
+
block.splice(1, 3, ...rgb);
|
|
247
|
+
if (info.speed && lighting.speed != null)
|
|
248
|
+
block[5] = SPEEDS.length + 1 - lighting.speed;
|
|
249
|
+
if (lighting.brightness != null)
|
|
250
|
+
block[7] = BRIGHTNESS.indexOf(lighting.brightness) + 1;
|
|
251
|
+
await this.writeAndConfirm(address, block);
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
356
255
|
const effect = M612_MODES.find(([, mode]) => mode === lighting.mode)?.[0];
|
|
357
256
|
if (!effect)
|
|
358
|
-
throw new Error(`The Redragon
|
|
257
|
+
throw new Error(`The Redragon ${model} has no "${lighting.mode}" lighting effect.`);
|
|
359
258
|
const info = REDRAGON_M612_EFFECTS.find((candidate) => candidate.effect === effect);
|
|
360
|
-
if (lighting.speed != null && !M612_SPEEDS.includes(lighting.speed)) {
|
|
361
|
-
throw new Error(`Redragon M612 lighting speed ${lighting.speed} is outside 1-${REDRAGON_M612_LIGHTING_SPEEDS}.`);
|
|
362
|
-
}
|
|
363
|
-
if (lighting.brightness != null && !M612_BRIGHTNESS.includes(lighting.brightness)) {
|
|
364
|
-
throw new Error(`Redragon M612 brightness ${lighting.brightness}% is not one of ${M612_BRIGHTNESS.join(", ")}.`);
|
|
365
|
-
}
|
|
366
|
-
const rgb = lighting.color == null ? null : parseColor(lighting.color);
|
|
367
259
|
await this.run(async () => {
|
|
368
260
|
await this.open();
|
|
369
|
-
const shown = await this.
|
|
261
|
+
const shown = await this.readEffectLighting();
|
|
370
262
|
const selector = await this.readBytes(REDRAGON_M612_LIGHTING_EFFECT_ADDRESS, 2);
|
|
371
263
|
const writes = [];
|
|
372
264
|
if (info.block !== null) {
|
|
@@ -374,10 +266,10 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
374
266
|
if (info.color && rgb && lighting.color !== shown.color)
|
|
375
267
|
block.splice(1, 3, ...rgb);
|
|
376
268
|
if (info.speed && lighting.speed != null && lighting.speed !== shown.speed) {
|
|
377
|
-
block[5] =
|
|
269
|
+
block[5] = SPEEDS.length + 1 - lighting.speed;
|
|
378
270
|
}
|
|
379
271
|
if (lighting.brightness != null && lighting.brightness !== shown.brightness) {
|
|
380
|
-
block[7] =
|
|
272
|
+
block[7] = BRIGHTNESS.indexOf(lighting.brightness) + 1;
|
|
381
273
|
}
|
|
382
274
|
writes.push([info.block, block]);
|
|
383
275
|
}
|
|
@@ -392,70 +284,94 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
392
284
|
await this.confirm(address, data);
|
|
393
285
|
});
|
|
394
286
|
}
|
|
287
|
+
/** Names every button of `profile` with its decoded action, from one ranged read. */
|
|
395
288
|
async readButtonMappings(profile) {
|
|
396
|
-
const
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
return Object.fromEntries(M612_BUTTON_NAMES.map((name, slot) => {
|
|
400
|
-
const offset = REDRAGON_M612_BUTTON_OFFSETS[slot];
|
|
401
|
-
return [name, redragonM612DecodeButtonAction(bytes.subarray(offset, offset + REDRAGON_M612_BUTTON_LENGTH))];
|
|
402
|
-
}));
|
|
289
|
+
const { names, offsets, decode } = this.model.buttons;
|
|
290
|
+
const bytes = await this.readRange(REDRAGON_BUTTON_BASES[profile], offsets.at(-1) + REDRAGON_BUTTON_LENGTH);
|
|
291
|
+
return Object.fromEntries(names.map((name, slot) => [name, decode(bytes.subarray(offsets[slot], offsets[slot] + REDRAGON_BUTTON_LENGTH))]));
|
|
403
292
|
}
|
|
404
|
-
|
|
293
|
+
/** M724: the profile's block; brightness is hidden when the effect is Off. */
|
|
294
|
+
async readProfileLighting(profile) {
|
|
295
|
+
const block = await this.readBytes(redragonM724LightingAddress(profile), REDRAGON_M724_LIGHTING_BLOCK_LENGTH);
|
|
296
|
+
const info = redragonM724EffectForBlock(block);
|
|
297
|
+
const lit = info !== undefined && info.name !== "Off";
|
|
298
|
+
return {
|
|
299
|
+
zone: "Mouse",
|
|
300
|
+
modes: REDRAGON_M724_EFFECTS.map((effect) => effect.name),
|
|
301
|
+
mode: info?.name ?? null,
|
|
302
|
+
color: `#${hex(block.subarray(1, 4)).replaceAll(" ", "")}`,
|
|
303
|
+
color2: null,
|
|
304
|
+
colorModes: REDRAGON_M724_EFFECTS.filter((effect) => effect.color).map((effect) => effect.name),
|
|
305
|
+
dualColorModes: [],
|
|
306
|
+
reactiveModes: REDRAGON_M724_EFFECTS.filter((effect) => effect.speed).map((effect) => effect.name),
|
|
307
|
+
speeds: SPEEDS,
|
|
308
|
+
speed: info?.speed && block[5] >= 1 && block[5] <= SPEEDS.length ? SPEEDS.length + 1 - block[5] : null,
|
|
309
|
+
brightness: lit ? (BRIGHTNESS[block[7] - 1] ?? null) : null,
|
|
310
|
+
brightnessLevels: lit ? [...BRIGHTNESS] : undefined,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/** M612: the global effect bit and that effect's parameter block (none for Off). */
|
|
314
|
+
async readEffectLighting() {
|
|
405
315
|
const [bit] = await this.readBytes(REDRAGON_M612_LIGHTING_EFFECT_ADDRESS, 1);
|
|
406
316
|
const info = redragonM612EffectForBit(bit ?? -1);
|
|
407
317
|
const block = info?.block != null ? await this.readBytes(info.block, REDRAGON_M612_LIGHTING_BLOCK_LENGTH) : null;
|
|
408
318
|
const mode = M612_MODES.find(([effect]) => effect === info?.effect)?.[1] ?? null;
|
|
409
|
-
const
|
|
410
|
-
const speedModes = M612_MODES.filter(([effect]) => REDRAGON_M612_EFFECTS.find((e) => e.effect === effect).speed).map(([, m]) => m);
|
|
411
|
-
const lit = block !== null;
|
|
319
|
+
const modesWhere = (key) => M612_MODES.filter(([effect]) => REDRAGON_M612_EFFECTS.find((e) => e.effect === effect)[key]).map(([, m]) => m);
|
|
412
320
|
return {
|
|
413
321
|
zone: "Mouse",
|
|
414
322
|
modes: M612_MODES.map(([, m]) => m),
|
|
415
323
|
mode,
|
|
416
|
-
color: block ? `#${
|
|
324
|
+
color: block ? `#${hex(block.subarray(1, 4)).replaceAll(" ", "")}` : null,
|
|
417
325
|
color2: null,
|
|
418
|
-
colorModes,
|
|
326
|
+
colorModes: modesWhere("color"),
|
|
419
327
|
dualColorModes: [],
|
|
420
|
-
reactiveModes:
|
|
421
|
-
speeds:
|
|
422
|
-
speed: block && info?.speed && block[5] >= 1 && block[5] <=
|
|
423
|
-
|
|
424
|
-
brightness: block ? (M612_BRIGHTNESS[block[7] - 1] ?? null) : null,
|
|
328
|
+
reactiveModes: modesWhere("speed"),
|
|
329
|
+
speeds: SPEEDS,
|
|
330
|
+
speed: block && info?.speed && block[5] >= 1 && block[5] <= SPEEDS.length ? SPEEDS.length + 1 - block[5] : null,
|
|
331
|
+
brightness: block ? (BRIGHTNESS[block[7] - 1] ?? null) : null,
|
|
425
332
|
// Off has no parameter block, so there is no brightness to set.
|
|
426
|
-
brightnessLevels:
|
|
333
|
+
brightnessLevels: block !== null ? [...BRIGHTNESS] : undefined,
|
|
427
334
|
};
|
|
428
335
|
}
|
|
336
|
+
/** Null on models without lift-off, or for a level byte outside 0-2. */
|
|
337
|
+
async readLiftOff() {
|
|
338
|
+
if (this.model.liftOffAddress === undefined)
|
|
339
|
+
return null;
|
|
340
|
+
const [level] = await this.readBytes(this.model.liftOffAddress, 1);
|
|
341
|
+
return LIFT_OFF_LEVELS[level] ?? null;
|
|
342
|
+
}
|
|
343
|
+
/** Reads any length in transfers of at most 8 bytes. */
|
|
429
344
|
async readRange(address, length) {
|
|
430
345
|
const out = new Uint8Array(length);
|
|
431
|
-
for (let offset = 0; offset < length; offset +=
|
|
432
|
-
out.set(await this.readBytes(address + offset, Math.min(
|
|
346
|
+
for (let offset = 0; offset < length; offset += REDRAGON_MAX_TRANSFER) {
|
|
347
|
+
out.set(await this.readBytes(address + offset, Math.min(REDRAGON_MAX_TRANSFER, length - offset)), offset);
|
|
433
348
|
}
|
|
434
349
|
return out;
|
|
435
350
|
}
|
|
351
|
+
/** Active profile, its stage table and active stage, and its polling rate; rejects values the firmware never holds. */
|
|
436
352
|
async readSettings() {
|
|
437
353
|
const profile = await this.readActiveProfile();
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
throw new Error(`The Redragon M612 reported DPI stage ${activeStage}; expected 0-4.`);
|
|
354
|
+
const [activeStage] = await this.readBytes(REDRAGON_PROFILE_BASES[profile], 1);
|
|
355
|
+
if (activeStage === undefined || activeStage >= REDRAGON_STAGE_COUNT) {
|
|
356
|
+
throw new Error(`The Redragon ${this.model.model} reported DPI stage ${activeStage}; expected 0-4.`);
|
|
442
357
|
}
|
|
443
358
|
const stages = [];
|
|
444
|
-
for (let stage = 0; stage <
|
|
445
|
-
const slot = await this.readBytes(
|
|
446
|
-
stages.push(
|
|
359
|
+
for (let stage = 0; stage < REDRAGON_STAGE_COUNT; stage++) {
|
|
360
|
+
const slot = await this.readBytes(redragonSlotAddress(profile, stage), REDRAGON_SLOT_LENGTH);
|
|
361
|
+
stages.push(this.model.dpi.decode(slot[1], slot[2]));
|
|
447
362
|
}
|
|
448
|
-
const [pollCode] = await this.readBytes(
|
|
363
|
+
const [pollCode] = await this.readBytes(redragonPollAddress(profile), 1);
|
|
449
364
|
const pollingHz = REDRAGON_POLLING_RATES.find((hz) => REDRAGON_POLLING_CODES[hz] === pollCode);
|
|
450
365
|
if (pollingHz === undefined) {
|
|
451
|
-
throw new Error(`The Redragon
|
|
366
|
+
throw new Error(`The Redragon ${this.model.model} reported polling code ${pollCode}; expected 1, 2, 4, or 8.`);
|
|
452
367
|
}
|
|
453
368
|
return { profile, activeStage, stages, pollingHz };
|
|
454
369
|
}
|
|
370
|
+
/** The active profile index 0-4, rejecting anything else. */
|
|
455
371
|
async readActiveProfile() {
|
|
456
|
-
const [profile] = await this.readBytes(
|
|
457
|
-
if (profile === undefined || profile >=
|
|
458
|
-
throw new Error(`The Redragon
|
|
372
|
+
const [profile] = await this.readBytes(REDRAGON_ACTIVE_PROFILE_ADDRESS, 1);
|
|
373
|
+
if (profile === undefined || profile >= REDRAGON_PROFILE_COUNT) {
|
|
374
|
+
throw new Error(`The Redragon ${this.model.model} reported profile ${profile}; expected 0-4.`);
|
|
459
375
|
}
|
|
460
376
|
return profile;
|
|
461
377
|
}
|
|
@@ -469,9 +385,8 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
469
385
|
async writeAndConfirm(address, data) {
|
|
470
386
|
await this.writeSession(async () => {
|
|
471
387
|
await this.sendFrame(redragonEncodeWrite(address, data));
|
|
472
|
-
for (const code of REDRAGON_COMMIT_CODES)
|
|
388
|
+
for (const code of REDRAGON_COMMIT_CODES)
|
|
473
389
|
await this.sendFrame(redragonEncodeCommit(code));
|
|
474
|
-
}
|
|
475
390
|
});
|
|
476
391
|
await this.confirm(address, data);
|
|
477
392
|
}
|
|
@@ -479,15 +394,37 @@ export class RedragonM612HidClient extends RedragonHidClient {
|
|
|
479
394
|
async confirm(address, data) {
|
|
480
395
|
const confirmed = await this.readBytes(address, data.length);
|
|
481
396
|
if (confirmed.some((byte, index) => byte !== data[index])) {
|
|
482
|
-
|
|
483
|
-
throw new Error(`The Redragon M612 kept ${hex(confirmed)} at 0x${address.toString(16)} instead of ${hex(data)}.`);
|
|
397
|
+
throw new Error(`The Redragon ${this.model.model} kept ${hex(confirmed)} at 0x${address.toString(16)} instead of ${hex(data)}.`);
|
|
484
398
|
}
|
|
485
399
|
}
|
|
400
|
+
async sendFrame(frame) {
|
|
401
|
+
await this.device.sendFeatureReport(REDRAGON_REPORT_ID, frame.slice(1).buffer);
|
|
402
|
+
await new Promise((resolve) => setTimeout(resolve, WRITE_DELAY_MS));
|
|
403
|
+
}
|
|
404
|
+
/** The bracket is always closed: a session left open hangs the interface. */
|
|
405
|
+
async writeSession(operation) {
|
|
406
|
+
await this.sendFrame(redragonSession(true));
|
|
407
|
+
try {
|
|
408
|
+
await operation();
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
await this.sendFrame(redragonSession(false));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async run(operation) {
|
|
415
|
+
const result = this.queue.then(operation, operation);
|
|
416
|
+
this.queue = result.then(() => undefined, () => undefined);
|
|
417
|
+
return await result;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** @deprecated `RedragonHidClient` serves the M612 too; the model follows the PID. */
|
|
421
|
+
export class RedragonM612HidClient extends RedragonHidClient {
|
|
486
422
|
}
|
|
487
|
-
|
|
423
|
+
/** `#rrggbb` to RGB bytes; anything else throws. */
|
|
424
|
+
function parseColor(color, model) {
|
|
488
425
|
const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
|
|
489
426
|
if (!match)
|
|
490
|
-
throw new Error(`Redragon
|
|
427
|
+
throw new Error(`Redragon ${model} colour "${color}" is not #rrggbb.`);
|
|
491
428
|
return [parseInt(match[1], 16), parseInt(match[2], 16), parseInt(match[3], 16)];
|
|
492
429
|
}
|
|
493
430
|
//# sourceMappingURL=hid.js.map
|