2018-03-04 15:13:55 -08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
import { MCP230XXi } from '../src'
|
|
|
|
import { MCP230XX } from '../src'
|
2018-07-31 10:29:11 -07:00
|
|
|
import Base from '@uci/base'
|
2018-03-04 15:13:55 -08:00
|
|
|
|
2018-07-31 10:29:11 -07:00
|
|
|
const BUS_HOST = 'sbc' // if ihost not given will be the same as host:
|
2018-03-04 15:13:55 -08:00
|
|
|
const BUS_PORT = 1776 // 1776 is default port for i2c-bus module
|
|
|
|
const SW_ADDRESS = 0x25 // 1776 is default port for i2c-bus module
|
|
|
|
const RY_ADDRESS = 0x27 // 1776 is default port for i2c-bus module
|
|
|
|
|
2018-07-31 10:29:11 -07:00
|
|
|
let announce = new Base({id:'switch:announce'})
|
2018-03-04 15:13:55 -08:00
|
|
|
|
2018-07-31 10:29:11 -07:00
|
|
|
let sw17 = new MCP230XXi([9,10],{id:'sw17', chip17:true, host:BUS_HOST, address:SW_ADDRESS+1})
|
|
|
|
// let sw8 = new MCP230XXi([24],{id:'sw8', host:BUS_HOST, address:SW_ADDRESS})
|
|
|
|
// let ry8 = new MCP230XX({id:'ry8', host:BUS_HOST, address:RY_ADDRESS})
|
|
|
|
const reply = { reply: () => {} }
|
|
|
|
// ry8.c = reply;
|
|
|
|
sw17.c=reply
|
|
|
|
// sw8.c= reply
|
2018-03-04 15:13:55 -08:00
|
|
|
|
|
|
|
function iprocess(details) {
|
|
|
|
console.log('--common interrupt processor--')
|
|
|
|
console.log(details)
|
2018-07-31 10:29:11 -07:00
|
|
|
announce.push()
|
|
|
|
// action function can do whatever but best would be to push the details to any attached client (mqtt or some database that then pushes
|
|
|
|
// local_action(details)
|
2018-03-04 15:13:55 -08:00
|
|
|
}
|
|
|
|
|
2018-07-31 10:29:11 -07:00
|
|
|
// just something to do
|
|
|
|
async function local_action (details) {
|
2018-03-04 15:13:55 -08:00
|
|
|
if (details.id === 'sw17') {
|
2018-07-31 10:29:11 -07:00
|
|
|
await ry8.pin.state.toggle({pins:'2,4,6,8'})
|
2018-03-04 15:13:55 -08:00
|
|
|
}
|
|
|
|
if (details.id === 'sw8') {
|
|
|
|
if (details.pin===1) {
|
|
|
|
if (details.state==='off') await ry8.pin.state.off({pins:'all'})
|
|
|
|
else ry8.pin.state.on({pins:'all'})
|
|
|
|
}
|
|
|
|
if (details.pin===8) {
|
|
|
|
if (details.state==='off') await ry8.pin.state.off({pins:'1,3,5,7'})
|
|
|
|
else await ry8.pin.state.on({pins:'1,3,5,7'})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
|
|
|
await sw17.init()
|
|
|
|
sw17.interruptProcessor(iprocess)
|
|
|
|
|
2018-07-31 10:29:11 -07:00
|
|
|
// await sw8.init()
|
|
|
|
// sw8.interruptProcessor(iprocess)
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// await ry8.init()
|
|
|
|
// let packet = {pins:'all', cfg:'output'}
|
|
|
|
// await ry8.pin.cfg(packet)
|
2018-03-04 15:13:55 -08:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|