Skip to content

Commit 5519a82

Browse files
author
Alberto Iannaccone
committed
add serial plotter reset command
1 parent e4c7f05 commit 5519a82

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '../node/monitor-settings/monitor-settings-provider';
1313
import { BoardsConfig } from './boards/boards-config';
1414
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
15+
import { SerialPlotterContribution } from './serial/plotter/plotter-frontend-contribution';
1516

1617
@injectable()
1718
export class MonitorManagerProxyClientImpl
@@ -109,10 +110,14 @@ export class MonitorManagerProxyClientImpl
109110
if (
110111
board.fqbn !== this.lastConnectedBoard?.selectedBoard?.fqbn ||
111112
port.id !== this.lastConnectedBoard?.selectedPort?.id
112-
)
113+
) {
113114
await this.commandRegistry.executeCommand(
114115
MonitorViewContribution.RESET_SERIAL_MONITOR
115116
);
117+
await this.commandRegistry.executeCommand(
118+
SerialPlotterContribution.Commands.RESET.id
119+
);
120+
}
116121
this.lastConnectedBoard = {
117122
selectedBoard: board,
118123
selectedPort: port,

arduino-ide-extension/src/browser/serial/plotter/plotter-frontend-contribution.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export namespace SerialPlotterContribution {
2323
label: 'Serial Plotter',
2424
category: 'Arduino',
2525
};
26+
export const RESET: Command = {
27+
id: 'serial-plotter-reset',
28+
label: 'Reset Serial Plotter',
29+
category: 'Arduino',
30+
};
2631
}
2732
}
2833

@@ -59,6 +64,9 @@ export class PlotterFrontendContribution extends Contribution {
5964
registry.registerCommand(SerialPlotterContribution.Commands.OPEN, {
6065
execute: this.startPlotter.bind(this),
6166
});
67+
registry.registerCommand(SerialPlotterContribution.Commands.RESET, {
68+
execute: () => this.reset(),
69+
});
6270
}
6371

6472
registerMenus(menus: MenuModelRegistry): void {
@@ -96,28 +104,9 @@ export class PlotterFrontendContribution extends Contribution {
96104
}
97105

98106
protected async open(wsPort: number): Promise<void> {
99-
const board = this.boardsServiceProvider.boardsConfig.selectedBoard;
100-
const port = this.boardsServiceProvider.boardsConfig.selectedPort;
101-
let baudrates: number[] = [];
102-
let currentBaudrate = -1;
103-
if (board && port) {
104-
const { pluggableMonitorSettings } =
105-
await this.monitorManagerProxy.getCurrentSettings(board, port);
106-
if (pluggableMonitorSettings && 'baudrate' in pluggableMonitorSettings) {
107-
// Convert from string to numbers
108-
baudrates = pluggableMonitorSettings['baudrate'].values.map((b) => +b);
109-
currentBaudrate = +pluggableMonitorSettings['baudrate'].selectedValue;
110-
}
111-
}
112-
113107
const initConfig: Partial<SerialPlotter.Config> = {
114-
baudrates,
115-
currentBaudrate,
116-
currentLineEnding: this.model.lineEnding,
117108
darkTheme: this.themeService.getCurrentTheme().type === 'dark',
118109
wsPort,
119-
interpolate: this.model.interpolate,
120-
connected: this.model.connected,
121110
serialPort: this.model.serialPort,
122111
};
123112
const urlWithParams = queryString.stringifyUrl(
@@ -129,4 +118,11 @@ export class PlotterFrontendContribution extends Contribution {
129118
);
130119
this.window = window.open(urlWithParams, 'serialPlotter');
131120
}
121+
122+
protected async reset(): Promise<void> {
123+
if (!!this.window) {
124+
this.window.close();
125+
await this.startPlotter();
126+
}
127+
}
132128
}

0 commit comments

Comments
 (0)