This commit is contained in:
Corey Johnson 2025-11-19 10:47:57 -08:00
parent 843f3680e1
commit 4ff9508933
2 changed files with 3 additions and 50 deletions

View File

@ -1,47 +0,0 @@
import { GPIO } from "./pins"
console.log(`kill -9 ${process.pid}`)
const gpio = new GPIO({ resetOnClose: true })
// // Blink an LED
using led = gpio.output(21)
// Read a button
using inputs = gpio.inputGroup({
button: { pin: 20, pull: "up", debounce: 10 },
switch: { pin: 16, pull: "up", debounce: 10 }
})
led.value = inputs.pins.button.value
const iteratorEvents = new Promise(async (resolve) => {
for await (const event of inputs.events()) {
if (event.pin === "button") {
console.log(`🌭`, event.value)
led.value = event.value
}
}
})
const switchEvent = new Promise<void>(async (resolve) => {
await inputs.pins.switch.waitForValue(0)
console.log("Switch pressed!")
resolve()
})
process.on("SIGINT", () => {
inputs.close()
led.close()
process.exit(0)
})
process.on("SIGTERM", () => {
inputs.close()
process.exit(0)
})
await Promise.race([iteratorEvents, switchEvent])
console.log(`👋 Goodbye!`)

View File

@ -25,9 +25,9 @@ type PhoneContext = {
const gpio = new GPIO({ resetOnClose: true }) const gpio = new GPIO({ resetOnClose: true })
using ringer = gpio.output(17) using ringer = gpio.output(17)
using inputs = gpio.inputGroup({ using inputs = gpio.inputGroup({
hook: { pin: 27, debounce: 50 }, hook: { pin: 27, debounce: 3 },
rotaryInUse: { pin: 22, debounce: 50 }, rotaryInUse: { pin: 22, debounce: 3 },
rotaryNumber: { pin: 23, debounce: 10 }, rotaryNumber: { pin: 23, debounce: 3 },
}) })
export const startPhone = async (agentId: string, apiKey: string) => { export const startPhone = async (agentId: string, apiKey: string) => {