mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-13 06:16:33 +00:00
Preserve baud rate and line ending; Use google protobuf Struct type now for setting configs
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
7f33b62e0b
commit
dac9c6437e
@ -24,6 +24,7 @@
|
||||
"@types/ps-tree": "^1.1.0",
|
||||
"@types/which": "^1.3.1",
|
||||
"@types/react-select": "^3.0.0",
|
||||
"@types/google-protobuf": "^3.7.1",
|
||||
"css-element-queries": "^1.2.0",
|
||||
"react-select": "^3.0.4",
|
||||
"p-queue": "^5.0.0",
|
||||
|
@ -4,7 +4,9 @@ import { Emitter } from "@theia/core";
|
||||
export namespace MonitorModel {
|
||||
export interface Data {
|
||||
autoscroll: boolean,
|
||||
timestamp: boolean
|
||||
timestamp: boolean,
|
||||
baudRate: number,
|
||||
lineEnding: string
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +19,8 @@ export class MonitorModel {
|
||||
|
||||
protected _autoscroll: boolean = true;
|
||||
protected _timestamp: boolean = false;
|
||||
baudRate: number;
|
||||
lineEnding: string = '\n';
|
||||
|
||||
get autoscroll(): boolean {
|
||||
return this._autoscroll;
|
||||
@ -39,12 +43,16 @@ export class MonitorModel {
|
||||
restore(model: MonitorModel.Data) {
|
||||
this._autoscroll = model.autoscroll;
|
||||
this._timestamp = model.timestamp;
|
||||
this.baudRate = model.baudRate;
|
||||
this.lineEnding = model.lineEnding;
|
||||
}
|
||||
|
||||
store(): MonitorModel.Data {
|
||||
return {
|
||||
autoscroll: this._autoscroll,
|
||||
timestamp: this._timestamp
|
||||
timestamp: this._timestamp,
|
||||
baudRate: this.baudRate,
|
||||
lineEnding: this.lineEnding
|
||||
}
|
||||
}
|
||||
}
|
@ -113,8 +113,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
|
||||
protected lines: string[];
|
||||
protected tempData: string;
|
||||
protected baudRate: number;
|
||||
protected _lineEnding: string;
|
||||
|
||||
protected widgetHeight: number;
|
||||
|
||||
@ -135,7 +133,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
|
||||
this.lines = [];
|
||||
this.tempData = '';
|
||||
this._lineEnding = '\n';
|
||||
|
||||
this.scrollOptions = undefined;
|
||||
|
||||
@ -221,7 +218,7 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
}
|
||||
|
||||
protected async getConnectionConfig(): Promise<ConnectionConfig | undefined> {
|
||||
const baudRate = this.baudRate;
|
||||
const baudRate = this.model.baudRate;
|
||||
const { boardsConfig } = this.boardsServiceClient;
|
||||
const { selectedBoard, selectedPort } = boardsConfig;
|
||||
if (!selectedBoard) {
|
||||
@ -276,6 +273,8 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
protected render(): React.ReactNode {
|
||||
const le = this.getLineEndings();
|
||||
const br = this.getBaudRates();
|
||||
const leVal = this.model.lineEnding && le.find(val => val.value === this.model.lineEnding);
|
||||
const brVal = this.model.baudRate && br.find(val => val.value === this.model.baudRate);
|
||||
return <React.Fragment>
|
||||
<div className='serial-monitor-container'>
|
||||
<div className='head'>
|
||||
@ -283,8 +282,8 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
<SerialMonitorSendField onSend={this.onSend} />
|
||||
</div>
|
||||
<div className='config'>
|
||||
{this.renderSelectField('arduino-serial-monitor-line-endings', le, le[1], this.onChangeLineEnding)}
|
||||
{this.renderSelectField('arduino-serial-monitor-baud-rates', br, br[4], this.onChangeBaudRate)}
|
||||
{this.renderSelectField('arduino-serial-monitor-line-endings', le, leVal || le[1], this.onChangeLineEnding)}
|
||||
{this.renderSelectField('arduino-serial-monitor-baud-rates', br, brVal || br[4], this.onChangeBaudRate)}
|
||||
</div>
|
||||
</div>
|
||||
<div id='serial-monitor-output-container'>
|
||||
@ -298,16 +297,22 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
|
||||
protected async doSend(value: string) {
|
||||
const { connectionId } = this.connection;
|
||||
if (connectionId) {
|
||||
this.monitorService.send(connectionId, value + this._lineEnding);
|
||||
this.monitorService.send(connectionId, value + this.model.lineEnding);
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly onChangeLineEnding = (le: SelectOption) => {
|
||||
this._lineEnding = typeof le.value === 'string' ? le.value : '\n';
|
||||
this.model.lineEnding = typeof le.value === 'string' ? le.value : '\n';
|
||||
}
|
||||
|
||||
protected readonly onChangeBaudRate = (br: SelectOption) => {
|
||||
this.baudRate = typeof br.value === 'number' ? br.value : 9600;
|
||||
protected readonly onChangeBaudRate = async (br: SelectOption) => {
|
||||
await this.connection.disconnect();
|
||||
this.model.baudRate = typeof br.value === 'number' ? br.value : 9600;
|
||||
this.clear();
|
||||
const config = await this.getConnectionConfig();
|
||||
if (config) {
|
||||
await this.connection.connect(config);
|
||||
}
|
||||
}
|
||||
|
||||
protected renderSelectField(id: string, options: OptionsType<SelectOption>, defaultVal: SelectOption, onChange: (v: SelectOption) => void): React.ReactNode {
|
||||
|
@ -6,6 +6,7 @@ import { ILogger, Disposable, DisposableCollection } from '@theia/core';
|
||||
import { MonitorService, MonitorServiceClient, ConnectionConfig, ConnectionType } from '../../common/protocol/monitor-service';
|
||||
import { StreamingOpenReq, StreamingOpenResp, MonitorConfig } from '../cli-protocol/monitor/monitor_pb';
|
||||
import { MonitorClientProvider } from './monitor-client-provider';
|
||||
import * as google_protobuf_struct_pb from "google-protobuf/google/protobuf/struct_pb";
|
||||
|
||||
export interface MonitorDuplex {
|
||||
readonly toDispose: Disposable;
|
||||
@ -98,7 +99,8 @@ export class MonitorServiceImpl implements MonitorService {
|
||||
monitorConfig.setType(this.mapType(type));
|
||||
monitorConfig.setTarget(port);
|
||||
if (config.baudRate !== undefined) {
|
||||
monitorConfig.setAdditionalconfig({ 'BaudRate': config.baudRate });
|
||||
const obj = google_protobuf_struct_pb.Struct.fromJavaScript({ 'BaudRate': config.baudRate });
|
||||
monitorConfig.setAdditionalconfig(obj);
|
||||
}
|
||||
req.setMonitorconfig(monitorConfig);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user