Skip to content

Commit a4a6102

Browse files
committed
Centralize NanoXRP flag on Connection
Introduce a private _isNanoXRP flag with isNanoXRP() getter and setNanoXRP() setter on the base Connection class. Remove the USBConnection-specific isNanoXRP() override.
1 parent 00d34eb commit a4a6102

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/connections/connection.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ abstract class Connection {
6767
abstract disconnect(): Promise<void>;
6868
abstract isConnected(): boolean;
6969

70-
isNanoXRP(): boolean { return false; }
70+
private _isNanoXRP: boolean = false;
71+
72+
isNanoXRP(): boolean { return this._isNanoXRP; }
73+
74+
setNanoXRP(val: boolean): void { this._isNanoXRP = val; }
7175

7276
/**
7377
* HandleEsc

src/connections/usbconnection.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,6 @@ export class USBConnection extends Connection {
263263
return this.connectionStates === ConnectionState.Connected;
264264
}
265265

266-
public isNanoXRP(): boolean {
267-
if (this.port) {
268-
const info = this.port.getInfo();
269-
return info.usbProductId === this.USB_PRODUCT_ID_NANOXRP &&
270-
info.usbVendorId === this.USB_VENDOR_ID_NANOXRP;
271-
}
272-
return false;
273-
}
274-
275266
/**
276267
* connection - creates an async connection and return result via promise
277268
*/

src/managers/commandstoxrpmgr.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ export class CommandToXRPMgr {
227227
this.PROCESSOR = 2350;
228228
} else if (hiddenLines[1].includes('RP2040')) {
229229
this.PROCESSOR = 2040;
230-
this.is_NanoXRP = this.connection?.isNanoXRP() ?? false;
230+
this.is_NanoXRP = hiddenLines[1].includes('NanoXRP');
231+
this.connection?.setNanoXRP(this.is_NanoXRP);
231232
}
232233
}
233234
if(hiddenLines[1].includes('XRP')){ //is this an XRP version of microPython?
@@ -253,7 +254,8 @@ export class CommandToXRPMgr {
253254
this.lastRun = undefined;
254255
this.HAS_MICROPYTHON = true; // this is set after connection is successful
255256
this.is_NanoXRP = false;
256-
257+
this.connection?.setNanoXRP(false);
258+
257259
//get version information from the XRP
258260
const info = await this.getVersionInfo();
259261

0 commit comments

Comments
 (0)