Move from polling to worker thread #3

Merged
probablycorey merged 7 commits from worker-test into main 2025-11-19 21:21:05 +00:00
2 changed files with 3 additions and 50 deletions
Showing only changes of commit 4ff9508933 - Show all commits

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 })
using ringer = gpio.output(17)
using inputs = gpio.inputGroup({
hook: { pin: 27, debounce: 50 },
rotaryInUse: { pin: 22, debounce: 50 },
rotaryNumber: { pin: 23, debounce: 10 },
hook: { pin: 27, debounce: 3 },
rotaryInUse: { pin: 22, debounce: 3 },
rotaryNumber: { pin: 23, debounce: 3 },
})
export const startPhone = async (agentId: string, apiKey: string) => {