58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
export default {
|
|
|
|
ack: async function (){
|
|
// TODO if mux channel used check it as well
|
|
let bus = await this.send(this._bus_name,{ cmd:'scan'})
|
|
if (bus.error) return bus
|
|
let res = { cmd:'reply', ack: false, address:this.address, scan:bus.response}
|
|
if (bus.response.indexOf(this.address) !== -1) res.ack = true
|
|
return res
|
|
},
|
|
|
|
receive: async function() {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'receive', args: {address:this.address}})
|
|
},
|
|
|
|
send: async function(byte) {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'send', args: {address:this.address, byte:byte }})
|
|
},
|
|
|
|
// for devices needing a buffer/stream
|
|
readRaw: async function (length, buffer) {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'readRaw', args: {address:this.address, length:length, buffer:buffer }})
|
|
},
|
|
|
|
writeRaw: async function (length, buffer) {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'writeRaw', args: {address:this.address, length:length, buffer:buffer }})
|
|
},
|
|
|
|
// both cmd and byte should be a single byte as a decimal or hex
|
|
read: async function (cmd) {
|
|
await this._setChannel()
|
|
// console.log('after set before read',this.address,this.id,this._channel,await this.socket.bus.send(getState)
|
|
return await this.send(this._bus_name, { cmd:'read', args: {address:this.address, cmd:cmd }})
|
|
},
|
|
|
|
write: async function (cmd, byte) {
|
|
await this._setChannel()
|
|
// console.log('after set, before write',this.address,this.id,this._channel,await this.socket.bus.send(getState)
|
|
return await this.send(this._bus_name, { cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }})
|
|
},
|
|
|
|
// for I2C devices that use a word length packackage
|
|
read2: async function (cmd) {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'read2', args: {address:this.address, cmd:cmd }})
|
|
},
|
|
|
|
write2: async function (cmd, bytes) {
|
|
await this._setChannel()
|
|
return await this.send(this._bus_name, { cmd:'write2', args: {address:this.address, cmd:cmd, byte:bytes }})
|
|
}
|
|
|
|
}
|