refactor socket options

master
David Kebler 2018-02-17 18:27:25 -08:00
parent 78397d22bf
commit cab186f1f1
2 changed files with 15 additions and 11 deletions

View File

@ -1,8 +1,8 @@
{
"name": "@uci/i2c-bus",
"version": "0.1.0",
"version": "0.1.2",
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
"main": "src/bus",
"main": "src/bus-packet.mjs",
"scripts": {
"busa": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus",
"bus": "SOCKET_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus",

View File

@ -2,10 +2,11 @@
import i2c from 'i2c-bus'
import pify from 'pify'
import btc from 'better-try-catch'
// import Base from '@uci/base'
import Base from '../../uci-base/src/base'
import Base from '@uci/base'
// import Base from '../../uci-base/src/base'
import logger from '../../uci-logger/src/logger'
// import logger from '../../uci-logger/src/logger'
import logger from '@uci/logger'
let log = {}
const LOG_OPTS = {
repo:'uci-i2c-bus',
@ -19,11 +20,16 @@ const LOG_OPTS = {
export default class Bus extends Base {
constructor(opts) {
log = logger.child(LOG_OPTS)
opts.sockets = opts.sockets || 'us#s>n,ts#s>t'
opts.ts = opts.ts || { port:1776 }
opts.us = opts.us || {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
log.info({opts:opts},'create bus with these opts')
// TODO make ts options when tcp:true option or tcp:port
if(!opts.ns) opts.ns = {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ns#s>n'
if(opts.ts) {
opts.ts.port = opts.ts.port || 1776
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ts#s>t'
}
super(opts)
log.info({opts:opts},'created bus with these opts')
console.log({opts:opts},'created bus with these opts')
this.busnum = opts.busnum || 1
this.i2cbus = i2c.open(this.busnum, () => {})
this.bus = bus_funcs
@ -84,8 +90,6 @@ const validateArgs = function (packet) {
return {}
}
const bus_funcs = {
scan: function () { return pify(this.i2cbus.scan).bind(this.i2cbus)() },
close: function () { return pify(this.i2cbus.close).bind(this.i2cbus)() },