0.1.16 fix old access to socket to using getSocket
parent
26e480725c
commit
54872314ba
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/i2c-device",
|
"name": "@uci/i2c-device",
|
||||||
"version": "0.1.15",
|
"version": "0.1.16",
|
||||||
"description": "Device Classes for I2C Interfacing",
|
"description": "Device Classes for I2C Interfacing",
|
||||||
"main": "src/device",
|
"main": "src/device",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -12,46 +12,45 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
receive: async function() {
|
receive: async function() {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'receive', args: {address:this.address}})
|
return await this.send('bus',{ cmd:'receive', args: {address:this.address}})
|
||||||
},
|
},
|
||||||
|
|
||||||
send: async function(byte) {
|
send: async function(byte) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'send', args: {address:this.address, byte:byte }})
|
return await this.send('bus',{ cmd:'send', args: {address:this.address, byte:byte }})
|
||||||
},
|
},
|
||||||
|
|
||||||
// for devices needing a buffer/stream
|
// for devices needing a buffer/stream
|
||||||
readRaw: async function (length, buffer) {
|
readRaw: async function (length, buffer) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'readRaw', args: {address:this.address, length:length, buffer:buffer }})
|
return await this.send('bus',{ cmd:'readRaw', args: {address:this.address, length:length, buffer:buffer }})
|
||||||
},
|
},
|
||||||
|
|
||||||
writeRaw: async function (length, buffer) {
|
writeRaw: async function (length, buffer) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'writeRaw', args: {address:this.address, length:length, buffer:buffer }})
|
return await this.send('bus',{ cmd:'writeRaw', args: {address:this.address, length:length, buffer:buffer }})
|
||||||
},
|
},
|
||||||
|
|
||||||
// both cmd and byte should be a single byte as a decimal or hex
|
// both cmd and byte should be a single byte as a decimal or hex
|
||||||
read: async function (cmd) {
|
read: async function (cmd) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }})
|
return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }})
|
||||||
},
|
},
|
||||||
|
|
||||||
write: async function (cmd, byte) {
|
write: async function (cmd, byte) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }})
|
return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }})
|
||||||
},
|
},
|
||||||
|
|
||||||
// for I2C devices that use a word length packackage
|
// for I2C devices that use a word length packackage
|
||||||
read2: async function (cmd) {
|
read2: async function (cmd) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'read2', args: {address:this.address, cmd:cmd }})
|
return await this.send('bus',{ cmd:'read2', args: {address:this.address, cmd:cmd }})
|
||||||
},
|
},
|
||||||
|
|
||||||
write2: async function (cmd, bytes) {
|
write2: async function (cmd, bytes) {
|
||||||
await this._setChannel()
|
if (this.channel) await this._setChannel()
|
||||||
return await this.send('bus',{ cmd:'write2', args: {address:this.address, cmd:cmd, byte:bytes }})
|
return await this.send('bus',{ cmd:'write2', args: {address:this.address, cmd:cmd, byte:bytes }})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import Base from '@uci/base'
|
import Base from '@uci/base'
|
||||||
// import Base from '../../uci-base/src/base'
|
|
||||||
import commands from './bus-device-commands'
|
import commands from './bus-device-commands'
|
||||||
// import logger from '../../uci-logger/src/logger'
|
|
||||||
import logger from '@uci-utils/logger'
|
import logger from '@uci-utils/logger'
|
||||||
let log = {}
|
let log = {}
|
||||||
|
|
||||||
|
@ -25,14 +23,14 @@ class I2CDevice extends Base {
|
||||||
})
|
})
|
||||||
if (!opts.address) log.fatal({ opts: opts, method:'constructor', line:26, msg:'no i2c bus address supplied'})
|
if (!opts.address) log.fatal({ opts: opts, method:'constructor', line:26, msg:'no i2c bus address supplied'})
|
||||||
this.address = +opts.address // make sure any passed number is number not a string
|
this.address = +opts.address // make sure any passed number is number not a string
|
||||||
this._channel = +opts.channel // if using TAC9546A channel number on which device is attached
|
this.channel = +opts.channel // if using TAC9546A channel number on which device is attached
|
||||||
this.bus = this.bindFuncs(commands)
|
this.bus = this.bindFuncs(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await super.init()
|
await super.init()
|
||||||
let res = await this.bus.ack()
|
let res = await this.bus.ack()
|
||||||
let socket = this.socket.bus.opts
|
let socket = this.getSocket('bus').opts
|
||||||
let connection = socket.path || socket.host + ':' + socket.port
|
let connection = socket.path || socket.host + ':' + socket.port
|
||||||
if (!res.ack) {
|
if (!res.ack) {
|
||||||
let err ={error:'ack', res:res, socket:socket, method:'init', line:38, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`}
|
let err ={error:'ack', res:res, socket:socket, method:'init', line:38, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`}
|
||||||
|
@ -42,9 +40,9 @@ class I2CDevice extends Base {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO enable mux channel set
|
// TODO enable mux board channel set
|
||||||
// async _setChannel() {
|
async _setChannel() {
|
||||||
// }
|
}
|
||||||
|
|
||||||
} // end of i2c Device Class
|
} // end of i2c Device Class
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue