@@ -113,8 +113,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
113
113
114
114
protected lines : string [ ] ;
115
115
protected tempData : string ;
116
- protected baudRate : number ;
117
- protected _lineEnding : string ;
118
116
119
117
protected widgetHeight : number ;
120
118
@@ -135,7 +133,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
135
133
136
134
this . lines = [ ] ;
137
135
this . tempData = '' ;
138
- this . _lineEnding = '\n' ;
139
136
140
137
this . scrollOptions = undefined ;
141
138
@@ -221,7 +218,7 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
221
218
}
222
219
223
220
protected async getConnectionConfig ( ) : Promise < ConnectionConfig | undefined > {
224
- const baudRate = this . baudRate ;
221
+ const baudRate = this . model . baudRate ;
225
222
const { boardsConfig } = this . boardsServiceClient ;
226
223
const { selectedBoard, selectedPort } = boardsConfig ;
227
224
if ( ! selectedBoard ) {
@@ -276,15 +273,17 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
276
273
protected render ( ) : React . ReactNode {
277
274
const le = this . getLineEndings ( ) ;
278
275
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 ) ;
279
278
return < React . Fragment >
280
279
< div className = 'serial-monitor-container' >
281
280
< div className = 'head' >
282
281
< div className = 'send' >
283
282
< SerialMonitorSendField onSend = { this . onSend } />
284
283
</ div >
285
284
< 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 ) }
288
287
</ div >
289
288
</ div >
290
289
< div id = 'serial-monitor-output-container' >
@@ -298,16 +297,22 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
298
297
protected async doSend ( value : string ) {
299
298
const { connectionId } = this . connection ;
300
299
if ( connectionId ) {
301
- this . monitorService . send ( connectionId , value + this . _lineEnding ) ;
300
+ this . monitorService . send ( connectionId , value + this . model . lineEnding ) ;
302
301
}
303
302
}
304
303
305
304
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' ;
307
306
}
308
307
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
+ }
311
316
}
312
317
313
318
protected renderSelectField ( id : string , options : OptionsType < SelectOption > , defaultVal : SelectOption , onChange : ( v : SelectOption ) => void ) : React . ReactNode {
0 commit comments