@@ -12,9 +12,8 @@ import type { ButtonsLcdDisplayService } from '../services/buttonsLcdDisplay/int
12
12
import type { StreamDeckButtonControlDefinition , StreamDeckControlDefinition } from '../controlDefinition.js'
13
13
import type { LcdStripDisplayService } from '../services/lcdStripDisplay/interface.js'
14
14
import type { PropertiesService } from '../services/properties/interface.js'
15
- import type { EncoderInputService } from '../services/encoderInput.js'
16
- import type { LcdStripInputService } from '../services/lcdStripInput.js'
17
15
import type { CallbackHook } from '../services/callback-hook.js'
16
+ import type { StreamDeckInputService } from '../services/input/interface.js'
18
17
19
18
export type EncodeJPEGHelper = ( buffer : Uint8Array , width : number , height : number ) => Promise < Uint8Array >
20
19
@@ -46,12 +45,11 @@ export type StreamDeckProperties = Readonly<{
46
45
47
46
export interface StreamDeckServicesDefinition {
48
47
deviceProperties : StreamDeckProperties
49
- events : CallbackHook < StreamDeckEvents > | null
48
+ events : CallbackHook < StreamDeckEvents >
50
49
properties : PropertiesService
51
50
buttonsLcd : ButtonsLcdDisplayService
51
+ inputService : StreamDeckInputService
52
52
lcdStripDisplay : LcdStripDisplayService | null
53
- lcdStripInput : LcdStripInputService | null
54
- encoderInput : EncoderInputService | null
55
53
}
56
54
57
55
export class StreamDeckBase extends EventEmitter < StreamDeckEvents > implements StreamDeck {
@@ -88,10 +86,8 @@ export class StreamDeckBase extends EventEmitter<StreamDeckEvents> implements St
88
86
readonly #propertiesService: PropertiesService
89
87
readonly #buttonsLcdService: ButtonsLcdDisplayService
90
88
readonly #lcdStripDisplayService: LcdStripDisplayService | null
91
- readonly #lcdStripInputService: LcdStripInputService | null
92
- readonly #encoderInputService: EncoderInputService | null
89
+ readonly #inputService: StreamDeckInputService
93
90
// private readonly options: Readonly<OpenStreamDeckOptions>
94
- readonly #keyState: boolean [ ]
95
91
96
92
constructor ( device : HIDDevice , _options : OpenStreamDeckOptions , services : StreamDeckServicesDefinition ) {
97
93
super ( )
@@ -101,58 +97,18 @@ export class StreamDeckBase extends EventEmitter<StreamDeckEvents> implements St
101
97
this . #propertiesService = services . properties
102
98
this . #buttonsLcdService = services . buttonsLcd
103
99
this . #lcdStripDisplayService = services . lcdStripDisplay
104
- this . #lcdStripInputService = services . lcdStripInput
105
- this . #encoderInputService = services . encoderInput
100
+ this . #inputService = services . inputService
106
101
107
102
// propogate events
108
103
services . events ?. listen ( ( key , ...args ) => this . emit ( key , ...args ) )
109
104
110
- const maxButtonIndex = this . deviceProperties . CONTROLS . filter (
111
- ( control ) : control is StreamDeckButtonControlDefinition => control . type === 'button' ,
112
- ) . map ( ( control ) => control . index )
113
- this . #keyState = new Array < boolean > ( Math . max ( - 1 , ...maxButtonIndex ) + 1 ) . fill ( false )
114
-
115
- this . device . on ( 'input' , ( data : Uint8Array ) => this . #handleInputBuffer( data ) )
105
+ this . device . on ( 'input' , ( data : Uint8Array ) => this . #inputService. handleInput ( data ) )
116
106
117
107
this . device . on ( 'error' , ( err ) => {
118
108
this . emit ( 'error' , err )
119
109
} )
120
110
}
121
111
122
- #handleInputBuffer( data : Uint8Array ) : void {
123
- const inputType = data [ 0 ]
124
- switch ( inputType ) {
125
- case 0x00 : // Button
126
- this . #handleButtonInputBuffer( data )
127
- break
128
- case 0x02 : // LCD
129
- this . #lcdStripInputService?. handleInput ( data )
130
- break
131
- case 0x03 : // Encoder
132
- this . #encoderInputService?. handleInput ( data )
133
- break
134
- }
135
- }
136
-
137
- #handleButtonInputBuffer( data : Uint8Array ) : void {
138
- const dataOffset = this . deviceProperties . KEY_DATA_OFFSET || 0
139
-
140
- for ( const control of this . deviceProperties . CONTROLS ) {
141
- if ( control . type !== 'button' ) continue
142
-
143
- const keyPressed = Boolean ( data [ dataOffset + control . hidIndex ] )
144
- const stateChanged = keyPressed !== this . #keyState[ control . index ]
145
- if ( stateChanged ) {
146
- this . #keyState[ control . index ] = keyPressed
147
- if ( keyPressed ) {
148
- this . emit ( 'down' , control )
149
- } else {
150
- this . emit ( 'up' , control )
151
- }
152
- }
153
- }
154
- }
155
-
156
112
protected checkValidKeyIndex (
157
113
keyIndex : KeyIndex ,
158
114
feedbackType : StreamDeckButtonControlDefinition [ 'feedbackType' ] | null ,
0 commit comments