8000 Serial Plotter implementation by AlbyIanna · Pull Request #597 · arduino/arduino-ide · GitHub
[go: up one dir, main page]

Skip to content

Serial Plotter implementation #597

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

Merged
merged 27 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
401bcf5
spawn new window where to instantiate serial plotter app
Oct 14, 2021
a834e86
initialize serial monito web app
Oct 20, 2021
a145ad9
WIP connect serial plotter app with websocket
Oct 21, 2021
d7c85fb
use npm serial-plotter package
fstasi Oct 25, 2021
f0fdc24
connect serial plotter app with websocket
Oct 21, 2021
3d616c5
refactor monito connection and fix some connection issues
Oct 29, 2021
eead91d
plotter communication
fstasi Nov 3, 2021
6ab7a38
fix clearConsole + refactor monitor connection
Nov 4, 2021
ef1377e
fixed duplicated message issue
fstasi Nov 4, 2021
eed7366
sync EoL and baudRates
fstasi Nov 4, 2021
8f1223c
add serial unit tests
Nov 9, 2021
dbaf244
updated serial plotter webapp
fstasi Nov 10, 2021
df9902d
updated serial plotter webapp to 0.0.6
fstasi Nov 11, 2021
31fde3e
handle interpolate message
Nov 11, 2021
f96a04a
fix reconnecting issues
Nov 11, 2021
5052862
updated plotter to 0.0.8
fstasi Nov 11, 2021
ee607af
bump arduino-serial-plotter-webapp to 0.0.10
Nov 15, 2021
f4938b5
bump arduino-serial-plotter-webapp to 0.0.11
Nov 16, 2021
e17960b
fix upload when serial port is open
Nov 16, 2021
1f0d4bf
remove menu bar on windows/linux
Nov 16, 2021
89e7bab
dispose send message event listener on disconnect
Nov 17, 2021
ad1cb25
update serial plotter app to 0.0.13
fstasi Nov 22, 2021
f333bbd
i18n generation
fstasi Nov 22, 2021
03eb1b3
clear flush message interval when disconnecting
Nov 23, 2021
90f9afe
bump arduino-serial-plotter-webapp to 0.0.15
Nov 23, 2021
e352f5a
refactoring and cleaning code
Nov 23, 2021
118f7f0
update localisation for serial
Nov 23, 2021
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
Prev Previous commit
Next Next commit
fix upload when serial port is open
  • Loading branch information
Alberto Iannaccone authored and fstasi committed Nov 23, 2021
commit e17960b333331d0d863ebcebd84f574c348fe2ee
43 changes: 27 additions & 16 deletions arduino-ide-extension/src/browser/monitor/monitor-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BoardsConfig } from '../boards/boards-config';
import { MonitorModel } from './monitor-model';
import { ThemeService } from '@theia/core/lib/browser/theming';
import { nls } from '@theia/core/lib/browser/nls';
import { CoreService } from '../../common/protocol';

@injectable()
export class SerialConnectionManager {
Expand Down Expand Up @@ -64,7 +65,8 @@ export class SerialConnectionManager {
@inject(BoardsServiceProvider)
protected readonly boardsServiceProvider: BoardsServiceProvider,
@inject(MessageService) protected messageService: MessageService,
@inject(ThemeService) protected readonly themeService: ThemeService
@inject(ThemeService) protected readonly themeService: ThemeService,
@inject(CoreService) protected readonly core: CoreService
) {
this.monitorServiceClient.onWebSocketChanged(
this.handleWebSocketChanged.bind(this)
Expand Down Expand Up @@ -121,20 +123,25 @@ export class SerialConnectionManager {
*
* @param newConfig the porperties of the config that has changed
*/
setConfig(newConfig: Partial<MonitorConfig>): void {
async setConfig(newConfig: Partial<MonitorConfig>): Promise<void> {
let configHasChanged = false;
Object.keys(this.config).forEach((key: keyof MonitorConfig) => {
if (newConfig[key] !== this.config[key]) {
configHasChanged = true;
this.config = { ...this.config, [key]: newConfig[key] };
}
});
if (configHasChanged && this.isSerialOpen()) {
if (
configHasChanged &&
this.isSerialOpen() &&
!(await this.core.isUploading())
) {
this.monitorService.updateWsConfigParam({
currentBaudrate: this.config.baudRate,
serialPort: this.config.port?.address,
});
this.disconnect().then(() => this.connect());
await this.disconnect();
await this.connect();
}
}

Expand Down Expand Up @@ -176,22 +183,25 @@ export class SerialConnectionManager {
/**
* Sets the types of connections needed by the client.
*
* @param s The new types of connections (can be 'Monitor', 'Plotter', none or both).
* @param newState The new types of connections (can be 'Monitor', 'Plotter', none or both).
* If the previuos state was empty and 's' is not, it tries to reconnect to the serial service
* If the provios state was NOT empty and now it is, it disconnects to the serial service
* @returns The status of the operation
*/
protected async setState(s: Serial.State): Promise<Status> {
protected async setState(newState: Serial.State): Promise<Status> {
const oldState = deepClone(this._state);
this._state = s;
let status = Status.OK;

if (this.isSerialOpen(oldState) && !this.isSerialOpen()) {
if (this.isSerialOpen(oldState) && !this.isSerialOpen(newState)) {
status = await this.disconnect();
} else if (!this.isSerialOpen(oldState) && this.isSerialOpen()) {
} else if (!this.isSerialOpen(oldState) && this.isSerialOpen(newState)) {
if (await this.core.isUploading()) {
this.messageService.error(`Cannot open serial port when uploading`);
return Status.NOT_CONNECTED;
}
status = await this.connect();
}

this._state = newState;
return status;
}

Expand Down Expand Up @@ -226,6 +236,12 @@ export class SerialConnectionManager {
* @returns the status of the operation
*/
async openSerial(type: Serial.Type): Promise<Status> {
if (!isMonitorConfig(this.config)) {
this.messageService.error(
`Please select a board and a port to open the serial connection.`
);
return Status.NOT_CONNECTED;
}
if (this.state.includes(type)) return Status.OK;
const newState = deepClone(this.state);
newState.push(type);
Expand Down Expand Up @@ -360,12 +376,7 @@ export class SerialConnectionManager {

async connect(): Promise<Status> {
if (this.connected) return Status.ALREADY_CONNECTED;
if (!isMonitorConfig(this.config)) {
this.messageService.error(
`Please select a board and a port to open the serial connection.`
);
return Status.NOT_CONNECTED;
}
if (!isMonitorConfig(this.config)) return Status.NOT_CONNECTED;

console.info(
`>>> Creating serial connection for ${Board.toString(
Expand Down
1 change: 1 addition & 0 deletions arduino-ide-extension/src/browser/monitor/monitor-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function messagesToLines(
const linesToAdd: Line[] = prevLines.length
? [prevLines[prevLines.length - 1]]
: [{ message: '', lineLen: 0 }];
if (!(Symbol.iterator in Object(messages))) return [prevLines, charCount];

for (const message of messages) {
const messageLen = message.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ export class PlotterFrontendContribution extends Contribution {
}
});

this.monitorConnection.onConnectionChanged((connected) => {
if (!!this.window) {
}
});

return super.onStart(app);
}

Expand All @@ -78,17 +73,16 @@ export class PlotterFrontendContribution extends Contribution {
}

async connect(): Promise<void> {
if (this.monitorConnection.connected) {
if (!!this.window) {
this.window.focus();
return;
}
if (!!this.window) {
this.window.focus();
return;
}
const status = await this.monitorConnection.openSerial(Serial.Type.Plotter);
const wsPort = this.monitorConnection.getWsPort();
if (Status.isOK(status) && wsPort) {
this.open(wsPort);
} else {
this.monitorConnection.closeSerial(Serial.Type.Plotter);
this.messageService.error(`Couldn't open serial plotter`);
}
}
Expand Down
1 change: 1 addition & 0 deletions arduino-ide-extension/src/common/protocol/core-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface CoreService {
upload(options: CoreService.Upload.Options): Promise<void>;
uploadUsingProgrammer(options: CoreService.Upload.Options): Promise<void>;
burnBootloader(options: CoreService.Bootloader.Options): Promise<void>;
isUploading(): Promise<boolean>;
}

export namespace CoreService {
Expand Down
9 changes: 9 additions & 0 deletions arduino-ide-extension/src/node/core-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
@inject(NotificationServiceServer)
protected readonly notificationService: NotificationServiceServer;

protected uploading = false;

async compile(
options: CoreService.Compile.Options & {
exportBinaries?: boolean;
Expand Down Expand Up @@ -110,6 +112,10 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
);
}

isUploading(): Promise<boolean> {
return Promise.resolve(this.uploading);
}

protected async doUpload(
options: CoreService.Upload.Options,
requestProvider: () => UploadRequest | UploadUsingProgrammerRequest,
Expand All @@ -120,6 +126,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
) => ClientReadableStream<UploadResponse | UploadUsingProgrammerResponse>,
task = 'upload'
): Promise<void> {
this.uploading = true;
await this.compile(Object.assign(options, { exportBinaries: false }));
const { sketchUri, fqbn, port, programmer } = options;
const sketchPath = FileUri.fsPath(sketchUri);
Expand Down Expand Up @@ -173,6 +180,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
severity: 'error',
});
throw e;
} finally {
this.uploading = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Emitter, MessageService } from '@theia/core';
import { BoardsServiceProvider } from '../../browser/boards/boards-service-provider';
import {
BoardsService,
CoreService,
MonitorService,
MonitorServiceClient,
Status,
Expand Down Expand Up @@ -51,6 +52,7 @@ describe.only('SerialConnectionManager', () => {
let boardsServiceProvider: IMock<BoardsServiceProvider>;
let messageService: IMock<MessageService>;
let themeService: IMock<ThemeService>;
let core: IMock<CoreService>;

let handleBoardConfigChange: (
boardsConfig: BoardsConfig.Config
Expand All @@ -68,6 +70,7 @@ describe.only('SerialConnectionManager', () => {
boardsServiceProvider = Mock.ofType<BoardsServiceProvider>();
messageService = Mock.ofType<MessageService>();
themeService = Mock.ofType<ThemeService>();
core = Mock.ofType<CoreService>();

boardsServiceProvider
.setup((b) => b.boardsConfig)
Expand Down Expand Up @@ -103,14 +106,17 @@ describe.only('SerialConnectionManager', () => {
.setup((m) => m.disconnect())
.returns(() => Promise.resolve(Status.OK));

core.setup((u) => u.isUploading()).returns(() => Promise.resolve(false));

subject = new SerialConnectionManager(
monitorModel.object,
monitorService.object,
monitorServiceClient.object,
boardsService.object,
boardsServiceProvider.object,
messageService.object,
themeService.object
themeService.object,
core.object
);
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4109,10 +4109,10 @@ archive-type@^4.0.0:
dependencies:
file-type "^4.2.0"

arduino-serial-plotter-webapp@0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/arduino-serial-plotter-webapp/-/arduino-serial-plotter-webapp-0.0.10.tgz#1379e91705a0462ae31badffabaea8563ef59a51"
integrity sha512-FqFPk2k8iPrMr2vuZfkEbxhbWPy7zn5a9+PMZp2C4akmjdWD6V2ZO89rDOs8ODr0IZgEJxyKpGG212css5vS6g==
arduino-serial-plotter-webapp@0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/arduino-serial-plotter-webapp/-/arduino-serial-plotter-webapp-0.0.11.tgz#a4197f8b2d005ba782bef57ce1aa9b73398ef8a3"
integrity sha512-WcPsCC0S6GefRVdsvFlng4+6ohjiIcTfolr/39zDMV3OjoRPOCqBTEEiYtrymWX9ujaaas1m6aFhTGDjisZwmQ==

are-we-there-yet@~1.1.2:
version "1.1.5"
Expand Down
0