Skip to content

Commit b305da3

Browse files
committed
Fixup a few random bugs
1 parent b5255bb commit b305da3

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

POC/ts/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Keyboard } from "../../src";
22
import {
3-
allColor,
43
applyHardwareProfile,
5-
galaxy,
6-
sparkle,
7-
sparkleBatch,
8-
testKey
94
} from "./examples";
105

116
// Ok. Let's create a keyboard
@@ -42,7 +37,7 @@ keyboard.initialize();
4237

4338
// cosmos themed profile
4439
// galaxy(keyboard, 'uk');
45-
//galaxy(keyboard, "us");
40+
// galaxy(keyboard, "us");
4641
applyHardwareProfile(keyboard, "en-US");
4742

4843
/*

src/channel-state.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ export class ChannelState {
128128
return this;
129129
}
130130

131+
public setToHardwareProfile() {
132+
this.effectId = 0;
133+
return this;
134+
}
135+
131136
public build(): number[][] {
132137

133138
const packetsToSend = [];
@@ -160,7 +165,8 @@ export class ChannelState {
160165
this.downDecrement,
161166
this.upIncrementDelay,
162167
this.downDecrementDelay,
163-
this.startDelay
168+
this.startDelay,
169+
this.effectId,
164170
).buildPacketBytes());
165171
}
166172

src/key-info.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { KeyInfo } from "./key-info";
2-
import { KeyModel } from 'internal/models';
2+
import { KeyModel } from './internal/models';
33

44
describe("KeyInfo", () => {
55
describe("en-US", () => {
66
it("should have the 'en-US' culture defined.", () => {
77
expect(KeyInfo["en-US"]).not.toBeUndefined();
88
});
99

10-
it("should have 110 positions defined.", () => {
11-
expect(Object.getOwnPropertyNames(KeyInfo["en-US"]).length).toEqual(110);
10+
it("should have 114 positions defined.", () => {
11+
expect(Object.getOwnPropertyNames(KeyInfo["en-US"]).length).toEqual(114);
1212
});
1313
});
1414

src/keyboard.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { ChannelState } from "./channel-state";
12
import { BrightnessPacket } from "./internal/models/packets/brightness-packet";
23
import { FirmwarePacket } from "./internal/models/packets/firmware-packet";
34
import { FreezePacket } from "./internal/models/packets/freeze-packet";
45
import { InitializePacket } from "./internal/models/packets/initialize-packet";
56
import { TriggerPacket } from "./internal/models/packets/trigger-packet";
67
import { KeyState } from "./key-state";
7-
8-
import { ChannelState } from "./channel-state";
98
import { findUsbDevice, Usb } from "./usb";
109

1110
export class Keyboard {

src/usb/hid.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,28 @@ export class UsbHid extends Usb {
3535
if (this.hidDevice === undefined) {
3636
throw new Error("The HID device is undefined.");
3737
}
38-
const res = this.hidDevice.sendFeatureReport(data);
39-
if (res !== data.length) {
40-
throw new Error("Failed to write data");
38+
let res: number = 0;
39+
while (res !== data.length) {
40+
try {
41+
res = this.hidDevice.sendFeatureReport(data);
42+
} catch {
43+
res = 0;
44+
}
4145
}
4246
}
4347

4448
public read(): number[] {
4549
if (this.hidDevice === undefined) {
4650
throw new Error("The HID device is undefined.");
4751
}
48-
const res = this.hidDevice.getFeatureReport(0, 65);
52+
let res: number[] = [];
53+
while (res.length !== 64) {
54+
try {
55+
res = this.hidDevice.getFeatureReport(0, 65);
56+
} catch {
57+
res = [];
58+
}
59+
}
4960
if (process.platform === "darwin") {
5061
res.unshift(0);
5162
}

0 commit comments

Comments
 (0)