Skip to content

Commit dac9c64

Browse files
committed
Preserve baud rate and line ending; Use google protobuf Struct type now for setting configs
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent 7f33b62 commit dac9c64

File tree

5 files changed

+34
-1645
lines changed

5 files changed

+34
-1645
lines changed

arduino-ide-extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@types/ps-tree": "^1.1.0",
2525
"@types/which": "^1.3.1",
2626
"@types/react-select": "^3.0.0",
27+
"@types/google-protobuf": "^3.7.1",
2728
"css-element-queries": "^1.2.0",
2829
"react-select": "^3.0.4",
2930
"p-queue": "^5.0.0",

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Emitter } from "@theia/core";
44
export namespace MonitorModel {
55
export interface Data {
66
autoscroll: boolean,
7-
timestamp: boolean
7+
timestamp: boolean,
8+
baudRate: number,
9+
lineEnding: string
810
}
911
}
1012

@@ -17,6 +19,8 @@ export class MonitorModel {
1719

1820
protected _autoscroll: boolean = true;
1921
protected _timestamp: boolean = false;
22+
baudRate: number;
23+
lineEnding: string = '\n';
2024

2125
get autoscroll(): boolean {
2226
return this._autoscroll;
@@ -39,12 +43,16 @@ export class MonitorModel {
3943
restore(model: MonitorModel.Data) {
4044
this._autoscroll = model.autoscroll;
4145
this._timestamp = model.timestamp;
46+
this.baudRate = model.baudRate;
47+
this.lineEnding = model.lineEnding;
4248
}
4349

4450
store(): MonitorModel.Data {
4551
return {
4652
autoscroll: this._autoscroll,
47-
timestamp: this._timestamp
53+
timestamp: this._timestamp,
54+
baudRate: this.baudRate,
55+
lineEnding: this.lineEnding
4856
}
4957
}
5058
}

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

+15-10
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
113113

114114
protected lines: string[];
115115
protected tempData: string;
116-
protected baudRate: number;
117-
protected _lineEnding: string;
118116

119117
protected widgetHeight: number;
120118

@@ -135,7 +133,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
135133

136134
this.lines = [];
137135
this.tempData = '';
138-
this._lineEnding = '\n';
139136

140137
this.scrollOptions = undefined;
141138

@@ -221,7 +218,7 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
221218
}
222219

223220
protected async getConnectionConfig(): Promise<ConnectionConfig | undefined> {
224-
const baudRate = this.baudRate;
221+
const baudRate = this.model.baudRate;
225222
const { boardsConfig } = this.boardsServiceClient;
226223
const { selectedBoard, selectedPort } = boardsConfig;
227224
if (!selectedBoard) {
@@ -276,15 +273,17 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
276273
protected render(): React.ReactNode {
277274
const le = this.getLineEndings();
278275
const br = this.getBaudRates();
276+
const leVal = this.model.lineEnding && le.find(val => val.value === this.model.lineEnding);
277+
const brVal = this.model.baudRate && br.find(val => val.value === this.model.baudRate);
279278
return <React.Fragment>
280279
<div className='serial-monitor-container'>
281280
<div className='head'>
282281
<div className='send'>
283282
<SerialMonitorSendField onSend={this.onSend} />
284283
</div>
285284
<div className='config'>
286-
{this.renderSelectField('arduino-serial-monitor-line-endings', le, le[1], this.onChangeLineEnding)}
287-
{this.renderSelectField('arduino-serial-monitor-baud-rates', br, br[4], this.onChangeBaudRate)}
285+
{this.renderSelectField('arduino-serial-monitor-line-endings', le, leVal || le[1], this.onChangeLineEnding)}
286+
{this.renderSelectField('arduino-serial-monitor-baud-rates', br, brVal || br[4], this.onChangeBaudRate)}
288287
</div>
289288
</div>
290289
<div id='serial-monitor-output-container'>
@@ -298,16 +297,22 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
298297
protected async doSend(value: string) {
299298
const { connectionId } = this.connection;
300299
if (connectionId) {
301-
this.monitorService.send(connectionId, value + this._lineEnding);
300+
this.monitorService.send(connectionId, value + this.model.lineEnding);
302301
}
303302
}
304303

305304
protected readonly onChangeLineEnding = (le: SelectOption) => {
306-
this._lineEnding = typeof le.value === 'string' ? le.value : '\n';
305+
this.model.lineEnding = typeof le.value === 'string' ? le.value : '\n';
307306
}
308307

309-
protected readonly onChangeBaudRate = (br: SelectOption) => {
310-
this.baudRate = typeof br.value === 'number' ? br.value : 9600;
308+
protected readonly onChangeBaudRate = async (br: SelectOption) => {
309+
await this.connection.disconnect();
310+
this.model.baudRate = typeof br.value === 'number' ? br.value : 9600;
311+
this.clear();
312+
const config = await this.getConnectionConfig();
313+
if (config) {
314+
await this.connection.connect(config);
315+
}
311316
}
312317

313318
protected renderSelectField(id: string, options: OptionsType<SelectOption>, defaultVal: SelectOption, onChange: (v: SelectOption) => void): React.ReactNode {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ILogger, Disposable, DisposableCollection } from '@theia/core';
66
import { MonitorService, MonitorServiceClient, ConnectionConfig, ConnectionType } from '../../common/protocol/monitor-service';
77
import { StreamingOpenReq, StreamingOpenResp, MonitorConfig } from '../cli-protocol/monitor/monitor_pb';
88
import { MonitorClientProvider } from './monitor-client-provider';
9+
import * as google_protobuf_struct_pb from "google-protobuf/google/protobuf/struct_pb";
910

1011
export interface MonitorDuplex {
1112
readonly toDispose: Disposable;
@@ -98,7 +99,8 @@ export class MonitorServiceImpl implements MonitorService {
9899
monitorConfig.setType(this.mapType(type));
99100
monitorConfig.setTarget(port);
100101
if (config.baudRate !== undefined) {
101-
monitorConfig.setAdditionalconfig({ 'BaudRate': config.baudRate });
102+
const obj = google_protobuf_struct_pb.Struct.fromJavaScript({ 'BaudRate': config.baudRate });
103+
monitorConfig.setAdditionalconfig(obj);
102104
}
103105
req.setMonitorconfig(monitorConfig);
104106

0 commit comments

Comments
 (0)