Skip to content

Commit 08b816c

Browse files
author
Alberto Iannaccone
committed
ease upload
1 parent 224b11a commit 08b816c

File tree

3 files changed

+52
-38
lines changed

3 files changed

+52
-38
lines changed

src/boardConfiguration.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,6 @@ export default class BoardConfiguration {
159159
}
160160
this.serialMonitorContent = '';
161161

162-
const uploadTarget = {
163-
board: board.fqbn,
164-
port: board.port,
165-
network: false
166-
};
167-
168-
const file = {
169-
name: compiledSketch.name + board.upload[0].ext,
170-
data: compiledSketch.hex
171-
};
172-
173-
const uploadData = {
174-
files: [file],
175-
commandline: board.upload[0].commandline,
176-
signature: board.upload[0].options.signature,
177-
extrafiles: [],
178-
options: {
179-
wait_for_upload_port: (board.upload[0].options.wait_for_upload_port === true || board.upload[0].options.wait_for_upload_port === 'true'), // eslint-disable-line camelcase
180-
use_1200bps_touch: (board.upload[0].options.use_1200bps_touch === true || board.upload[0].options.use_1200bps_touch === 'true'), // eslint-disable-line camelcase
181-
params_verbose: '-v' // eslint-disable-line camelcase
182-
}
183-
};
184-
185162
// check the uploading status:
186163
if (this.daemon.uploading.getValue().status === this.daemon.UPLOAD_IN_PROGRESS) {
187164
// if there is an upload in course, notify observers;
@@ -240,6 +217,7 @@ export default class BoardConfiguration {
240217
this.configuring.next({ status: this.CONFIGURE_ERROR, err: `Couldn't configure board at port ${board.port}. Upload failed with error: ${upload.err}` });
241218
});
242219

243-
this.daemon.upload(uploadTarget, uploadData);
220+
this.daemon.initUpload();
221+
this.daemon.uploadSketch(compiledSketch, board);
244222
}
245223
}

src/daemon.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,35 @@ export default class Daemon {
9393
}
9494
throw new Error('Stop Upload not supported on Chrome OS');
9595
}
96+
97+
uploadSketch(compiledSketch, board) {
98+
const uploadTarget = {
99+
board: board.fqbn,
100+
port: board.port,
101+
network: false
102+
};
103+
104+
const file = {
105+
name: compiledSketch.name + board.upload[0].ext,
106+
data: compiledSketch.hex
107+
};
108+
109+
const uploadData = {
110+
files: [file],
111+
commandline: board.upload[0].commandline,
112+
signature: board.upload[0].options.signature,
113+
extrafiles: [],
114+
options: {
115+
wait_for_upload_port: (board.upload[0].options.wait_for_upload_port === true || board.upload[0].options.wait_for_upload_port === 'true'),
116+
use_1200bps_touch: (board.upload[0].options.use_1200bps_touch === true || board.upload[0].options.use_1200bps_touch === 'true'),
117+
params_verbose: '-v'
118+
}
119+
};
120+
121+
this.upload(uploadTarget, uploadData);
122+
}
123+
124+
initUpload() {
125+
this.uploading.next({ status: this.UPLOAD_NOPE });
126+
}
96127
}

src/socket-daemon.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import semVerCompare from 'semver-compare';
3232
import { detect } from 'detect-browser';
3333

3434
import { BehaviorSubject, timer } from 'rxjs';
35-
import { delayWhen, filter, takeUntil, first } from 'rxjs/operators';
35+
import { filter, takeUntil, first } from 'rxjs/operators';
3636

3737
import Daemon from './daemon';
3838

@@ -330,8 +330,8 @@ export default class SocketDaemon extends Daemon {
330330
return;
331331
}
332332
if (message.Flash === 'Ok' && message.ProgrammerStatus === 'Done') {
333-
this.uploading.next({ status: this.UPLOAD_DONE, msg: message.Flash });
334-
return;
333+
// After the upload is completed the port goes down for a while, so we have to wait a few seconds
334+
return timer(10000).subscribe(() => this.uploading.next({ status: this.UPLOAD_DONE, msg: message.Flash }));
335335
}
336336
switch (message.ProgrammerStatus) {
337337
case 'Starting':
@@ -437,17 +437,22 @@ export default class SocketDaemon extends Daemon {
437437
payload.extrafiles.push({ filename: data.files[i].name, hex: data.files[i].data });
438438
}
439439

440-
fetch(`${this.pluginURL}/upload`, {
441-
method: 'POST',
442-
headers: {
443-
'Content-Type': 'text/plain; charset=utf-8'
444-
},
445-
body: JSON.stringify(payload)
446-
})
447-
.catch(error => {
448-
this.uploading.next({ status: this.UPLOAD_ERROR, err: error });
449-
});
450-
}
440+
this.serialMonitorOpened.pipe(filter(open => !open))
441+
.pipe(first())
442+
.subscribe(() => {
443+
444+
fetch(`${this.pluginURL}/upload`, {
445+
method: 'POST',
446+
headers: {
447+
'Content-Type': 'text/plain; charset=utf-8'
448+
},
449+
body: JSON.stringify(payload)
450+
})
451+
.catch(error => {
452+
this.uploading.next({ status: this.UPLOAD_ERROR, err: error });
453+
});
454+
})
455+
}
451456

452457
/**
453458
* Download tool

0 commit comments

Comments
 (0)