Skip to content

Improved support for Web Serial API. #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.10.0] - 2022-09-08
## [2.11.0] - 2022-09-27

### Changed
- When using Web Serial API, the interactions between the client library
(as an example, the Arduino `arduino-chromeos-uploader` libray) has been simplified.
- A new parameter `dialogCustomizations` has been added to the upload functionality. It's used
to provide custom confirmation dialogs when using the Web Serial API.
It has no effect with other daemons.

### Removed
- `cdcReset` functionality, now it's embedded in the `upload` functionality
in the Web Serial daemon.
### Changed

## [2.10.1] - 2022-09-08

### Changed
- 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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arduino-create-agent-js-client",
"version": "2.10.1",
"version": "2.11.0-alpha.2",
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
9 changes: 7 additions & 2 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ export default class Daemon {
* @param {string} sketchName
* @param {Object} compilationResult
* @param {boolean} verbose
* @param {any[]} dialogCustomizations Optional - Used in Web Serial API to customize the permission dialogs.
* It's an array because the Web Serial API library can use more than one dialog, e.g. one to
* ask permission and one to give instruction to save an UF2 file.
* It's called 'customizations' because the library already provides a basic non-styled dialog.
*/
uploadSerial(target, sketchName, compilationResult, verbose = true) {
uploadSerial(target, sketchName, compilationResult, verbose = true, dialogCustomizations) {
this.uploadingPort = target.port;
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Upload started' });
this.serialDevicesBeforeUpload = this.devicesList.getValue().serial;
Expand All @@ -142,7 +146,8 @@ export default class Daemon {
commandline: uploadCommandInfo.commandline,
filename: `${sketchName}.${ext}`,
hex: data, // For desktop agent
data // For chromeOS plugin, consider to align this
data, // For chromeOS plugin, consider to align this
dialogCustomizations // used only in Web Serial API uploader
};

this.uploadingDone.subscribe(() => {
Expand Down
39 changes: 23 additions & 16 deletions src/web-serial-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ export default class WebSerialDaemon extends Daemon {
}
}

/**
* Send the 'writePort' message to the serial port
* @param {string} port the port name
* @param {string} message the text to be sent to serial
*/
writeSerial(port, message) {
this.channel.postMessage({
command: 'writePort',
data: {
name: port,
data: message
}
});
}

/**
* Request serial port open
* @param {string} port the port name
Expand Down Expand Up @@ -247,23 +262,12 @@ export default class WebSerialDaemon extends Daemon {
});
}

cdcReset({ fqbn, port }) {
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'CDC reset started' });
this.channel.postMessage({
command: 'cdcReset',
data: {
fqbn,
port
}
});
}

connectToSerialDevice({ fqbn }) {
this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Board selection started' });
connectToSerialDevice({ from, dialogCustomization }) {
this.channel.postMessage({
command: 'connectToSerial',
data: {
fqbn
from,
dialogCustomization
}
});
}
Expand All @@ -274,9 +278,11 @@ export default class WebSerialDaemon extends Daemon {
*/
_upload(uploadPayload, uploadCommandInfo) {
const {
board, port, commandline, data, pid, vid
board, port, commandline, data, pid, vid, dialogCustomizations
} = uploadPayload;

const extrafiles = uploadCommandInfo && uploadCommandInfo.files && Array.isArray(uploadCommandInfo.files) ? uploadCommandInfo.files : [];

try {
window.oauth.getAccessToken().then(token => {
this.channel.postMessage({
Expand All @@ -289,7 +295,8 @@ export default class WebSerialDaemon extends Daemon {
token: token.token,
extrafiles,
pid,
vid
vid,
dialogCustomizations
}
});
});
Expand Down