-
Notifications
You must be signed in to change notification settings - Fork 236
Pause UsbDetector during uploading #372
Changes from 3 commits
d1f8fae
9eb2082
a813904
398a8f3
b52a0b2
610ee36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,22 @@ import { SerialMonitor } from "./serialMonitor"; | |
|
||
export class UsbDetector { | ||
|
||
public static extensionRoot: string; | ||
|
||
public static getInstance(): UsbDetector { | ||
if (!UsbDetector._instance) { | ||
UsbDetector._instance = new UsbDetector(UsbDetector.extensionRoot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should check the extensionRoot value carefully since there is no any explicit of the sequence of the calling order There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what behavior should be if the assumption is violated. Can you give me some advice? |
||
} | ||
return UsbDetector._instance; | ||
} | ||
|
||
private static _instance: UsbDetector; | ||
|
||
private _usbDetector; | ||
|
||
private _boardDescriptors = null; | ||
|
||
constructor( | ||
private constructor( | ||
private _extensionRoot: string) { | ||
} | ||
|
||
|
@@ -106,6 +117,20 @@ export class UsbDetector { | |
} | ||
} | ||
|
||
public pauseListening() { | ||
if (this._usbDetector) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we resume the existing stopListening/startListening? The two new APIs seems duplicate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, it is possible but the startListening() method needs to be modified. The current startListening() just sets the add event listener and does not explicitly start listening. It works previously just because the detector is default to be listening after initialization. startListening() cannot switch back the status of detector correctly yet. My concern is that it may be unnecessary to set the add event listener again and again. |
||
this._usbDetector.stopMonitoring(); | ||
} | ||
} | ||
|
||
public resumeListening() { | ||
if (this._usbDetector) { | ||
this._usbDetector.startMonitoring(); | ||
} else { | ||
this.startListening(); | ||
} | ||
} | ||
|
||
private switchBoard(bd: IBoard, vid: string, pid: string) { | ||
ArduinoContext.boardManager.doChangeBoardType(bd); | ||
const monitor = SerialMonitor.getInstance(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add Initialize(extensionRoot : string) method to UsbDector instance for passing value but not use the module to pass object value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good advice.