Skip to content

Commit

Permalink
Remove ParentControlHub, since control hubs will always be parents
Browse files Browse the repository at this point in the history
  • Loading branch information
LandryNorris committed May 30, 2023
1 parent 41ae6a3 commit 27ffa13
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/control-hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@types/node": "^16.18.18",
"@types/semver": "^7.5.0",
"@types/node-forge": "^1.3.2",
"typescript": "^5.0.2"
},
"scripts": {
Expand Down
6 changes: 1 addition & 5 deletions packages/control-hub/src/ControlHub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { ExpansionHub, ParentRevHub } from "@rev-robotics/expansion-hub";

export interface ParentControlHub extends ParentRevHub, ControlHub {
readonly serialNumber: string;
}

export interface ControlHub extends ExpansionHub {}
export interface ControlHub extends ExpansionHub, ParentRevHub {}
2 changes: 1 addition & 1 deletion packages/control-hub/src/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function isControlHub(deviceClient: DeviceClient): Promise<boolean> {
}

async function createWiFiControlHub(): Promise<ControlHub> {
let hub = new ControlHubInternal();
let hub = new ControlHubInternal("Placeholder");

if (!(await hub.isWiFiConnected())) {
throw new Error("Hub is not connected via WiFi");
Expand Down
17 changes: 13 additions & 4 deletions packages/control-hub/src/internal/ControlHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,28 @@ import axios from "axios";
import semver from "semver";
import WebSocket from "isomorphic-ws";
import adb from "@u4/adbkit";
import { ControlHub, ParentControlHub } from "../ControlHub.js";
import { ControlHub } from "../ControlHub.js";

export class ControlHubInternal implements ControlHub {
readonly isOpen: boolean = true;
moduleAddress: number = 0;
responseTimeoutMs: number = 0;
type: RevHubType = RevHubType.ControlHub;
webSocketConnection!: WebSocket;
private readonly serialNumber?: string;
readonly serialNumber: string;
readonly children: ReadonlyArray<RevHub> = [];

keyGenerator = 0;
currentActiveCommands = new Map<
any,
(response: any | undefined, error: any | undefined) => void
>();

constructor(serialNumber?: string) {
constructor(serialNumber: string) {
this.serialNumber = serialNumber;
}

isParent(): this is ParentControlHub {
isParent(): this is ParentRevHub {
return this.serialNumber !== undefined;
}

Expand Down Expand Up @@ -418,4 +419,12 @@ export class ControlHubInternal implements ControlHub {
});
});
}

addChild(hub: RevHub): void {
throw new Error("not implemented");
}

addChildByAddress(moduleAddress: number): Promise<RevHub> {
throw new Error("not implemented");
}
}
6 changes: 1 addition & 5 deletions packages/sample/src/command/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { openConnectedControlHub, openUsbControlHubs } from "@rev-robotics/contr
export async function list() {
let usbControlHubs = await openUsbControlHubs();
for (const hub of usbControlHubs) {
if (hub.isParent()) {
console.log(`USB Control Hub: ${hub.serialNumber} ${hub.moduleAddress}\n\n`);
} else {
console.log(`\tUSB Control Hub: ${hub.moduleAddress}\n\n`);
}
console.log(`USB Control Hub: ${hub.serialNumber} ${hub.moduleAddress}\n\n`);
hub.close();
}

Expand Down

0 comments on commit 27ffa13

Please sign in to comment.