Commit b305da3 1 parent b5255bb commit b305da3 Copy full SHA for b305da3
File tree 5 files changed +27
-16
lines changed
5 files changed +27
-16
lines changed Original file line number Diff line number Diff line change 1
1
import { Keyboard } from "../../src" ;
2
2
import {
3
- allColor ,
4
3
applyHardwareProfile ,
5
- galaxy ,
6
- sparkle ,
7
- sparkleBatch ,
8
- testKey
9
4
} from "./examples" ;
10
5
11
6
// Ok. Let's create a keyboard
@@ -42,7 +37,7 @@ keyboard.initialize();
42
37
43
38
// cosmos themed profile
44
39
// galaxy(keyboard, 'uk');
45
- //galaxy(keyboard, "us");
40
+ // galaxy(keyboard, "us");
46
41
applyHardwareProfile ( keyboard , "en-US" ) ;
47
42
48
43
/*
Original file line number Diff line number Diff line change @@ -128,6 +128,11 @@ export class ChannelState {
128
128
return this ;
129
129
}
130
130
131
+ public setToHardwareProfile ( ) {
132
+ this . effectId = 0 ;
133
+ return this ;
134
+ }
135
+
131
136
public build ( ) : number [ ] [ ] {
132
137
133
138
const packetsToSend = [ ] ;
@@ -160,7 +165,8 @@ export class ChannelState {
160
165
this . downDecrement ,
161
166
this . upIncrementDelay ,
162
167
this . downDecrementDelay ,
163
- this . startDelay
168
+ this . startDelay ,
169
+ this . effectId ,
164
170
) . buildPacketBytes ( ) ) ;
165
171
}
166
172
Original file line number Diff line number Diff line change 1
1
import { KeyInfo } from "./key-info" ;
2
- import { KeyModel } from 'internal/models' ;
2
+ import { KeyModel } from './ internal/models' ;
3
3
4
4
describe ( "KeyInfo" , ( ) => {
5
5
describe ( "en-US" , ( ) => {
6
6
it ( "should have the 'en-US' culture defined." , ( ) => {
7
7
expect ( KeyInfo [ "en-US" ] ) . not . toBeUndefined ( ) ;
8
8
} ) ;
9
9
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 ) ;
12
12
} ) ;
13
13
} ) ;
14
14
Original file line number Diff line number Diff line change
1
+ import { ChannelState } from "./channel-state" ;
1
2
import { BrightnessPacket } from "./internal/models/packets/brightness-packet" ;
2
3
import { FirmwarePacket } from "./internal/models/packets/firmware-packet" ;
3
4
import { FreezePacket } from "./internal/models/packets/freeze-packet" ;
4
5
import { InitializePacket } from "./internal/models/packets/initialize-packet" ;
5
6
import { TriggerPacket } from "./internal/models/packets/trigger-packet" ;
6
7
import { KeyState } from "./key-state" ;
7
-
8
- import { ChannelState } from "./channel-state" ;
9
8
import { findUsbDevice , Usb } from "./usb" ;
10
9
11
10
export class Keyboard {
Original file line number Diff line number Diff line change @@ -35,17 +35,28 @@ export class UsbHid extends Usb {
35
35
if ( this . hidDevice === undefined ) {
36
36
throw new Error ( "The HID device is undefined." ) ;
37
37
}
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
+ }
41
45
}
42
46
}
43
47
44
48
public read ( ) : number [ ] {
45
49
if ( this . hidDevice === undefined ) {
46
50
throw new Error ( "The HID device is undefined." ) ;
47
51
}
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
+ }
49
60
if ( process . platform === "darwin" ) {
50
61
res . unshift ( 0 ) ;
51
62
}
You can’t perform that action at this time.
0 commit comments