Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7464b77

Browse files
committedOct 10, 2022
Improved support for Web Serial API.
* Now the interaction between the client library (e.g. the Arduino `arduino-chromeos-uploader` library) has been simplified. * Added a parameter to pass dialog customization to the web serial api uploader library * Removed `connectToSerialDevice` function from the Web Serial API daemon. * Added functionality to write on the serial port
1 parent 6ee305c commit 7464b77

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed
 

‎CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [2.10.0] - 2022-09-08
4+
## [2.11.0] - 2022-09-27
5+
6+
### Changed
7+
- When using Web Serial API, the interactions between the client library
8+
(as an example, the Arduino `arduino-chromeos-uploader` libray) has been simplified.
9+
- A new parameter `dialogCustomizations` has been added to the upload functionality. It's used
10+
to provide custom confirmation dialogs when using the Web Serial API.
11+
It has no effect with other daemons.
12+
13+
### Removed
14+
- `connectToSerialDevice` functionality, now it's embedded in the `upload` functionality
15+
in the Web Serial daemon.
16+
### Changed
17+
18+
## [2.10.1] - 2022-09-08
519

620
### Changed
721
- Fixed a bug released in 2.9.1 caused by the wrong assumption that the build filename is always at the end of the command line. This fix makes the library backward compatible with older ESP boards.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arduino-create-agent-js-client",
3-
"version": "2.10.1",
3+
"version": "2.11.0-alpha.2",
44
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
55
"main": "lib/index.js",
66
"module": "es/index.js",

‎src/daemon.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ export default class Daemon {
115115
* @param {string} sketchName
116116
* @param {Object} compilationResult
117117
* @param {boolean} verbose
118+
* @param {any[]} dialogCustomizations Optional - Used in Web Serial API to customize the permission dialogs.
119+
* It's an array because the Web Serial API library can use more than one dialog, e.g. one to
120+
* ask permission and one to give instruction to save an UF2 file.
121+
* It's called 'customizations' because the library already provides a basic non-styled dialog.
118122
*/
119-
uploadSerial(target, sketchName, compilationResult, verbose = true) {
123+
uploadSerial(target, sketchName, compilationResult, verbose = true, dialogCustomizations) {
120124
this.uploadingPort = target.port;
121125
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Upload started' });
122126
this.serialDevicesBeforeUpload = this.devicesList.getValue().serial;
@@ -142,7 +146,8 @@ export default class Daemon {
142146
commandline: uploadCommandInfo.commandline,
143147
filename: `${sketchName}.${ext}`,
144148
hex: data, // For desktop agent
145-
data // For chromeOS plugin, consider to align this
149+
data, // For chromeOS plugin, consider to align this
150+
dialogCustomizations // used only in Web Serial API uploader
146151
};
147152

148153
this.uploadingDone.subscribe(() => {

‎src/web-serial-daemon.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ export default class WebSerialDaemon extends Daemon {
190190
}
191191
}
192192

193+
/**
194+
* Send the 'writePort' message to the serial port
195+
* @param {string} port the port name
196+
* @param {string} message the text to be sent to serial
197+
*/
198+
writeSerial(port, message) {
199+
this.channel.postMessage({
200+
command: 'writePort',
201+
data: {
202+
name: port,
203+
data: message
204+
}
205+
});
206+
}
207+
193208
/**
194209
* Request serial port open
195210
* @param {string} port the port name
@@ -247,23 +262,12 @@ export default class WebSerialDaemon extends Daemon {
247262
});
248263
}
249264

250-
cdcReset({ fqbn, port }) {
251-
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'CDC reset started' });
252-
this.channel.postMessage({
253-
command: 'cdcReset',
254-
data: {
255-
fqbn,
256-
port
257-
}
258-
});
259-
}
260-
261-
connectToSerialDevice({ fqbn }) {
262-
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Board selection started' });
265+
connectToSerialDevice({ from, dialogCustomization }) {
263266
this.channel.postMessage({
264267
command: 'connectToSerial',
265268
data: {
266-
fqbn
269+
from,
270+
dialogCustomization
267271
}
268272
});
269273
}
@@ -274,9 +278,11 @@ export default class WebSerialDaemon extends Daemon {
274278
*/
275279
_upload(uploadPayload, uploadCommandInfo) {
276280
const {
277-
board, port, commandline, data, pid, vid
281+
board, port, commandline, data, pid, vid, dialogCustomizations
278282
} = uploadPayload;
283+
279284
const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : [];
285+
280286
try {
281287
window.oauth.getAccessToken().then(token => {
282288
this.channel.postMessage({
@@ -289,7 +295,8 @@ export default class WebSerialDaemon extends Daemon {
289295
token: token.token,
290296
extrafiles,
291297
pid,
292-
vid
298+
vid,
299+
dialogCustomizations
293300
}
294301
});
295302
});

0 commit comments

Comments
 (0)
Please sign in to comment.