Skip to content

Commit 74dd9da

Browse files
committed
sync EoL and baudRates
1 parent bf5cfd1 commit 74dd9da

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
@@ -86,6 +86,17 @@ export class SerialConnectionManager {
8686
this.monitorServiceClient.onWebSocketChanged(
8787
this.handleWebSocketChanged.bind(this)
8888
);
89+
this.monitorServiceClient.onBaudRateChanged((baudRate) => {
90+
if (this.monitorModel.baudRate !== baudRate) {
91+
this.monitorModel.baudRate = baudRate;
92+
}
93+
});
94+
this.monitorServiceClient.onLineEndingChanged((lineending) => {
95+
if (this.monitorModel.lineEnding !== lineending) {
96+
this.monitorModel.lineEnding = lineending;
97+
}
98+
});
99+
89100
this.monitorServiceClient.onError(this.handleError.bind(this));
90101
this.boardsServiceProvider.onBoardsConfigChanged(
91102
this.handleBoardConfigChange.bind(this)
@@ -99,6 +110,16 @@ export class SerialConnectionManager {
99110
const { boardsConfig } = this.boardsServiceProvider;
100111
this.handleBoardConfigChange(boardsConfig);
101112
}
113+
114+
// update the current values in the backend and propagate to websocket clients
115+
this.monitorService.updateWsConfigParam({
116+
...(property === 'baudRate' && {
117+
currentBaudrate: this.monitorModel.baudRate,
118+
}),
119+
...(property === 'lineEnding' && {
120+
currentLineEnding: this.monitorModel.lineEnding,
121+
}),
122+
});
102123
});
103124

104125
this.themeService.onDidColorThemeChange((theme) => {
@@ -433,10 +454,6 @@ export class SerialConnectionManager {
433454
if (ports.some((port) => Port.equals(port, boardsConfig.selectedPort))) {
434455
const { selectedBoard: board, selectedPort: port } = boardsConfig;
435456
const { baudRate } = this.monitorModel;
436-
// update the baudrate on the config
437-
this.monitorService.updateWsConfigParam({
438-
currentBaudrate: baudRate,
439-
});
440457
const newConfig: MonitorConfig = { board, port, baudRate };
441458
this.setConfig(newConfig);
442459
}

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
@@ -64,6 +64,7 @@ export class MonitorWidget extends ReactWidget {
6464
this.toDispose.push(
6565
this.monitorConnection.onConnectionChanged(() => this.clearConsole())
6666
);
67+
this.toDispose.push(this.monitorModel.onChange(() => this.update()));
6768
}
6869

6970
clearConsole(): void {
@@ -172,7 +173,7 @@ export class MonitorWidget extends ReactWidget {
172173
<ArduinoSelect
173174
maxMenuHeight={this.widgetHeight - 40}
174175
options={lineEndings}
175-
defaultValue={lineEnding}
176+
value={lineEnding}
176177
onChange={this.onChangeLineEnding}
177178
/>
178179
</div>
@@ -181,7 +182,7 @@ export class MonitorWidget extends ReactWidget {
181182
className="select"
182183
maxMenuHeight={this.widgetHeight - 40}
183184
options={baudRates}
184-
defaultValue={baudRate}
185+
value={baudRate}
185186
onChange={this.onChangeBaudRate}
186187
/>
187188
</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)