Skip to content

Commit 01ec377

Browse files
author
Alberto Iannaccone
committed
ease upload
1 parent 2cf3144 commit 01ec377

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
@@ -150,29 +150,6 @@ export default class BoardConfiguration {
150150
}
151151
this.serialMonitorContent = '';
152152

153-
const uploadTarget = {
154-
board: board.fqbn,
155-
port: board.port,
156-
network: false
157-
};
158-
159-
const file = {
160-
name: compiledSketch.name + board.upload[0].ext,
161-
data: compiledSketch.hex
162-
};
163-
164-
const uploadData = {
165-
files: [file],
166-
commandline: board.upload[0].commandline,
167-
signature: board.upload[0].options.signature,
168-
extrafiles: [],
169-
options: {
170-
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
171-
use_1200bps_touch: (board.upload[0].options.use_1200bps_touch === true || board.upload[0].options.use_1200bps_touch === 'true'), // eslint-disable-line camelcase
172-
params_verbose: '-v' // eslint-disable-line camelcase
173-
}
174-
};
175-
176153
// check the uploading status:
177154
if (this.daemon.uploading.getValue().status === this.daemon.UPLOAD_IN_PROGRESS) {
178155
// if there is an upload in course, notify observers;
@@ -231,6 +208,7 @@ export default class BoardConfiguration {
231208
this.configuring.next({ status: this.CONFIGURE_ERROR, err: `Couldn't configure board at port ${board.port}. Upload failed with error: ${upload.err}` });
232209
});
233210

234-
this.daemon.upload(uploadTarget, uploadData);
211+
this.daemon.initUpload();
212+
this.daemon.uploadSketch(compiledSketch, board);
235213
}
236214
}

src/daemon.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,35 @@ export default class Daemon {
113113
}
114114
throw new Error('Stop Upload not supported on Chrome OS');
115115
}
116+
117+
uploadSketch(compiledSketch, board) {
118+
const uploadTarget = {
119+
board: board.fqbn,
120+
port: board.port,
121+
network: false
122+
};
123+
124+
const file = {
125+
name: compiledSketch.name + board.upload[0].ext,
126+
data: compiledSketch.hex
127+
};
128+
129+
const uploadData = {
130+
files: [file],
131+
commandline: board.upload[0].commandline,
132+
signature: board.upload[0].options.signature,
133+
extrafiles: [],
134+
options: {
135+
wait_for_upload_port: (board.upload[0].options.wait_for_upload_port === true || board.upload[0].options.wait_for_upload_port === 'true'),
136+
use_1200bps_touch: (board.upload[0].options.use_1200bps_touch === true || board.upload[0].options.use_1200bps_touch === 'true'),
137+
params_verbose: '-v'
138+
}
139+
};
140+
141+
this.upload(uploadTarget, uploadData);
142+
}
143+
144+
initUpload() {
145+
this.uploading.next({ status: this.UPLOAD_NOPE });
146+
}
116147
}

src/socket-daemon.js

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

2525
import { BehaviorSubject, timer } from 'rxjs';
26-
import { filter, takeUntil } from 'rxjs/operators';
26+
import { filter, takeUntil, first } from 'rxjs/operators';
2727

2828
import Daemon from './daemon';
2929

@@ -332,8 +332,8 @@ export default class SocketDaemon extends Daemon {
332332
return;
333333
}
334334
if (message.Flash === 'Ok' && message.ProgrammerStatus === 'Done') {
335-
this.uploading.next({ status: this.UPLOAD_DONE, msg: message.Flash });
336-
return;
335+
// After the upload is completed the port goes down for a while, so we have to wait a few seconds
336+
return timer(10000).subscribe(() => this.uploading.next({ status: this.UPLOAD_DONE, msg: message.Flash }));
337337
}
338338
switch (message.ProgrammerStatus) {
339339
case 'Starting':
@@ -439,17 +439,22 @@ export default class SocketDaemon extends Daemon {
439439
payload.extrafiles.push({ filename: data.files[i].name, hex: data.files[i].data });
440440
}
441441

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

454459
/**
455460
* Download tool

0 commit comments

Comments
 (0)