Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to i2c-bus 5.2.2, fix buffers allocations. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"bignumber.js": "^4.0.2",
"i2c-bus": "^1.2.2"
"i2c-bus": "^5.2.2"
},
"node-red": {
"nodes": {
Expand Down
6 changes: 3 additions & 3 deletions sensors/bme280-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module.exports = function (RED) {

// get calibration parameters set 1 (1 of 2)
let p2 = new Promise((resolve, reject) => {
let buffer = new Uint8Array(12 * 2 + 1 /* 12 coefficients, 2 bytes each + 1 byte*/);
let buffer = Buffer.alloc(12 * 2 + 1 /* 12 coefficients, 2 bytes each + 1 byte*/); //new Uint8Array(12 * 2 + 1 /* 12 coefficients, 2 bytes each + 1 byte*/);
i2cBus.readI2cBlock(node.address, CALIBRATION_PARAMS_ADDRESS1, buffer.length, buffer, (err, bytesRead, buffer) => {
if (err) {
let errResult = `${node.name} read calibration parameters error: ${err}`;
Expand Down Expand Up @@ -299,7 +299,7 @@ module.exports = function (RED) {

// get calibration parameters set 2 (2 of 2)
let p3 = new Promise((resolve, reject) => {
let buffer = new Uint8Array(7);
let buffer = Buffer.alloc(7); //new Uint8Array(7);
i2cBus.readI2cBlock(node.address, CALIBRATION_PARAMS_ADDRESS2, buffer.length, buffer, (err, bytesRead, buffer) => {
if (err) {
let errResult = `${node.name} read calibration parameters error: ${err}`;
Expand Down Expand Up @@ -535,7 +535,7 @@ module.exports = function (RED) {
function measure() {
debug(' measure() ...');

let buffer = new Uint8Array(8);
let buffer = Buffer.alloc(8); //new Uint8Array(8);
let timeToWait = getMaxMeasureTime(node.tresolution, node.presolution, node.hresolution);
debug(`timeToWait -> ${timeToWait} ms`);

Expand Down
4 changes: 2 additions & 2 deletions sensors/bmp180-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module.exports = function (RED) {

// get calibration parameters
let p2 = new Promise((resolve, reject) => {
let buffer = new Uint8Array(11 * 2 /* 12 coefficients, 2 bytes each */);
let buffer = Buffer.alloc(11 * 2 /* 11 coefficients, 2 bytes each */); //new Uint8Array(11 * 2 /* 12 coefficients, 2 bytes each */);
i2cBus.readI2cBlock(node.address, CALIBRATION_PARAMS_ADDRESS, buffer.length, buffer, (err, bytesRead, buffer) => {
if (err) {
let errResult = `${node.name} read calibration parameters error: ${err}`;
Expand Down Expand Up @@ -237,7 +237,7 @@ module.exports = function (RED) {
function measure() {
debug(' measure() ...');

let buffer = new Uint8Array(3);
let buffer = Buffer.alloc(3); //new Uint8Array(3);
let timestamp;
let UT = 0;
let UP = 0;
Expand Down
4 changes: 2 additions & 2 deletions sensors/bmp280-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module.exports = function (RED) {

// get calibration parameters
let p2 = new Promise((resolve, reject) => {
let buffer = new Uint8Array(12 * 2 /* 12 coefficients, 2 bytes each */);
let buffer = Buffer.alloc(12 * 2 /* 12 coefficients, 2 bytes each */); //new Uint8Array(12 * 2 /* 12 coefficients, 2 bytes each */);
i2cBus.readI2cBlock(node.address, CALIBRATION_PARAMS_ADDRESS, buffer.length, buffer, (err, bytesRead, buffer) => {
if (err) {
let errResult = `${node.name} read calibration parameters error: ${err}`;
Expand Down Expand Up @@ -339,7 +339,7 @@ module.exports = function (RED) {
}

function measure(node) {
let buffer = new Uint8Array(6);
let buffer = Buffer.alloc(6); //new Uint8Array(6);
let command = (node.p_oversampling | node.t_oversampling | node.powermode) & 0xff;
node.log(' measure() ...');

Expand Down
2 changes: 1 addition & 1 deletion sensors/mcp9808-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module.exports = function (RED) {
reject(`mcp9808 set measure temperature error: ${err}`);
} else {

let buffer = new Uint8Array(2);
let buffer = Buffer.alloc(2); //new Uint8Array(2);
i2cBus.readI2cBlock(node.address, REGISTER_TEMPERATURE, buffer.length, buffer, (err, bytesRead, buffer) => {
if (err) {
reject( `mcp9808 get temperature bytes error: ${err}` );
Expand Down
2 changes: 1 addition & 1 deletion sensors/tsl2561-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ module.exports = function (RED) {

let lux = 0;

let buffer = new Uint8Array(4);
let buffer = Buffer.alloc(4); //new Uint8Array(4);
let channel0 = 0;
let channel1 = 0;

Expand Down