Skip to content

Commit e9c23bd

Browse files
fstasiAlberto Iannaccone
authored and
Alberto Iannaccone
committed
sync EoL and baudRates
1 parent b5bfb6f commit e9c23bd

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

Diff for: arduino-ide-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:watch": "mocha --watch --watch-files lib \"./lib/test/**/*.test.js\""
2020
},
2121
"dependencies": {
22-
"arduino-serial-plotter-webapp": "0.0.3",
22+
"arduino-serial-plotter-webapp": "0.0.4",
2323
"@grpc/grpc-js": "^1.3.7",
2424
"@theia/application-package": "1.18.0",
2525
"@theia/core": "1.18.0",

Diff for: arduino-ide-extension/src/browser/monitor/monitor-connection.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ export class SerialConnectionManager {
8787
this.monitorServiceClient.onWebSocketChanged(
8888
this.handleWebSocketChanged.bind(this)
8989
);
90+
this.monitorServiceClient.onBaudRateChanged((baudRate) => {
91+
if (this.monitorModel.baudRate !== baudRate) {
92+
this.monitorModel.baudRate = baudRate;
93+
}
94+
});
95+
this.monitorServiceClient.onLineEndingChanged((lineending) => {
96+
if (this.monitorModel.lineEnding !== lineending) {
97+
this.monitorModel.lineEnding = lineending;
98+
}
99+
});
100+
90101
this.monitorServiceClient.onError(this.handleError.bind(this));
91102
this.boardsServiceProvider.onBoardsConfigChanged(
92103
this.handleBoardConfigChange.bind(this)
@@ -100,6 +111,16 @@ export class SerialConnectionManager {
100111
const { boardsConfig } = this.boardsServiceProvider;
101112
this.handleBoardConfigChange(boardsConfig);
102113
}
114+
115+
// update the current values in the backend and propagate to websocket clients
116+
this.monitorService.updateWsConfigParam({
117+
...(property === 'baudRate' && {
118+
currentBaudrate: this.monitorModel.baudRate,
119+
}),
120+
...(property === 'lineEnding' && {
121+
currentLineEnding: this.monitorModel.lineEnding,
122+
}),
123+
});
103124
});
104125

105126
this.themeService.onDidColorThemeChange((theme) => {
@@ -452,10 +473,6 @@ export class SerialConnectionManager {
452473
if (ports.some((port) => Port.equals(port, boardsConfig.selectedPort))) {
453474
const { selectedBoard: board, selectedPort: port } = boardsConfig;
454475
const { baudRate } = this.monitorModel;
455-
// update the baudrate on the config
456-
this.monitorService.updateWsConfigParam({
457-
currentBaudrate: baudRate,
458-
});
459476
const newConfig: MonitorConfig = { board, port, baudRate };
460477
this.setConfig(newConfig);
461478
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Emitter } from '@theia/core/lib/common/event';
33
import {
44
MonitorServiceClient,
55
MonitorError,
6+
MonitorConfig,
67
} from '../../common/protocol/monitor-service';
8+
import { MonitorModel } from './monitor-model';
79

810
@injectable()
911
export class MonitorServiceClientImpl implements MonitorServiceClient {
@@ -13,11 +15,25 @@ export class MonitorServiceClientImpl implements MonitorServiceClient {
1315
protected readonly onMessageEmitter = new Emitter<number>();
1416
readonly onWebSocketChanged = this.onMessageEmitter.event;
1517

18+
protected readonly onBaudEmitter = new Emitter<MonitorConfig.BaudRate>();
19+
readonly onBaudRateChanged = this.onBaudEmitter.event;
20+
21+
protected readonly onEolEmitter = new Emitter<MonitorModel.EOL>();
22+
readonly onLineEndingChanged = this.onEolEmitter.event;
23+
1624
notifyError(error: MonitorError): void {
1725
this.onErrorEmitter.fire(error);
1826
}
1927

2028
notifyWebSocketChanged(message: number): void {
2129
this.onMessageEmitter.fire(message);
2230
}
31+
32+
notifyBaudRateChanged(message: MonitorConfig.BaudRate): void {
33+
this.onBaudEmitter.fire(message);
34+
}
35+
36+
notifyLineEndingChanged(message: MonitorModel.EOL): void {
37+
this.onEolEmitter.fire(message);
38+
}
2339
}

Diff for: arduino-ide-extension/src/browser/monitor/monitor-widget.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class MonitorWidget extends ReactWidget {
6969
this.toDispose.push(
7070
this.monitorConnection.onConnectionChanged(() => this.clearConsole())
7171
);
72+
this.toDispose.push(this.monitorModel.onChange(() => this.update()));
7273
}
7374

7475
clearConsole(): void {
@@ -183,7 +184,7 @@ export class MonitorWidget extends ReactWidget {
183184
<ArduinoSelect
184185
maxMenuHeight={this.widgetHeight - 40}
185186
options={lineEndings}
186-
defaultValue={lineEnding}
187+
value={lineEnding}
187188
onChange={this.onChangeLineEnding}
188189
/>
189190
</div>
@@ -192,7 +193,7 @@ export class MonitorWidget extends ReactWidget {
192193
className="select"
193194
maxMenuHeight={this.widgetHeight - 40}
194195
options={baudRates}
195-
defaultValue={baudRate}
196+
value={baudRate}
196197
onChange={this.onChangeBaudRate}
197198
/>
198199
</div>

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

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
22
import { Board, Port } from './boards-service';
33
import { Event } from '@theia/core/lib/common/event';
44
import { SerialPlotter } from '../../browser/plotter/protocol';
5+
import { MonitorModel } from '../../browser/monitor/monitor-model';
56

67
export interface Status {}
78
export type OK = Status;
@@ -58,8 +59,12 @@ export const MonitorServiceClient = Symbol('MonitorServiceClient');
5859
export interface MonitorServiceClient {
5960
onError: Event<MonitorError>;
6061
onWebSocketChanged: Event<number>;
62+
onLineEndingChanged: Event<MonitorModel.EOL>;
63+
onBaudRateChanged: Event<MonitorConfig.BaudRate>;
6164
notifyError(event: MonitorError): void;
6265
notifyWebSocketChanged(message: number): void;
66+
notifyLineEndingChanged(message: MonitorModel.EOL): void;
67+
notifyBaudRateChanged(message: MonitorConfig.BaudRate): void;
6368
}
6469

6570
export interface MonitorError {

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

+4
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ export class MonitorServiceImpl implements MonitorService {
158158
break;
159159

160160
case SerialPlotter.Protocol.Command.PLOTTER_SET_BAUDRATE:
161+
this.client?.notifyBaudRateChanged(
162+
parseInt(message.data, 10) as MonitorConfig.BaudRate
163+
);
161164
break;
162165

163166
case SerialPlotter.Protocol.Command.PLOTTER_SET_LINE_ENDING:
167+
this.client?.notifyLineEndingChanged(message.data);
164168
break;
165169

166170
default:

0 commit comments

Comments
 (0)