@@ -5,7 +5,7 @@ import * as vscode from "vscode";
5
5
import * as constants from "../common/constants" ;
6
6
import { DeviceContext } from "../deviceContext" ;
7
7
import * as Logger from "../logger/logger" ;
8
- import { SerialPortCtrl } from "./serialportctrl" ;
8
+ import { SerialPortCtrl , SerialPortEnding } from "./serialportctrl" ;
9
9
10
10
export interface ISerialPortDetail {
11
11
comName : string ;
@@ -20,6 +20,8 @@ export class SerialMonitor implements vscode.Disposable {
20
20
21
21
public static DEFAULT_BAUD_RATE : number = 115200 ;
22
22
23
+ public static DEFAULT_ENDING : SerialPortEnding = SerialPortEnding [ "No line ending" ] ;
24
+
23
25
public static listBaudRates ( ) : number [ ] {
24
26
return [ 300 , 1200 , 2400 , 4800 , 9600 , 19200 , 38400 , 57600 , 74880 , 115200 , 230400 , 250000 ] ;
25
27
}
@@ -43,10 +45,14 @@ export class SerialMonitor implements vscode.Disposable {
43
45
44
46
private _baudRateStatusBar : vscode . StatusBarItem ;
45
47
48
+ private _endingStatusBar : vscode . StatusBarItem ;
49
+
46
50
private _serialPortCtrl : SerialPortCtrl = null ;
47
51
48
52
private _outputChannel : vscode . OutputChannel ;
49
53
54
+ private _ending : SerialPortEnding ;
55
+
50
56
private constructor ( ) {
51
57
const dc = DeviceContext . getInstance ( ) ;
52
58
dc . onDidChange ( ( ) => {
@@ -78,6 +84,12 @@ export class SerialMonitor implements vscode.Disposable {
78
84
this . _baudRateStatusBar . tooltip = "Baud Rate" ;
79
85
this . _baudRateStatusBar . text = SerialMonitor . DEFAULT_BAUD_RATE . toString ( ) ;
80
86
this . updatePortListStatus ( null ) ;
87
+
88
+ this . _endingStatusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , constants . statusBarPriority . ENDING ) ;
89
+ this . _ending = SerialMonitor . DEFAULT_ENDING ;
90
+ this . _endingStatusBar . command = "arduino.changeEnding" ;
91
+ this . _endingStatusBar . tooltip = "Serial Port Line Ending" ;
92
+ this . _endingStatusBar . text = `No line ending` ;
81
93
}
82
94
public get initialized ( ) : boolean {
83
95
return ! ! this . _outputChannel ;
@@ -144,7 +156,7 @@ export class SerialMonitor implements vscode.Disposable {
144
156
return ;
145
157
}
146
158
} else {
147
- this . _serialPortCtrl = new SerialPortCtrl ( this . _currentPort , this . _currentBaudRate , this . _outputChannel ) ;
159
+ this . _serialPortCtrl = new SerialPortCtrl ( this . _currentPort , this . _currentBaudRate , this . _ending , this . _outputChannel ) ;
148
160
}
149
161
150
162
if ( ! this . _serialPortCtrl . currentPort ) {
@@ -195,6 +207,19 @@ export class SerialMonitor implements vscode.Disposable {
195
207
this . _baudRateStatusBar . text = chosen ;
196
208
}
197
209
210
+ public async changeEnding ( ) {
211
+ const chosen : string | undefined = await vscode . window . showQuickPick ( Object . keys ( SerialPortEnding )
212
+ . filter ( ( key ) => {
213
+ return ! isNaN ( Number ( SerialPortEnding [ key ] ) ) ;
214
+ } ) , { placeHolder : "Select serial port ending" } ) ;
215
+ if ( ! chosen ) {
216
+ return ;
217
+ }
218
+ this . _ending = SerialPortEnding [ chosen ] ;
219
+ this . _serialPortCtrl . changeEnding ( this . _ending ) ;
220
+ this . _endingStatusBar . text = chosen ;
221
+ }
222
+
198
223
public async closeSerialMonitor ( port : string , showWarning : boolean = true ) : Promise < boolean > {
199
224
if ( this . _serialPortCtrl ) {
200
225
if ( port && port !== this . _serialPortCtrl . currentPort ) {
@@ -230,11 +255,13 @@ export class SerialMonitor implements vscode.Disposable {
230
255
this . _openPortStatusBar . text = `$(x)` ;
231
256
this . _openPortStatusBar . tooltip = "Close Serial Monitor" ;
232
257
this . _baudRateStatusBar . show ( ) ;
258
+ this . _endingStatusBar . show ( ) ;
233
259
} else {
234
260
this . _openPortStatusBar . command = "arduino.openSerialMonitor" ;
235
261
this . _openPortStatusBar . text = `$(plug)` ;
236
262
this . _openPortStatusBar . tooltip = "Open Serial Monitor" ;
237
263
this . _baudRateStatusBar . hide ( ) ;
264
+ this . _endingStatusBar . hide ( ) ;
238
265
}
239
266
240
267
}
0 commit comments