Socket
Socket
Sign inDemoInstall

chip-io

Package Overview
Dependencies
24
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## Version 2.0.2
* Correct internal temperature controller name.
* Correct PWM polarity inversion.
* Switch to sync. I/O, resolves I2C issues.
## Version 2.0.1

@@ -2,0 +8,0 @@

23

lib/allwinner-r8.js

@@ -75,17 +75,8 @@ var events = require('events');

AllwinnerR8.prototype.open = function(callback) {
fs.open('/dev/mem', 'rs+', function(err, fd) {
if (err) {
callback(err);
return;
}
AllwinnerR8.prototype.open = function() {
this._fd = fs.openSync('/dev/mem', 'rs+');
this._fd = fd;
var registers = libc.mmap(null, REGISTERS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, this._fd, REGISTERS_START);
var registers = libc.mmap(null, REGISTERS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, this._fd, REGISTERS_START);
this._registers = ref.reinterpret(registers, REGISTERS_SIZE, 0);
callback();
}.bind(this));
this._registers = ref.reinterpret(registers, REGISTERS_SIZE, 0);
};

@@ -116,3 +107,3 @@

if (pin === 'PWM0' && mode === 2) {
var pwmCtrlVal = (1 << 6) | (1 << 4);
var pwmCtrlVal = (1 << 6) | (1 << 5) | (1 << 4);
var pwmPeriodVal = (0xff << 16) | 0;

@@ -181,3 +172,3 @@

AllwinnerR8.prototype.close = function(callback) {
AllwinnerR8.prototype.close = function() {
if (this._registers) {

@@ -187,3 +178,3 @@ libc.munmap(this._registers, REGISTERS_SIZE);

fs.close(this._fd, callback);
fs.closeSync(this._fd);
};

@@ -190,0 +181,0 @@

@@ -17,3 +17,2 @@ var events = require('events');

this._reads = {};
this._readInProgress = {};
}

@@ -23,4 +22,4 @@

AXP209.prototype.open = function(callback) {
this._i2c.open(callback);
AXP209.prototype.open = function() {
this._i2c.open();
};

@@ -45,66 +44,43 @@

AXP209.prototype.tick = function() {
if (this._reads.BAT && !this._readInProgress.BAT) {
this._readInProgress.BAT = true;
if (this._reads.BAT) {
var batVolt = this._readBatVolt();
this._readBatVolt(function(err, value) {
if (!err) {
this.emit('analog-read', 'BAT', value);
}
this._readInProgress.BAT = false;
}.bind(this));
this.emit('analog-read', 'BAT', batVolt);
}
if (this._reads.INTTEMP && !this._readInProgress.INTTEMP) {
this._readInProgress.INTTEMP = true;
if (this._reads.INTTEMP) {
var intTemp = this._readIntTemp();
this._readIntTemp(function(err, value) {
if (!err) {
this.emit('analog-read', 'INTTEMP', value);
}
this._readInProgress.INTTEMP = false;
}.bind(this));
this.emit('analog-read', 'INTTEMP', intTemp);
}
};
AXP209.prototype.close = function(callback) {
this._i2c.close(callback);
AXP209.prototype.close = function() {
this._i2c.close();
};
AXP209.prototype._readIntTemp = function(callback) {
this._readAdc(INT_TEMP_MSB_REGISTER, INT_TEMP_LSB_REGISTER, callback);
AXP209.prototype._readIntTemp = function() {
return this._readAdc(INT_TEMP_MSB_REGISTER, INT_TEMP_LSB_REGISTER);
};
AXP209.prototype._readBatVolt = function(callback) {
this._readAdc(BAT_VOLT_MSB_REGISTER, BAT_VOLT_LSB_REGISTER, callback);
AXP209.prototype._readBatVolt = function() {
return this._readAdc(BAT_VOLT_MSB_REGISTER, BAT_VOLT_LSB_REGISTER);
};
AXP209.prototype._configureBatAdc = function(callback) {
AXP209.prototype._configureBatAdc = function() {
// force ADC enable for battery voltage and current
this._i2c.writeRegister(BAT_ADC_REGISTER, new Buffer([0xc3]), callback);
return this._i2c.writeRegister(BAT_ADC_REGISTER, new Buffer([0xc3]));
};
AXP209.prototype._writeGpio2 = function(value, callback) {
this._i2c.writeRegister(GPIO2_REGISTER, new Buffer([value]), callback);
AXP209.prototype._writeGpio2 = function(value) {
this._i2c.writeRegister(GPIO2_REGISTER, new Buffer([value]));
};
AXP209.prototype._readAdc = function(msbRegister, lsbRegister, callback) {
this._i2c.readRegister(msbRegister, 1, function(err, msbData) {
if (err) {
return callback(err);
}
AXP209.prototype._readAdc = function(msbRegister, lsbRegister) {
msbData = this._i2c.readRegister(msbRegister, 1);
lsbData = this._i2c.readRegister(lsbRegister, 1);
this._i2c.readRegister(lsbRegister, 1, function(err, lsbData) {
if (err) {
return callback(err);
}
var value = (msbData[0] << 4) | (lsbData[0] & 0x0f);
callback(null, value);
}.bind(this));
}.bind(this));
return ((msbData[0] << 4) | (lsbData[0] & 0x0f));
};
module.exports = AXP209;

@@ -65,22 +65,17 @@ var util = require('util');

this._chips.AXP209.open(function(err) {
if (err) {
throw err;
}
this._chips.AXP209.open();
this._chips.PCF8574A.open();
this._chips.PCF8574A.open(function(err) {
if (err) {
throw err;
}
try {
this._chips.R8.open();
} catch(err) {
// "optional" (requires root), so ignore err
}
this._chips.R8.open(function(err) {
// "optional" (requires root), so ignore err
// all done, emit 'ready' event on the next tick
process.nextTick(function() {
this.emit('ready');
// setup interval for digital and analog reads
this._tickInterval = setInterval(this._tick.bind(this), TICK_INTERVAL);
// all done, emit ready event
this.emit('ready');
}.bind(this));
}.bind(this));
// start the internal ticker
this._tick();
}.bind(this));

@@ -211,18 +206,12 @@ }

i2c.open(function(err) {
if (err) {
return;
}
i2c.open();
if (register) {
i2c.writeRegister(register, data, function() {
i2c.close();
});
} else {
i2c.write(data, function() {
i2c.close();
});
}
});
if (register) {
i2c.writeRegister(register, data);
} else {
i2c.write(data);
}
i2c.close();
return this;

@@ -258,39 +247,23 @@ };

var i2c = new I2C(bus, address);
var event;
var data;
i2c.open(function(err) {
if (err) {
return;
}
i2c.open();
if (register) {
i2c.readRegister(register, size, function(err, data) {
if (err) {
return;
}
if (register) {
event = 'I2C-reply-' + address + '-' + register;
data = i2c.readRegister(register, size);
} else {
event = 'I2C-reply-' + address;
data = i2c.read(size);
}
i2c.close(function() {
var event = 'I2C-reply-' + address + '-' + register;
i2c.close();
this.once(event, handler);
this.once(event, handler);
this.emit(event, data);
}.bind(this));
}.bind(this));
} else {
i2c.read(size, function(err, data) {
if (err) {
return;
}
process.nextTick(function(event, data) {
this.emit(event, data);
}.bind(this, event, data));
i2c.close(function() {
var event = 'I2C-reply-' + address;
this.once(event, handler);
this.emit(event, data);
}.bind(this));
}.bind(this));
}
}.bind(this));
return this;

@@ -307,2 +280,5 @@ };

}
// schedule next tick
this._tickTimeout = setTimeout(this._tick.bind(this), TICK_INTERVAL);
};

@@ -309,0 +285,0 @@

@@ -14,25 +14,21 @@ var fs = require('fs');

I2C.prototype.open = function(callback) {
fs.open('/dev/i2c-' + this._bus, 'r+', function(err, fd) {
if (err) {
return callback(err);
}
I2C.prototype.open = function() {
this._fd = fs.openSync('/dev/i2c-' + this._bus, 'r+');
this._fd = fd;
ioctl(this._fd, I2C_SLAVE_FORCE, this._address, callback);
}.bind(this));
ioctl(this._fd, I2C_SLAVE_FORCE, this._address);
};
I2C.prototype.write = function(value, callback) {
fs.write(this._fd, value, 0, value.length, callback);
I2C.prototype.write = function(value) {
fs.writeSync(this._fd, value, 0, value.length);
};
I2C.prototype.read = function(size, callback) {
fs.read(this._fd, new Buffer(size), 0, size, null, function(err, bytesRead, buffer) {
callback(err, buffer);
});
I2C.prototype.read = function(size) {
var buffer = new Buffer(size);
fs.readSync(this._fd, buffer, 0, size, null);
return buffer;
};
I2C.prototype.writeRegister = function(register, value, callback) {
I2C.prototype.writeRegister = function(register, value) {
var buffer = Buffer.concat([

@@ -46,16 +42,12 @@ new Buffer([register]),

I2C.prototype.readRegister = function(register, size, callback) {
this.write(new Buffer([register]), function(err) {
if (err) {
return callback(err);
}
I2C.prototype.readRegister = function(register, size) {
this.write(new Buffer([register]));
this.read(size, callback);
}.bind(this));
return this.read(size);
};
I2C.prototype.close = function(callback) {
fs.close(this._fd, callback);
I2C.prototype.close = function() {
fs.closeSync(this._fd);
};
module.exports = I2C;

@@ -10,3 +10,3 @@ var util = require('util');

opts.controller = Controllers.InternalTemperature;
opts.controller = Controllers.INTERNAL_TEMP;

@@ -13,0 +13,0 @@ five.Thermometer.call(this, opts);

@@ -8,3 +8,3 @@ var errno = require('errno').errno;

module.exports = function(fd, request, arg, callback) {
module.exports = function(fd, request, arg) {
var err;

@@ -17,6 +17,2 @@

}
if (typeof(callback) === 'function') {
callback(err);
}
};

@@ -16,9 +16,5 @@ var events = require('events');

PCF8574A.prototype.open = function(callback) {
this._i2c.open(function(err) {
if (err) {
return callback(err);
}
this._i2c.open();
this._i2c.write(0x00, callback);
}.bind(this));
this._i2c.write(0x00);
};

@@ -58,30 +54,24 @@

if (this._readMask) {
this._read(function(err, value) {
if (!err) {
for (var i = 0; i < 8; i++) {
var pinMask = (1 << i);
var value = this._read();
if (this._readMask & pinMask) {
this.emit('digital-read', 'XIO-P' + i, (value & pinMask) ? 1 : 0);
}
}
for (var i = 0; i < 8; i++) {
var pinMask = (1 << i);
if (this._readMask & pinMask) {
this.emit('digital-read', 'XIO-P' + i, (value & pinMask) ? 1 : 0);
}
}.bind(this));
}
}
};
PCF8574A.prototype.close = function(callback) {
this._i2c.close(callback);
PCF8574A.prototype.close = function() {
this._i2c.close();
};
PCF8574A.prototype._read = function(callback) {
this._i2c.read(1, function(err, value) {
if (err) {
return callback(err);
}
PCF8574A.prototype._read = function() {
var value = this._i2c.read(1);
callback(err, value[0]);
});
return value[0];
};
module.exports = PCF8574A;
{
"name": "chip-io",
"version": "2.0.1",
"version": "2.0.2",
"description": "Johnny-Five IO Plugin for the Next Thing Co. C.H.I.P.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,2 +24,4 @@ # chip-io

__NOTE:__ Must be run on the C.H.I.P. itself.
## Boilerplate Program

@@ -96,3 +98,3 @@

| CSID7 | 78 | Input, Output | ✓ | |
| I2C | | I2C | | Uses I2C port 2 (TWI2-SCK and TWI2-SDA) |
| I2C | | I2C | | Uses I2C port 2 (TWI2-SCK and TWI2-SDA). Address 0x38 is used by the built-in PCF8574A IO extender |

@@ -99,0 +101,0 @@ ![C.H.I.P. pinouts](http://docs.getchip.com/images/chip_pinouts.jpg)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc