Skip to content

Commit a3a22e5

Browse files
Alberto Iannacconefstasi
Alberto Iannaccone
authored andcommitted
handle interpolate message
1 parent 81329e8 commit a3a22e5

9 files changed

+69
-39
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,6 @@ import {
254254
UploadCertificateDialogWidget,
255255
} from './dialogs/certificate-uploader/certificate-uploader-dialog';
256256
import { PlotterFrontendContribution } from './plotter/plotter-frontend-contribution';
257-
import {
258-
PlotterPath,
259-
PlotterService,
260-
} from '../common/protocol/plotter-service';
261257
import { nls } from '@theia/core/lib/browser/nls';
262258

263259
const ElementQueries = require('css-element-queries/src/ElementQueries');
@@ -743,9 +739,4 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
743739
bind(UploadCertificateDialogProps).toConstantValue({
744740
title: 'UploadCertificate',
745741
});
746-
bind(PlotterService)
747-
.toDynamicValue((ctx) =>
748-
ctx.container.get(WebSocketConnectionProvider).createProxy(PlotterPath)
749-
)
750-
.inSingletonScope();
751742
});

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export class SerialConnectionManager {
8383
this.monitorModel.lineEnding = lineending;
8484
}
8585
});
86+
this.monitorServiceClient.onInterpolateChanged((interpolate) => {
87+
if (this.monitorModel.interpolate !== interpolate) {
88+
this.monitorModel.interpolate = interpolate;
89+
}
90+
});
8691

8792
this.monitorServiceClient.onError(this.handleError.bind(this));
8893
this.boardsServiceProvider.onBoardsConfigChanged(
@@ -100,12 +105,12 @@ export class SerialConnectionManager {
100105

101106
// update the current values in the backend and propagate to websocket clients
102107
this.monitorService.updateWsConfigParam({
103-
...(property === 'baudRate' && {
104-
currentBaudrate: this.monitorModel.baudRate,
105-
}),
106108
...(property === 'lineEnding' && {
107109
currentLineEnding: this.monitorModel.lineEnding,
108110
}),
111+
...(property === 'interpolate' && {
112+
interpolate: this.monitorModel.interpolate,
113+
}),
109114
});
110115
});
111116

@@ -131,6 +136,10 @@ export class SerialConnectionManager {
131136
}
132137
});
133138
if (configHasChanged && this.isSerialOpen()) {
139+
this.monitorService.updateWsConfigParam({
140+
currentBaudrate: this.config.baudRate,
141+
serialPort: this.config.port?.address,
142+
});
134143
this.disconnect().then(() => this.connect());
135144
}
136145
}
@@ -212,6 +221,8 @@ export class SerialConnectionManager {
212221

213222
set connected(c: boolean) {
214223
this._connected = c;
224+
this.monitorService.updateWsConfigParam({ connected: c });
225+
215226
this.onConnectionChangedEmitter.fire(this._connected);
216227
}
217228
/**

arduino-ide-extension/src/browser/monitor/monitor-model.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ export class MonitorModel implements FrontendApplicationContribution {
2424
protected _timestamp: boolean;
2525
protected _baudRate: MonitorConfig.BaudRate;
2626
protected _lineEnding: MonitorModel.EOL;
27+
protected _interpolate: boolean;
2728

2829
constructor() {
2930
this._autoscroll = true;
3031
this._timestamp = false;
3132
this._baudRate = MonitorConfig.BaudRate.DEFAULT;
3233
this._lineEnding = MonitorModel.EOL.DEFAULT;
34+
this._interpolate = false;
3335
this.onChangeEmitter = new Emitter<
3436
MonitorModel.State.Change<keyof MonitorModel.State>
3537
>();
@@ -106,11 +108,26 @@ export class MonitorModel implements FrontendApplicationContribution {
106108
);
107109
}
108110

111+
get interpolate(): boolean {
112+
return this._interpolate;
113+
}
114+
115+
set interpolate(i: boolean) {
116+
this._interpolate = i;
117+
this.storeState().then(() =>
118+
this.onChangeEmitter.fire({
119+
property: 'interpolate',
120+
value: this._interpolate,
121+
})
122+
);
123+
}
124+
109125
protected restoreState(state: MonitorModel.State): void {
110126
this._autoscroll = state.autoscroll;
111127
this._timestamp = state.timestamp;
112128
this._baudRate = state.baudRate;
113129
this._lineEnding = state.lineEnding;
130+
this._interpolate = state.interpolate;
114131
}
115132

116133
protected async storeState(): Promise<void> {
@@ -119,6 +136,7 @@ export class MonitorModel implements FrontendApplicationContribution {
119136
timestamp: this._timestamp,
120137
baudRate: this._baudRate,
121138
lineEnding: this._lineEnding,
139+
interpolate: this._interpolate,
122140
});
123141
}
124142
}
@@ -129,6 +147,7 @@ export namespace MonitorModel {
129147
timestamp: boolean;
130148
baudRate: MonitorConfig.BaudRate;
131149
lineEnding: EOL;
150+
interpolate: boolean;
132151
}
133152
export namespace State {
134153
export interface Change<K extends keyof State> {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ export class MonitorServiceClientImpl implements MonitorServiceClient {
1515
protected readonly onWebSocketChangedEmitter = new Emitter<number>();
1616
readonly onWebSocketChanged = this.onWebSocketChangedEmitter.event;
1717

18-
protected readonly onBaudEmitter = new Emitter<MonitorConfig.BaudRate>();
19-
readonly onBaudRateChanged = this.onBaudEmitter.event;
18+
protected readonly onBaudRateChangedEmitter =
19+
new Emitter<MonitorConfig.BaudRate>();
20+
readonly onBaudRateChanged = this.onBaudRateChangedEmitter.event;
2021

21-
protected readonly onEolEmitter = new Emitter<MonitorModel.EOL>();
22-
readonly onLineEndingChanged = this.onEolEmitter.event;
22+
protected readonly onLineEndingChangedEmitter =
23+
new Emitter<MonitorModel.EOL>();
24+
readonly onLineEndingChanged = this.onLineEndingChangedEmitter.event;
25+
26+
protected readonly onInterpolateChangedEmitter = new Emitter<boolean>();
27+
readonly onInterpolateChanged = this.onInterpolateChangedEmitter.event;
2328

2429
notifyError(error: MonitorError): void {
2530
this.onErrorEmitter.fire(error);
@@ -30,10 +35,14 @@ export class MonitorServiceClientImpl implements MonitorServiceClient {
3035
}
3136

3237
notifyBaudRateChanged(message: MonitorConfig.BaudRate): void {
33-
this.onBaudEmitter.fire(message);
38+
this.onBaudRateChangedEmitter.fire(message);
3439
}
3540

3641
notifyLineEndingChanged(message: MonitorModel.EOL): void {
37-
this.onEolEmitter.fire(message);
42+
this.onLineEndingChangedEmitter.fire(message);
43+
}
44+
45+
notifyInterpolateChanged(message: boolean): void {
46+
this.onInterpolateChangedEmitter.fire(message);
3847
}
3948
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { injectable, inject } from 'inversify';
33
import {
44
Command,
55
CommandRegistry,
6-
DisposableCollection,
76
MaybePromise,
87
MenuModelRegistry,
98
} from '@theia/core';
@@ -33,7 +32,6 @@ export class PlotterFrontendContribution extends Contribution {
3332
protected window: Window | null;
3433
protected url: string;
3534
protected wsPort: number;
36-
protected toDispose = new DisposableCollection();
3735

3836
@inject(MonitorModel)
3937
protected readonly model: MonitorModel;
@@ -51,12 +49,17 @@ export class PlotterFrontendContribution extends Contribution {
5149
this.url = new Endpoint({ path: '/plotter' }).getRestUrl().toString();
5250

5351
ipcRenderer.on('CLOSE_CHILD_WINDOW', async () => {
54-
if (this.window) {
52+
if (!!this.window) {
5553
this.window = null;
5654
await this.monitorConnection.closeSerial(Serial.Type.Plotter);
5755
}
5856
});
5957

58+
this.monitorConnection.onConnectionChanged((connected) => {
59+
if (!!this.window) {
60+
}
61+
});
62+
6063
return super.onStart(app);
6164
}
6265

@@ -76,7 +79,7 @@ export class PlotterFrontendContribution extends Contribution {
7679

7780
async connect(): Promise<void> {
7881
if (this.monitorConnection.connected) {
79-
if (this.window) {
82+
if (!!this.window) {
8083
this.window.focus();
8184
return;
8285
}
@@ -91,12 +94,15 @@ export class PlotterFrontendContribution extends Contribution {
9194
}
9295

9396
protected open(wsPort: number): void {
94-
const initConfig: SerialPlotter.Config = {
97+
const initConfig: Partial<SerialPlotter.Config> = {
9598
baudrates: MonitorConfig.BaudRates.map((b) => b),
9699
currentBaudrate: this.model.baudRate,
97100
currentLineEnding: this.model.lineEnding,
98101
darkTheme: this.themeService.getCurrentTheme().type === 'dark',
99102
wsPort,
103+
interpolate: this.model.interpolate,
104+
connected: this.monitorConnection.connected,
105+
serialPort: this.boardsServiceProvider.boardsConfig.selectedPort?.address,
100106
};
101107
const urlWithParams = queryString.stringifyUrl(
102108
{

arduino-ide-extension/src/browser/plotter/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ export namespace SerialPlotter {
55
currentLineEnding: string;
66
darkTheme: boolean;
77
wsPort: number;
8+
interpolate: boolean;
9+
serialPort: string;
10+
connected: boolean;
811
generate?: boolean;
912
};
1013
export namespace Protocol {
1114
export enum Command {
1215
PLOTTER_SET_BAUDRATE = 'PLOTTER_SET_BAUDRATE',
1316
PLOTTER_SET_LINE_ENDING = 'PLOTTER_SET_LINE_ENDING',
17+
PLOTTER_SET_INTERPOLATE = 'PLOTTER_SET_INTERPOLATE',
1418
PLOTTER_SEND_MESSAGE = 'PLOTTER_SEND_MESSAGE',
1519
MIDDLEWARE_CONFIG_CHANGED = 'MIDDLEWARE_CONFIG_CHANGED',
1620
}

arduino-ide-extension/src/common/protocol/monitor-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ export interface MonitorServiceClient {
6161
onWebSocketChanged: Event<number>;
6262
onLineEndingChanged: Event<MonitorModel.EOL>;
6363
onBaudRateChanged: Event<MonitorConfig.BaudRate>;
64+
onInterpolateChanged: Event<boolean>;
6465
notifyError(event: MonitorError): void;
6566
notifyWebSocketChanged(message: number): void;
6667
notifyLineEndingChanged(message: MonitorModel.EOL): void;
6768
notifyBaudRateChanged(message: MonitorConfig.BaudRate): void;
69+
notifyInterpolateChanged(message: boolean): void;
6870
}
6971

7072
export interface MonitorError {

arduino-ide-extension/src/common/protocol/plotter-service.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

arduino-ide-extension/src/node/monitor/monitor-service-impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export class MonitorServiceImpl implements MonitorService {
167167
this.client?.notifyLineEndingChanged(message.data);
168168
break;
169169

170+
case SerialPlotter.Protocol.Command.PLOTTER_SET_INTERPOLATE:
171+
this.client?.notifyInterpolateChanged(message.data);
172+
break;
173+
170174
default:
171175
break;
172176
}

0 commit comments

Comments
 (0)