uci-i2c-bus/examples/ipc-scan.mjs

31 lines
658 B
JavaScript

/*
* i2c bus unix socket and client in one for demo
*
*/
import Bus from '../src/bus-packet'
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
;
(async () => {
let i2cbus = new Bus({id:'i2c-bus', sockets:'us,uc'})
i2cbus.reply = function (packet) {
console.log('==== response from i2cbus =>',packet.bus.response)
}
await i2cbus.init()
console.log('=============sending============')
let packet = {cmd:'rw', bus:{func:'scan'} }
console.dir(packet)
await i2cbus.send(packet)
await delay(1000)
process.kill(process.pid, 'SIGTERM')
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})