// All the pin functions for corresponding packet cmd:'pin' // every function should return a packet ready to send to the i2c-bus socket // export {pin} const pin = { cfg: function(packet){ return new Promise( async (resolve) => { console.log(packet) return resolve() }) }, test: function(packet){ return new Promise( async (resolve, reject) => { setTimeout(() => {reject({error:'no response from bus in 2000ms'})},2000) let id = Math.random().toString().slice(2) let buspacket = {cmd:'scan', id:id} console.log('packet for bus', buspacket) this.busSend(buspacket) this.on(buspacket.id,function(busreply){ console.log('reply emitted',busreply) this.removeAllListeners(busreply.id) let res = { cmd:'reply', _req:packet, _reqBus:buspacket} if (busreply.response.indexOf(parseInt(this.address,16))!=-1) res.ready = true res.address = this.address console.log(res) resolve(res) }) }) }, status: function(packet){ return new Promise( async (resolve) => { console.log(packet) return resolve() }) }, // // state is equivalent to read // status: packet => { // }, // // threse three only for output pins // state : { // on: packet => { // }, // off: packet => { // }, // toggle: packet => { // } // }, // // will create packet to determin pin caused interrupt, packet will come from interrupt module // interrupt: { // find: packet =>{}, // report: packet=>{} // come here after determining which pin to report to requester // } } export default pin