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:
jbicker
2019-08-19 11:39:40 +02:00
parent 7f33b62e0b
commit dac9c6437e
5 changed files with 34 additions and 1645 deletions

View File

@@ -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
}
}
}

View File

@@ -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 {