11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
3- import * as constants from "../common/constants" ;
4- import { getSerialMonitorApi , LineEnding , Parity , Port , SerialMonitorApi , StopBits , Version } from "@microsoft/vscode-serial-monitor-api" ;
3+ import { getSerialMonitorApi , LineEnding , Parity , Port , SerialMonitorApi , StopBits , Version } from "@microsoft/vscode-serial-monitor-api" ;
54import * as vscode from "vscode" ;
6- import { SerialPortCtrl } from "./serialportctrl " ;
5+ import * as constants from "../common/constants " ;
76import { DeviceContext } from "../deviceContext" ;
7+ import { SerialPortCtrl } from "./serialportctrl" ;
88
99export interface ISerialPortDetail {
1010 port : string ;
@@ -15,6 +15,8 @@ export interface ISerialPortDetail {
1515}
1616
1717export class SerialMonitor implements vscode . Disposable {
18+ public static DEFAULT_TIMESTAMP_FORMAT : string = "" ;
19+
1820 public static listBaudRates ( ) : number [ ] {
1921 return [ 300 , 1200 , 2400 , 4800 , 9600 , 19200 , 38400 , 57600 , 74880 , 115200 , 230400 , 250000 , 500000 , 1000000 , 2000000 ] ;
2022 }
@@ -26,8 +28,6 @@ export class SerialMonitor implements vscode.Disposable {
2628 return SerialMonitor . _serialMonitor ;
2729 }
2830
29- public static DEFAULT_TIMESTAMP_FORMAT : string = "" ;
30-
3131 private static _serialMonitor : SerialMonitor = null ;
3232
3333 private serialMonitorApi : SerialMonitorApi | undefined ;
@@ -42,7 +42,7 @@ export class SerialMonitor implements vscode.Disposable {
4242
4343 public async initialize ( extensionContext : vscode . ExtensionContext ) {
4444 this . extensionContext = extensionContext ;
45-
45+
4646 this . portsStatusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , constants . statusBarPriority . PORT ) ;
4747 this . portsStatusBar . command = "arduino.selectSerialPort" ;
4848 this . portsStatusBar . tooltip = "Select Serial Port" ;
@@ -67,7 +67,7 @@ export class SerialMonitor implements vscode.Disposable {
6767 dc . onChangePort ( ( ) => {
6868 this . updatePortListStatus ( ) ;
6969 } ) ;
70-
70+
7171 this . serialMonitorApi = await getSerialMonitorApi ( Version . latest , extensionContext ) ;
7272 }
7373
@@ -100,34 +100,6 @@ export class SerialMonitor implements vscode.Disposable {
100100 return undefined ;
101101 }
102102
103- private updatePortListStatus ( port ?: string ) {
104- const dc = DeviceContext . getInstance ( ) ;
105- if ( port ) {
106- dc . port = port ;
107- }
108- this . currentPort = dc . port ;
109-
110- if ( dc . port ) {
111- this . portsStatusBar . text = dc . port ;
112- } else {
113- this . portsStatusBar . text = "<Select Serial Port>" ;
114- }
115- }
116-
117- private updatePortStatus ( isOpened : boolean ) {
118- if ( isOpened ) {
119- this . openPortStatusBar . command = "arduino.closeSerialMonitor" ;
120- this . openPortStatusBar . text = `$(x)` ;
121- this . openPortStatusBar . tooltip = "Close Serial Monitor" ;
122- this . timestampFormatStatusBar . show ( ) ;
123- } else {
124- this . openPortStatusBar . command = "arduino.openSerialMonitor" ;
125- this . openPortStatusBar . text = `$(plug)` ;
126- this . openPortStatusBar . tooltip = "Open Serial Monitor" ;
127- this . timestampFormatStatusBar . hide ( ) ;
128- }
129- }
130-
131103 public async changeTimestampFormat ( ) : Promise < void > {
132104 await vscode . commands . executeCommand ( "workbench.action.openSettings" , "vscode-serial-monitor.timestampFormat" ) ;
133105 }
@@ -196,4 +168,32 @@ export class SerialMonitor implements vscode.Disposable {
196168 public dispose ( ) {
197169 this . serialMonitorApi . dispose ( ) ;
198170 }
171+
172+ private updatePortListStatus ( port ?: string ) {
173+ const dc = DeviceContext . getInstance ( ) ;
174+ if ( port ) {
175+ dc . port = port ;
176+ }
177+ this . currentPort = dc . port ;
178+
179+ if ( dc . port ) {
180+ this . portsStatusBar . text = dc . port ;
181+ } else {
182+ this . portsStatusBar . text = "<Select Serial Port>" ;
183+ }
184+ }
185+
186+ private updatePortStatus ( isOpened : boolean ) {
187+ if ( isOpened ) {
188+ this . openPortStatusBar . command = "arduino.closeSerialMonitor" ;
189+ this . openPortStatusBar . text = `$(x)` ;
190+ this . openPortStatusBar . tooltip = "Close Serial Monitor" ;
191+ this . timestampFormatStatusBar . show ( ) ;
192+ } else {
193+ this . openPortStatusBar . command = "arduino.openSerialMonitor" ;
194+ this . openPortStatusBar . text = `$(plug)` ;
195+ this . openPortStatusBar . tooltip = "Open Serial Monitor" ;
196+ this . timestampFormatStatusBar . hide ( ) ;
197+ }
198+ }
199199}
0 commit comments