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 8c60ed9

Browse files
author
Alberto Iannaccone
committedOct 29, 2021
refactor monito connection and fix some connection issues
1 parent 617d985 commit 8c60ed9

File tree

5 files changed

+247
-318
lines changed

5 files changed

+247
-318
lines changed
 

‎arduino-ide-extension/src/browser/contributions/burn-bootloader.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ export class BurnBootloader extends SketchContribution {
4444
}
4545

4646
async burnBootloader(): Promise<void> {
47-
const monitorConfig = this.monitorConnection.monitorConfig;
48-
const serialConnection = this.monitorConnection.connectionType;
49-
50-
if (monitorConfig) {
51-
await this.monitorConnection.disconnect(serialConnection);
52-
}
47+
await this.monitorConnection.disconnect();
5348
try {
5449
const { boardsConfig } = this.boardsServiceClientImpl;
5550
const port = boardsConfig.selectedPort;
@@ -76,8 +71,8 @@ export class BurnBootloader extends SketchContribution {
7671
} catch (e) {
7772
this.messageService.error(e.toString());
7873
} finally {
79-
if (monitorConfig) {
80-
await this.monitorConnection.connect(serialConnection, monitorConfig);
74+
if (this.monitorConnection.isSerialOpen()) {
75+
await this.monitorConnection.connect();
8176
}
8277
}
8378
}

‎arduino-ide-extension/src/browser/contributions/upload-sketch.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@ export class UploadSketch extends SketchContribution {
104104
if (!sketch) {
105105
return;
106106
}
107-
let shouldAutoConnect = false;
108-
const monitorConfig = this.monitorConnection.monitorConfig;
109-
const serialConnection = this.monitorConnection.connectionType;
110-
if (monitorConfig) {
111-
await this.monitorConnection.disconnect(serialConnection);
112-
if (this.monitorConnection.autoConnect) {
113-
shouldAutoConnect = true;
114-
}
115-
this.monitorConnection.autoConnect = false;
116-
}
107+
await this.monitorConnection.disconnect();
117108
try {
118109
const { boardsConfig } = this.boardsServiceClientImpl;
119110
const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] =
@@ -169,18 +160,17 @@ export class UploadSketch extends SketchContribution {
169160
this.uploadInProgress = false;
170161
this.onDidChangeEmitter.fire();
171162

172-
if (monitorConfig) {
173-
const { board, port } = monitorConfig;
163+
if (
164+
this.monitorConnection.isSerialOpen() &&
165+
this.monitorConnection.monitorConfig
166+
) {
167+
const { board, port } = this.monitorConnection.monitorConfig;
174168
try {
175169
await this.boardsServiceClientImpl.waitUntilAvailable(
176170
Object.assign(board, { port }),
177171
10_000
178172
);
179-
this.monitorConnection.connect(
180-
serialConnection,
181-
monitorConfig,
182-
shouldAutoConnect
183-
);
173+
await this.monitorConnection.connect();
184174
} catch (waitError) {
185175
this.messageService.error(
186176
`Could not reconnect to serial monitor. ${waitError.toString()}`

‎arduino-ide-extension/src/browser/monitor/monitor-connection.ts

Lines changed: 226 additions & 265 deletions
Large diffs are not rendered by default.

‎arduino-ide-extension/src/browser/monitor/monitor-widget.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ export class MonitorWidget extends ReactWidget {
5252
this.scrollOptions = undefined;
5353
this.toDispose.push(this.clearOutputEmitter);
5454
this.toDispose.push(
55-
Disposable.create(() => {
56-
this.monitorConnection.autoConnect = false;
57-
if (this.monitorConnection.connected) {
58-
this.monitorConnection.disconnect(SerialType.Monitor);
59-
}
60-
})
55+
Disposable.create(() =>
56+
this.monitorConnection.closeSerial(SerialType.Monitor)
57+
)
6158
);
6259
}
6360

@@ -82,7 +79,7 @@ export class MonitorWidget extends ReactWidget {
8279
super.onAfterAttach(msg);
8380
// const { boardsConfig } = this.boardsServiceProvider;
8481

85-
this.monitorConnection.connect(SerialType.Monitor, undefined, true);
82+
this.monitorConnection.openSerial(SerialType.Monitor);
8683
}
8784

8885
onCloseRequest(msg: Message): void {

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ArduinoMenus } from '../menu/arduino-menus';
1111
import { Contribution } from '../contributions/contribution';
1212
import { Endpoint, FrontendApplication } from '@theia/core/lib/browser';
1313
import { ipcRenderer } from '@theia/core/shared/electron';
14-
import { MonitorConfig } from '../../common/protocol';
14+
import { MonitorConfig, Status } from '../../common/protocol';
1515
import { MonitorConnection, SerialType } from '../monitor/monitor-connection';
1616
import { SerialPlotter } from './protocol';
1717
import { BoardsServiceProvider } from '../boards/boards-service-provider';
@@ -49,8 +49,7 @@ export class PlotterFrontendContribution extends Contribution {
4949
ipcRenderer.on('CLOSE_CHILD_WINDOW', async () => {
5050
if (this.window) {
5151
this.window = null;
52-
await this.monitorConnection.disconnect(SerialType.Plotter);
53-
this.monitorConnection.autoConnect = false;
52+
await this.monitorConnection.closeSerial(SerialType.Plotter);
5453
}
5554
});
5655

@@ -78,25 +77,12 @@ export class PlotterFrontendContribution extends Contribution {
7877
return;
7978
}
8079
}
81-
const { boardsConfig } = this.boardsServiceProvider;
82-
const { selectedBoard: board, selectedPort: port } = boardsConfig;
83-
const { baudRate } = this.model;
84-
if (board && port) {
85-
const status = await this.monitorConnection.connect(SerialType.Plotter, {
86-
board,
87-
port,
88-
baudRate,
89-
});
90-
const wsPort = this.monitorConnection.getWsPort();
91-
if (status && wsPort) {
92-
this.open(wsPort);
93-
} else {
94-
this.messageService.error(`Couldn't open serial plotter`);
95-
}
80+
const status = await this.monitorConnection.openSerial(SerialType.Plotter);
81+
const wsPort = this.monitorConnection.getWsPort();
82+
if (Status.isOK(status) && wsPort) {
83+
this.open(wsPort);
9684
} else {
97-
this.messageService.error(
98-
`Please select a board and a port to open the Serial Plotter.`
99-
);
85+
this.messageService.error(`Couldn't open serial plotter`);
10086
}
10187
}
10288

0 commit comments

Comments
 (0)
Please sign in to comment.