@@ -30,13 +30,17 @@ const Comms = {
3030 /** Write the given data, returns a promise containing the data received immediately after sending the command
3131 options = {
3232 waitNewLine : bool // wait for a newline (rather than just 300ms of inactivity)
33+ noWait : bool // don't wait for a response, complete as soon as it's seny
3334 }
3435 */
3536 write : ( data , options ) => {
3637 if ( data === undefined ) throw new Error ( "Comms.write(undefined) called!" )
3738 options = options || { } ;
3839 if ( typeof UART !== "undefined" ) { // New method
39- return UART . write ( data , undefined , ! ! options . waitNewLine ) ;
40+ let o = {
41+ waitNewline : ! ! options . waitNewLine ,
42+ noWait : ! ! options . noWait } ;
43+ return UART . write ( data , undefined , o ) ;
4044 } else { // Old method
4145 return new Promise ( ( resolve , reject ) =>
4246 Puck . write ( data , result => {
@@ -120,7 +124,7 @@ const Comms = {
120124 showMessage : ( txt ) => {
121125 console . log ( `<COMMS> showMessage ${ JSON . stringify ( txt ) } ` ) ;
122126 if ( ! Const . HAS_E_SHOWMESSAGE ) return Promise . resolve ( ) ;
123- return Comms . write ( `\x10E.showMessage(${ JSON . stringify ( txt ) } )\n` ) ;
127+ return Comms . write ( `\x10E.showMessage(${ JSON . stringify ( txt ) } )\n` , { noWait : true } ) ;
124128 } ,
125129 // When upload is finished, show a message (or reload)
126130 showUploadFinished : ( ) => {
@@ -283,16 +287,17 @@ const Comms = {
283287 function startUpload ( ) {
284288 console . log ( `<COMMS> Upload ${ f . name } => ${ JSON . stringify ( f . content . length > 50 ? f . content . substr ( 0 , 50 ) + "..." : f . content ) } (${ f . content . length } b${ uploadPacket ?", binary" :"" } )` ) ;
285289 if ( uploadPacket ) {
286- Progress . show ( { // Ensure that the correct progress is being shown in app loader
287- percent : 0 ,
288- min :currentBytes / maxBytes ,
289- max : ( currentBytes + f . content . length ) / maxBytes } ) ;
290- return Comms . write ( `\x10 ${ Comms . getProgressCmd ( currentBytes / maxBytes ) } \n` ) . then ( ( ) => // update percent bar on Bangle.js screen
291- Comms . getConnection ( ) . espruinoSendFile ( f . name , f . content , { // send the file
290+ let progressMin = 0.1 + ( 0.9 * currentBytes / maxBytes ) ;
291+ let progressMax = 0.1 + ( 0.9 * ( currentBytes + f . content . length ) / maxBytes ) ;
292+ Progress . show ( { percent : 0 , min : progressMin , max : progressMin } ) ; // Don't show progress for sending the status update
293+ return Comms . write ( `\x10 ${ Comms . getProgressCmd ( currentBytes / maxBytes ) } \n` , { noWait : true } ) . then ( ( ) => { // update percent bar on Bangle.js screen
294+ Progress . show ( { percent : 0 , min : progressMin , max : progressMax } ) ; // Show progress for the actual packet upload
295+ return Comms . getConnection ( ) . espruinoSendFile ( f . name , f . content , { // send the file
292296 fs : Const . FILES_IN_FS ,
293297 chunkSize : Const . PACKET_UPLOAD_CHUNKSIZE ,
294298 noACK : Const . PACKET_UPLOAD_NOACK
295- } ) ) ;
299+ } ) ;
300+ } ) ;
296301 } else {
297302 return Comms . uploadCommandList ( f . cmd , currentBytes , maxBytes ) ;
298303 }
@@ -317,8 +322,9 @@ const Comms = {
317322
318323 // Start the upload
319324 function doUpload ( ) {
325+ Progress . show ( { min :0.05 , max :0.10 } ) ; // 5-10% for progress writing
320326 Comms . showMessage ( `Installing\n${ app . id } ...` ) .
321- then ( ( ) => Comms . write ( "\x10" + Comms . getProgressCmd ( ) + "\n" ) ) .
327+ then ( ( ) => Comms . write ( "\x10" + Comms . getProgressCmd ( ) + "\n" , { noWait : true } ) ) .
322328 then ( ( ) => {
323329 doUploadFiles ( ) ;
324330 } ) . catch ( ( err ) => {
@@ -329,7 +335,8 @@ const Comms = {
329335 if ( options . noReset ) {
330336 doUpload ( ) ;
331337 } else {
332- // reset to ensure we have enough memory to upload what we need to
338+ // reset to ensure we have enough memory to upload what we need to
339+ Progress . show ( { min :0 , max :0.05 } ) ; // 0-5% for reset
333340 Comms . reset ( ) . then ( doUpload , reject )
334341 }
335342 } ) ;
0 commit comments