@@ -1158,62 +1158,58 @@ function* handleFlashEV3(action: ReturnType<typeof firmwareFlashEV3>): Generator
11581158 }
11591159 } ) ;
11601160
1161- try {
1162- // Send the command
1163- const dataBuffer = new Uint8Array ( ( payload ?. byteLength ?? 0 ) + 6 ) ;
1164- const data = new DataView ( dataBuffer . buffer ) ;
1165-
1166- data . setInt16 ( 0 , ( payload ?. byteLength ?? 0 ) + 4 , true ) ;
1167- data . setInt16 ( 2 , 0 , true ) ; // TODO: reply number
1168- data . setUint8 ( 4 , 0x01 ) ; // system command w/ reply
1169- data . setUint8 ( 5 , command ) ;
1170- if ( payload ) {
1171- dataBuffer . set ( payload , 6 ) ;
1172- }
1173-
1174- const [ , sendError ] = yield * call ( ( ) =>
1175- maybe ( hidDevice . sendReport ( 0 , data ) ) ,
1176- ) ;
1161+ // Send the command
1162+ const dataBuffer = new Uint8Array ( ( payload ?. byteLength ?? 0 ) + 6 ) ;
1163+ const data = new DataView ( dataBuffer . buffer ) ;
1164+
1165+ data . setInt16 ( 0 , ( payload ?. byteLength ?? 0 ) + 4 , true ) ;
1166+ data . setInt16 ( 2 , 0 , true ) ; // TODO: reply number
1167+ data . setUint8 ( 4 , 0x01 ) ; // system command w/ reply
1168+ data . setUint8 ( 5 , command ) ;
1169+ if ( payload ) {
1170+ dataBuffer . set ( payload , 6 ) ;
1171+ }
11771172
1178- if ( sendError ) {
1179- return [ undefined , sendError ] ;
1180- }
1173+ const [ , sendError ] = yield * call ( ( ) => maybe ( hidDevice . sendReport ( 0 , data ) ) ) ;
11811174
1182- const { reply, timeout } = yield * race ( {
1183- reply : take ( replyChannel ) ,
1184- timeout : delay ( 5000 ) ,
1185- } ) ;
1175+ if ( sendError ) {
1176+ return [ undefined , sendError ] ;
1177+ }
11861178
1187- if ( timeout ) {
1188- return [ undefined , new Error ( 'Timeout waiting for EV3 reply' ) ] ;
1189- }
1179+ const { reply, timeout } = yield * race ( {
1180+ reply : take ( replyChannel ) ,
1181+ timeout : delay ( 5000 ) ,
1182+ } ) ;
11901183
1191- defined ( reply ) ;
1184+ if ( timeout ) {
1185+ return [ undefined , new Error ( 'Timeout waiting for EV3 reply' ) ] ;
1186+ }
11921187
1193- if ( reply . replyCommand !== command ) {
1194- return [
1195- undefined ,
1196- new Error (
1197- `EV3 reply command mismatch: expected ${ command } , got ${ reply . replyCommand } ` ,
1198- ) ,
1199- ] ;
1200- }
1188+ defined ( reply ) ;
12011189
1202- if ( reply . status !== 0 ) {
1203- return [
1204- undefined ,
1205- new Error (
1206- `EV3 reply status error: ${ reply . status } for command ${ command } ` ,
1207- ) ,
1208- ] ;
1209- }
1190+ if ( reply . replyCommand !== command ) {
1191+ return [
1192+ undefined ,
1193+ new Error (
1194+ `EV3 reply command mismatch: expected ${ command } , got ${ reply . replyCommand } ` ,
1195+ ) ,
1196+ ] ;
1197+ }
12101198
1211- return [ new DataView ( reply . payload ) , undefined ] ;
1212- } finally {
1213- // Always clean up
1214- yield * cancel ( forwardTask ) ;
1215- yield * call ( ( ) => replyChannel . close ( ) ) ;
1199+ if ( reply . status !== 0 ) {
1200+ return [
1201+ undefined ,
1202+ new Error (
1203+ `EV3 reply status error: ${ reply . status } for command ${ command } ` ,
1204+ ) ,
1205+ ] ;
12161206 }
1207+
1208+ // Clean up
1209+ yield * cancel ( forwardTask ) ;
1210+ yield * call ( ( ) => replyChannel . close ( ) ) ;
1211+
1212+ return [ new DataView ( reply . payload ) , undefined ] ;
12171213 }
12181214
12191215 const [ version , versionError ] = yield * sendCommand ( 0xf6 ) ; // get version
0 commit comments