-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from REVrobotics/refactor/pass-hubs
Pass hubs in to commands
- Loading branch information
Showing
4 changed files
with
84 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,33 @@ | ||
import { openConnectedExpansionHubs } from "@rev-robotics/expansion-hub"; | ||
import { ExpansionHub, openConnectedExpansionHubs } from "@rev-robotics/expansion-hub"; | ||
|
||
export async function analog(channel: number, continuous: boolean) { | ||
const hubs = await openConnectedExpansionHubs(); | ||
|
||
if (continuous) { | ||
while (true) { | ||
let value = await hubs[0].getAnalogInput(channel); | ||
console.log(`ADC: ${value} mV`); | ||
} | ||
} else { | ||
let value = await hubs[0].getAnalogInput(channel); | ||
export async function analog(hub: ExpansionHub, channel: number, continuous: boolean) { | ||
while (true) { | ||
let value = await hub.getAnalogInput(channel); | ||
console.log(`ADC: ${value} mV`); | ||
hubs.forEach((hub) => { | ||
hub.close(); | ||
}); | ||
if (!continuous) break; | ||
} | ||
} | ||
|
||
export async function temperature(continuous: boolean) { | ||
const hubs = await openConnectedExpansionHubs(); | ||
|
||
if (continuous) { | ||
while (true) { | ||
let value = await hubs[0].getTemperature(); | ||
console.log(`Temperature: ${value} C`); | ||
} | ||
} else { | ||
let value = await hubs[0].getTemperature(); | ||
export async function temperature(hub: ExpansionHub, continuous: boolean) { | ||
while (true) { | ||
let value = await hub.getTemperature(); | ||
console.log(`Temperature: ${value} C`); | ||
hubs.forEach((hub) => { | ||
hub.close(); | ||
}); | ||
if (!continuous) break; | ||
} | ||
} | ||
|
||
export async function battery(continuous: boolean) { | ||
const hubs = await openConnectedExpansionHubs(); | ||
|
||
if (continuous) { | ||
while (true) { | ||
let value = await hubs[0].getBatteryVoltage(); | ||
console.log(`Battery: ${value} mV`); | ||
} | ||
} else { | ||
let value = await hubs[0].getBatteryVoltage(); | ||
console.log(`Battery: ${value} mV`); | ||
hubs.forEach((hub) => { | ||
hub.close(); | ||
}); | ||
export async function battery(hub: ExpansionHub, continuous: boolean) { | ||
while (true) { | ||
let value = await hub.getTemperature(); | ||
console.log(`Temperature: ${value} C`); | ||
if (!continuous) break; | ||
} | ||
} | ||
|
||
export async function voltageRail(continuous: boolean) { | ||
const hubs = await openConnectedExpansionHubs(); | ||
|
||
if (continuous) { | ||
while (true) { | ||
let value = await hubs[0].get5VBusVoltage(); | ||
console.log(`5V rail: ${value} mV`); | ||
} | ||
} else { | ||
let value = await hubs[0].get5VBusVoltage(); | ||
export async function voltageRail(hub: ExpansionHub, continuous: boolean) { | ||
while (true) { | ||
let value = await hub.get5VBusVoltage(); | ||
console.log(`5V rail: ${value} mV`); | ||
hubs.forEach((hub) => { | ||
hub.close(); | ||
}); | ||
if (!continuous) break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { openConnectedExpansionHubs } from "@rev-robotics/expansion-hub"; | ||
import { ExpansionHub } from "@rev-robotics/expansion-hub"; | ||
|
||
export async function runServo(channel: number, pulseWidth: number, framePeriod: number) { | ||
const hubs = await openConnectedExpansionHubs(); | ||
|
||
await hubs[0].setServoConfiguration(channel, framePeriod); | ||
await hubs[0].setServoPulseWidth(channel, pulseWidth); | ||
await hubs[0].setServoEnable(channel, true); | ||
export async function runServo( | ||
hub: ExpansionHub, | ||
channel: number, | ||
pulseWidth: number, | ||
framePeriod: number, | ||
) { | ||
await hub.setServoConfiguration(channel, framePeriod); | ||
await hub.setServoPulseWidth(channel, pulseWidth); | ||
await hub.setServoEnable(channel, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters