Skip to content

Commit

Permalink
add missing command implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
LandryNorris committed Aug 16, 2023
1 parent 7b5f66f commit c2d5718
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/sample/src/command/set-hub-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ControlHub } from "@rev-robotics/rev-hub-core";

export async function setHubAddress(hub: ControlHub, address: number) {
hub.on("addressChanged", (oldAddress, newAddress) => {
console.log(`Address changed from ${oldAddress} -> ${newAddress}`);
});
await hub.setNewModuleAddress(address);
}
15 changes: 15 additions & 0 deletions packages/sample/src/command/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ControlHub, ModuleStatus } from "@rev-robotics/rev-hub-core";

export async function status(hub: ControlHub) {
hub.on("statusChanged", (status: ModuleStatus) => {
console.log(`Status Changed:\n${JSON.stringify(status)}`);
});

hub.on("addressChanged", (oldAddress, newAddress) => {
console.log(`Address Changed: ${oldAddress} -> ${newAddress}`);
});

hub.on("sessionEnded", () => {
console.log("Session ended");
});
}
4 changes: 2 additions & 2 deletions packages/sample/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import { distance } from "./command/distance.js";
import { sendFailSafe } from "./command/failsafe.js";
import { queryInterface } from "./command/query.js";
import { openUsbControlHubsAndChildren } from "./open-control-hub.js";
import { status } from "../dist/command/status.js";
import { setHubAddress } from "../dist/command/set-hub-address.js";
import { status } from "./command/status.js";
import { setHubAddress } from "./command/set-hub-address.js";

function runOnSigint(block: () => void) {
process.on("SIGINT", () => {
Expand Down

0 comments on commit c2d5718

Please sign in to comment.