@@ -48,6 +48,7 @@ export const FLASH_FIRMWARE_DIALOG_CLEAR = `${FLASH_FIRMWARE_DIALOG_ACTIONS}/Cle
48
48
export const FLASH_FIRMWARE_DIALOG_UPDATE_KEYBOARD_NAME = `${ FLASH_FIRMWARE_DIALOG_ACTIONS } /UpdateKeyboardName` ;
49
49
export const FLASH_FIRMWARE_DIALOG_UPDATE_FLASH_MODE = `${ FLASH_FIRMWARE_DIALOG_ACTIONS } /UpdateFlashMode` ;
50
50
export const FLASH_FIRMWARE_DIALOG_UPDATE_BUILDING_FIRMWARE_TASK = `${ FLASH_FIRMWARE_DIALOG_ACTIONS } /UpdateBuildingFirmwareTask` ;
51
+ export const FLASH_FIRMWARE_DIALOG_UPDATE_FIRMWARE_BLOB = `${ FLASH_FIRMWARE_DIALOG_ACTIONS } /UpdateFirmwareBlob` ;
51
52
export const FlashFirmwareDialogActions = {
52
53
updateFirmware : ( firmware : IFirmware | null ) => {
53
54
return {
@@ -117,6 +118,12 @@ export const FlashFirmwareDialogActions = {
117
118
value : task ,
118
119
} ;
119
120
} ,
121
+ updateFirmwareBlob : ( blob : Buffer | undefined ) => {
122
+ return {
123
+ type : FLASH_FIRMWARE_DIALOG_UPDATE_FIRMWARE_BLOB ,
124
+ value : blob ,
125
+ } ;
126
+ } ,
120
127
} ;
121
128
122
129
type ActionTypes = ReturnType <
@@ -171,9 +178,9 @@ export const firmwareActionsThunk = {
171
178
created_at : new Date ( ) ,
172
179
} )
173
180
) ;
181
+ await dispatch ( firmwareActionsThunk . loadFirmwareBlob ( ) ) ;
174
182
} ,
175
- // eslint-disable-next-line no-undef
176
- flashFirmware :
183
+ loadFirmwareBlob :
177
184
( ) : ThunkPromiseAction < void > =>
178
185
async (
179
186
dispatch : ThunkDispatch < RootState , undefined , ActionTypes > ,
@@ -182,21 +189,17 @@ export const firmwareActionsThunk = {
182
189
const handleError = ( error : string , cause ?: any ) => {
183
190
console . error ( error ) ;
184
191
dispatch ( NotificationActions . addError ( error , cause ) ) ;
185
- dispatch ( FlashFirmwareDialogActions . appendLog ( `Error: ${ error } ` ) ) ;
186
- dispatch ( FlashFirmwareDialogActions . updateFlashing ( false ) ) ;
192
+ dispatch ( FlashFirmwareDialogActions . clear ( ) ) ;
187
193
} ;
188
194
189
- dispatch ( FlashFirmwareDialogActions . updateLogs ( [ ] ) ) ;
190
- dispatch ( FlashFirmwareDialogActions . updateProgressRate ( 0 ) ) ;
191
- dispatch ( FlashFirmwareDialogActions . updateMode ( 'flashing' ) ) ;
192
- dispatch ( FlashFirmwareDialogActions . updateFlashing ( true ) ) ;
193
- const { entities, storage, serial, common } = getState ( ) ;
194
- const firmwareWriter = serial . writer ;
195
+ dispatch ( FlashFirmwareDialogActions . updateMode ( 'loading' ) ) ;
196
+ dispatch ( FlashFirmwareDialogActions . updateFlashing ( false ) ) ;
197
+
198
+ const { common, entities, storage } = getState ( ) ;
195
199
const firmware = common . firmware . flashFirmwareDialog . firmware ! ;
196
200
const bootloaderType =
197
201
common . firmware . flashFirmwareDialog . bootloaderType ! ;
198
202
const flashMode = common . firmware . flashFirmwareDialog . flashMode ;
199
-
200
203
let flashBytes : Buffer | undefined ;
201
204
if ( flashMode === 'fetch_and_flash' ) {
202
205
const definitionDocument = entities . keyboardDefinitionDocument ! ;
@@ -268,11 +271,48 @@ export const firmwareActionsThunk = {
268
271
return ;
269
272
}
270
273
}
274
+ dispatch ( FlashFirmwareDialogActions . updateFirmwareBlob ( flashBytes ) ) ;
275
+ dispatch ( FlashFirmwareDialogActions . updateMode ( 'instruction' ) ) ;
276
+ } ,
277
+ // eslint-disable-next-line no-undef
278
+ flashFirmware :
279
+ ( ) : ThunkPromiseAction < void > =>
280
+ async (
281
+ dispatch : ThunkDispatch < RootState , undefined , ActionTypes > ,
282
+ getState : ( ) => RootState
283
+ ) => {
284
+ const handleError = ( error : string , cause ?: any ) => {
285
+ console . error ( error ) ;
286
+ dispatch ( NotificationActions . addError ( error , cause ) ) ;
287
+ dispatch ( FlashFirmwareDialogActions . appendLog ( `Error: ${ error } ` ) ) ;
288
+ dispatch ( FlashFirmwareDialogActions . updateFlashing ( false ) ) ;
289
+ } ;
290
+
291
+ dispatch ( FlashFirmwareDialogActions . updateLogs ( [ ] ) ) ;
292
+ dispatch ( FlashFirmwareDialogActions . updateProgressRate ( 0 ) ) ;
293
+ dispatch ( FlashFirmwareDialogActions . updateMode ( 'flashing' ) ) ;
294
+ dispatch ( FlashFirmwareDialogActions . updateFlashing ( true ) ) ;
295
+ const { serial, common } = getState ( ) ;
296
+ const firmwareWriter = serial . writer ;
297
+ const bootloaderType =
298
+ common . firmware . flashFirmwareDialog . bootloaderType ! ;
299
+
300
+ let flashBytes : Buffer | undefined =
301
+ common . firmware . flashFirmwareDialog . firmwareBlob ;
302
+ if ( flashBytes === undefined ) {
303
+ dispatch (
304
+ NotificationActions . addError ( 'Firmware binary is not loaded.' )
305
+ ) ;
306
+ dispatch ( FlashFirmwareDialogActions . clear ( ) ) ;
307
+ return ;
308
+ }
309
+
271
310
dispatch (
272
311
FlashFirmwareDialogActions . appendLog (
273
- 'Reading the firmware binary done .'
312
+ 'Firmware binary has already been loaded. Start writing the firmware .'
274
313
)
275
314
) ;
315
+
276
316
dispatch ( FlashFirmwareDialogActions . updateProgressRate ( 15 ) ) ;
277
317
278
318
const writeResult = await firmwareWriter . write (
@@ -341,15 +381,14 @@ const createFlashBytes = (
341
381
return buffer ;
342
382
}
343
383
} catch ( error ) {
344
- console . error ( error ) ;
384
+ console . error ( 'Creating a flashed bytes failed.' , error ) ;
345
385
dispatch (
346
386
NotificationActions . addError (
347
387
'Creating the firmware binary failed.' ,
348
388
error
349
389
)
350
390
) ;
351
- dispatch ( FlashFirmwareDialogActions . appendLog ( `Error: ${ error } ` ) ) ;
352
- dispatch ( FlashFirmwareDialogActions . updateFlashing ( false ) ) ;
391
+ dispatch ( FlashFirmwareDialogActions . clear ( ) ) ;
353
392
return undefined ;
354
393
}
355
394
} ;
0 commit comments