36 lines
802 B
JavaScript
36 lines
802 B
JavaScript
|
|
/*
|
|
* i2c bus unix socket and client in one for demo
|
|
*
|
|
*/
|
|
|
|
import Base from '@uci/base'
|
|
|
|
const PATH = 'i2c-bus'
|
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
;
|
|
(async () => {
|
|
|
|
let scanner = new Base({id:'pipe-i2c-client', sockets:'uc#c>n', uc:{path:PATH}})
|
|
|
|
scanner.reply = function (packet) {
|
|
let addresses = packet.response.map(device => {
|
|
return device.toString(16)})
|
|
// console.log(packet)
|
|
console.log('==== device hex addreses on i2cbus ===\n',addresses)
|
|
}
|
|
await scanner.init()
|
|
console.log('=============sending============')
|
|
let packet = {cmd:'scan'}
|
|
console.dir(packet)
|
|
await scanner.send(packet)
|
|
|
|
await delay(3000)
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
})
|