Dia antes primera install
This commit is contained in:
33
node_modules/i2c-bus/integration-test/async-brute-force-leak-check.js
generated
vendored
Normal file
33
node_modules/i2c-bus/integration-test/async-brute-force-leak-check.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const leakTest = testRuns => {
|
||||
const tlbuf = Buffer.alloc(1000000);
|
||||
|
||||
i2c1.readI2cBlock(DS1621_ADDR, CMD_ACCESS_TL, 2, tlbuf, (err, bytesRead, buffer) => {
|
||||
assert(!err, 'can\'t read block data from tl');
|
||||
assert.strictEqual(bytesRead, 2, 'expected readI2cBlock to read 2 bytes');
|
||||
|
||||
if (testRuns % 1000 === 0) {
|
||||
console.log(testRuns);
|
||||
}
|
||||
|
||||
testRuns -= 1;
|
||||
if (testRuns === 0) {
|
||||
i2c1.closeSync();
|
||||
} else {
|
||||
leakTest(testRuns);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const i2c1 = i2c.open(1, err => {
|
||||
assert(!err, 'can\'t open i2c bus');
|
||||
leakTest(1000000);
|
||||
});
|
||||
|
||||
30
node_modules/i2c-bus/integration-test/async-performance.js
generated
vendored
Normal file
30
node_modules/i2c-bus/integration-test/async-performance.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const ITERATIONS = 5000;
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
let time;
|
||||
|
||||
const performanceTest = testRuns => {
|
||||
i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL, _ => {
|
||||
testRuns -= 1;
|
||||
if (testRuns === 0) {
|
||||
time = process.hrtime(time);
|
||||
const readsPerSec = Math.floor(ITERATIONS / (time[0] + time[1] / 1E9));
|
||||
i2c1.closeSync();
|
||||
console.log('ok - async-performance - ' + readsPerSec + ' reads per second');
|
||||
} else {
|
||||
performanceTest(testRuns);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const i2c1 = i2c.open(1, _ => {
|
||||
time = process.hrtime();
|
||||
performanceTest(ITERATIONS);
|
||||
});
|
||||
|
||||
31
node_modules/i2c-bus/integration-test/async-promise-performance.js
generated
vendored
Normal file
31
node_modules/i2c-bus/integration-test/async-promise-performance.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const ITERATIONS = 5000;
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
let time;
|
||||
|
||||
const performanceTest = (i2c1, testRuns) => {
|
||||
i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL).then(word => {
|
||||
testRuns -= 1;
|
||||
if (testRuns === 0) {
|
||||
time = process.hrtime(time);
|
||||
const readsPerSec = Math.floor(ITERATIONS / (time[0] + time[1] / 1E9));
|
||||
i2c1.close().then(_ =>
|
||||
console.log('ok - async-promise-performance - ' + readsPerSec + ' reads per second')
|
||||
);
|
||||
} else {
|
||||
performanceTest(i2c1, testRuns);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
i2c.openPromisified(1).then(i2c1 => {
|
||||
time = process.hrtime();
|
||||
performanceTest(i2c1, ITERATIONS);
|
||||
});
|
||||
|
||||
138
node_modules/i2c-bus/integration-test/async-promise.js
generated
vendored
Normal file
138
node_modules/i2c-bus/integration-test/async-promise.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_CONFIG = 0xac;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
// Wait while non volatile memory busy
|
||||
const waitForWrite = i2c1 => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const checkWriteFlag = _ => {
|
||||
i2c1.readByte(DS1621_ADDR, CMD_ACCESS_CONFIG).
|
||||
then(config => {
|
||||
if (config & 0x10) {
|
||||
checkWriteFlag();
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}).
|
||||
catch(reject);
|
||||
};
|
||||
|
||||
checkWriteFlag();
|
||||
});
|
||||
};
|
||||
|
||||
const finished = i2c1 =>
|
||||
i2c1.close().
|
||||
then(_ => console.log('ok - async-promise'));
|
||||
|
||||
const i2cFuncs = i2c1 =>
|
||||
i2c1.i2cFuncs().
|
||||
then(i2cFuncs => assert(i2cFuncs.smbusReadByte, 'expected it to be possible to read a byte'));
|
||||
|
||||
const scan = i2c1 =>
|
||||
i2c1.scan().
|
||||
then(devices => assert(
|
||||
devices.includes(DS1621_ADDR),
|
||||
'expected scan to find a ds1621 at address 0x' + DS1621_ADDR.toString(16)
|
||||
));
|
||||
|
||||
// Test i2cWrite & i2cRead
|
||||
// Change value of tl to 25 and verify that tl has been changed
|
||||
const i2cPlainReadWrite = i2c1 => {
|
||||
const cmdSetTL = Buffer.from([CMD_ACCESS_TL, 25, 0]);
|
||||
const cmdGetTL = Buffer.from([CMD_ACCESS_TL]);
|
||||
const tl = Buffer.alloc(2);
|
||||
|
||||
return i2c1.i2cWrite(DS1621_ADDR, cmdSetTL.length, cmdSetTL).
|
||||
then(block => {
|
||||
assert.strictEqual(block.bytesWritten, cmdSetTL.length, 'expected i2cWrite to write 3 bytes');
|
||||
assert.strictEqual(cmdSetTL, block.buffer, 'expected cmdSetTL to be block.buffer');
|
||||
}).
|
||||
then(_ => waitForWrite(i2c1)).
|
||||
then(_ => i2c1.i2cWrite(DS1621_ADDR, cmdGetTL.length, cmdGetTL)).
|
||||
then(block => {
|
||||
assert.strictEqual(block.bytesWritten, cmdGetTL.length, 'expected i2cWrite to write 1 byte');
|
||||
assert.strictEqual(cmdGetTL, block.buffer, 'expected cmdGetTL to be block.buffer');
|
||||
}).
|
||||
then(_ => i2c1.i2cRead(DS1621_ADDR, 2, tl)).
|
||||
then(block => {
|
||||
assert.strictEqual(block.bytesRead, 2, 'expected i2cRead to read 2 bytes');
|
||||
assert.strictEqual(tl.readUInt16LE(0), 25, 'expected i2cRead to read value 25');
|
||||
assert.strictEqual(tl, block.buffer, 'expected tl to be block.buffer');
|
||||
});
|
||||
};
|
||||
|
||||
// Test writeI2cBlock & readI2cBlock
|
||||
// Change value of tl to 22 and verify that tl has been changed
|
||||
const readWriteI2cBlock = i2c1 => {
|
||||
const newtl = Buffer.alloc(10);
|
||||
newtl.writeUInt16LE(22, 0);
|
||||
|
||||
return i2c1.writeI2cBlock(DS1621_ADDR, CMD_ACCESS_TL, 2, newtl).
|
||||
then(block => {
|
||||
assert.strictEqual(block.bytesWritten, 2, 'expected writeI2cBlock to write 2 bytes');
|
||||
assert.strictEqual(newtl, block.buffer, 'expected newtl to be block.buffer');
|
||||
}).
|
||||
then(_ => waitForWrite(i2c1)).
|
||||
then(_ => i2c1.readI2cBlock(DS1621_ADDR, CMD_ACCESS_TL, 2, newtl)).
|
||||
then(block => {
|
||||
assert.strictEqual(block.bytesRead, 2, 'expected readI2cBlock to read 2 bytes');
|
||||
assert.strictEqual(block.buffer.readUInt16LE(0), 22, 'expected readI2cBlock to read value 22');
|
||||
assert.strictEqual(newtl, block.buffer, 'expected newtl to be block.buffer');
|
||||
});
|
||||
};
|
||||
|
||||
// Test writeWord & readWord
|
||||
// Change value of tl and verify that tl has been changed
|
||||
const readWriteWord = i2c1 =>
|
||||
i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL).
|
||||
then(oldtl => {
|
||||
assert(typeof oldtl === 'number' && oldtl <= 0xffff, 'expeted readWord to read a word');
|
||||
const newtl = (oldtl === 24 ? 23 : 24);
|
||||
return i2c1.writeWord(DS1621_ADDR, CMD_ACCESS_TL, newtl).
|
||||
then(_ => i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL)).
|
||||
then(newtl2 => {
|
||||
assert(typeof newtl2 === 'number' && newtl2 <= 0xffff, 'expeted readWord to read a word');
|
||||
assert.strictEqual(newtl, newtl2, 'expected to read word written');
|
||||
});
|
||||
});
|
||||
|
||||
// Test sendByte & receiveByte
|
||||
// Read config and verify that it's epectedConfig
|
||||
const sendReceiveByte = (i2c1, epectedConfig) =>
|
||||
i2c1.sendByte(DS1621_ADDR, CMD_ACCESS_CONFIG).
|
||||
then(_ => i2c1.receiveByte(DS1621_ADDR)).
|
||||
then(config => {
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted receiveByte to receive a byte');
|
||||
assert.strictEqual(config, epectedConfig, '1st and 2nd config read differ');
|
||||
});
|
||||
|
||||
// Test writeByte & readByte
|
||||
// Enter continuous mode and verify that continuous mode has been entered
|
||||
const readWriteByte = i2c1 =>
|
||||
i2c1.writeByte(DS1621_ADDR, CMD_ACCESS_CONFIG, 0x0).
|
||||
then(_ => waitForWrite(i2c1)).
|
||||
then(_ => i2c1.readByte(DS1621_ADDR, CMD_ACCESS_CONFIG)).
|
||||
then(config => {
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted readByte to read a byte');
|
||||
assert.strictEqual(config & 0x1, 0, 'continuous mode not eneterd');
|
||||
return config;
|
||||
});
|
||||
|
||||
i2c.openPromisified(1).
|
||||
then(i2c1 => readWriteByte(i2c1).
|
||||
then(config => sendReceiveByte(i2c1, config)).
|
||||
then(_ => readWriteWord(i2c1)).
|
||||
then(_ => readWriteI2cBlock(i2c1)).
|
||||
then(_ => i2cPlainReadWrite(i2c1)).
|
||||
then(_ => scan(i2c1)).
|
||||
then(_ => i2cFuncs(i2c1)).
|
||||
then(_ => finished(i2c1))
|
||||
).
|
||||
catch(console.log);
|
||||
|
||||
138
node_modules/i2c-bus/integration-test/async.js
generated
vendored
Normal file
138
node_modules/i2c-bus/integration-test/async.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_CONFIG = 0xac;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
// Wait while non volatile memory busy
|
||||
const waitForWrite = cb => {
|
||||
i2c1.readByte(DS1621_ADDR, CMD_ACCESS_CONFIG, (err, config) => {
|
||||
assert(!err, 'can\'t read config to determine memory status');
|
||||
if (config & 0x10) {
|
||||
return waitForWrite(cb);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
const finished = _ => i2c1.close(_ => console.log('ok - async'));
|
||||
|
||||
const i2cPlainReadWrite = _ => {
|
||||
// Test i2cWrite & i2cRead
|
||||
// Change value of tl to 25 and verify that tl has been changed
|
||||
const cmdSetTL = Buffer.from([CMD_ACCESS_TL, 25, 0]);
|
||||
const cmdGetTL = Buffer.from([CMD_ACCESS_TL]);
|
||||
const tl = Buffer.alloc(2);
|
||||
|
||||
i2c1.i2cWrite(DS1621_ADDR, cmdSetTL.length, cmdSetTL, (err, bytesWritten, buffer) => {
|
||||
assert(!err, 'can\'t i2cWrite cmdSetTL');
|
||||
assert.strictEqual(bytesWritten, cmdSetTL.length, 'expected i2cWrite to write 3 bytes');
|
||||
assert.strictEqual(cmdSetTL, buffer, 'expected cmdSetTL to be passed to i2cWrite callback');
|
||||
|
||||
waitForWrite(_ => {
|
||||
i2c1.i2cWrite(DS1621_ADDR, cmdGetTL.length, cmdGetTL, (err, bytesWritten, buffer) => {
|
||||
assert(!err, 'can\'t i2cWrite cmdGetTL');
|
||||
assert.strictEqual(bytesWritten, cmdGetTL.length, 'expected i2cWrite to write 1 byte');
|
||||
assert.strictEqual(cmdGetTL, buffer, 'expected cmdGetTL to be passed to i2cWrite callback');
|
||||
|
||||
i2c1.i2cRead(DS1621_ADDR, 2, tl, (err, bytesRead, buffer) => {
|
||||
assert(!err, 'can\'t i2cRead tl');
|
||||
assert.strictEqual(bytesRead, 2, 'expected i2cRead to read 2 bytes');
|
||||
assert.strictEqual(tl.readUInt16LE(0), 25, 'expected i2cRead to read value 25');
|
||||
assert.strictEqual(tl, buffer, 'expected tl to be passed to i2cRead callback');
|
||||
|
||||
finished();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const readWriteI2cBlock = _ => {
|
||||
// Test writeI2cBlock & readI2cBlock
|
||||
// Change value of tl to 22 and verify that tl has been changed
|
||||
const newtl = Buffer.alloc(10);
|
||||
|
||||
newtl.writeUInt16LE(22, 0);
|
||||
i2c1.writeI2cBlock(DS1621_ADDR, CMD_ACCESS_TL, 2, newtl, (err, bytesWritten, buffer) => {
|
||||
assert(!err, 'can\'t writeI2cBlock to tl');
|
||||
assert.strictEqual(bytesWritten, 2, 'expected writeI2cBlock to write 2 bytes');
|
||||
assert.strictEqual(newtl, buffer, 'expected newtl to be passed to writeI2cBlock callback');
|
||||
|
||||
waitForWrite(_ => {
|
||||
i2c1.readI2cBlock(DS1621_ADDR, CMD_ACCESS_TL, 2, newtl, (err, bytesRead, buffer) => {
|
||||
assert(!err, 'can\'t readI2cBlock from tl');
|
||||
assert.strictEqual(bytesRead, 2, 'expected readI2cBlock to read 2 bytes');
|
||||
assert.strictEqual(buffer.readUInt16LE(0), 22, 'expected readI2cBlock to read value 22');
|
||||
assert.strictEqual(newtl, buffer, 'expected newtl to be passed to readI2cBlock callback');
|
||||
|
||||
i2cPlainReadWrite();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const readWriteWord = _ => {
|
||||
// Test writeWord & readWord
|
||||
// Change value of tl and verify that tl has been changed
|
||||
i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL, (err, oldtl) => {
|
||||
assert(!err, 'can\'t readWord from tl');
|
||||
assert(typeof oldtl === 'number' && oldtl <= 0xffff, 'expeted readWord to read a word');
|
||||
|
||||
const newtl = (oldtl === 24 ? 23 : 24);
|
||||
i2c1.writeWord(DS1621_ADDR, CMD_ACCESS_TL, newtl, err => {
|
||||
assert(!err, 'can\'t write word to tl');
|
||||
|
||||
i2c1.readWord(DS1621_ADDR, CMD_ACCESS_TL, (err, newtl2) => {
|
||||
assert(!err, 'can\'t read new word from tl');
|
||||
assert(typeof newtl2 === 'number' && newtl2 <= 0xffff, 'expeted readWord to read a word');
|
||||
assert.strictEqual(newtl, newtl2, 'expected to read word written');
|
||||
|
||||
readWriteI2cBlock();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const sendReceiveByte = epectedConfig => {
|
||||
// Test sendByte & receiveByte
|
||||
// Read config and verify that it's epectedConfig
|
||||
i2c1.sendByte(DS1621_ADDR, CMD_ACCESS_CONFIG, err => {
|
||||
assert(!err, 'can\'t send byte to config');
|
||||
|
||||
i2c1.receiveByte(DS1621_ADDR, (err, config) => {
|
||||
assert(!err, 'can\'t receive byte from config');
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted receiveByte to receive a byte');
|
||||
assert.strictEqual(config, epectedConfig, '1st and 2nd config read differ');
|
||||
|
||||
readWriteWord();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const readWriteByte = _ => {
|
||||
// Test writeByte & readByte
|
||||
// Enter continuous mode and verify that continuous mode has been entered
|
||||
i2c1.writeByte(DS1621_ADDR, CMD_ACCESS_CONFIG, 0x0, err => {
|
||||
assert(!err, 'can\'t write byte to config');
|
||||
|
||||
waitForWrite(_ => {
|
||||
i2c1.readByte(DS1621_ADDR, CMD_ACCESS_CONFIG, (err, config) => {
|
||||
assert(!err, 'can\'t read byte from config');
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted readByte to read a byte');
|
||||
assert.strictEqual(config & 0x1, 0, 'continuous mode not eneterd');
|
||||
|
||||
sendReceiveByte(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const i2c1 = i2c.open(1, err => {
|
||||
assert(!err, 'can\'t open i2c bus');
|
||||
readWriteByte();
|
||||
});
|
||||
|
||||
45
node_modules/i2c-bus/integration-test/busses.js
generated
vendored
Normal file
45
node_modules/i2c-bus/integration-test/busses.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const openPromisified = _ =>
|
||||
i2c.openPromisified(1).
|
||||
then(promisifiedBus => {
|
||||
assert.strictEqual(
|
||||
promisifiedBus, promisifiedBus.bus().promisifiedBus(),
|
||||
'expected promisifiedBus.bus().promisifiedBus() to return promisifiedBus'
|
||||
);
|
||||
|
||||
const bus = promisifiedBus.bus();
|
||||
assert.strictEqual(
|
||||
bus, bus.promisifiedBus().bus(),
|
||||
'expected bus.promisifiedBus().bus() to return bus'
|
||||
);
|
||||
|
||||
return promisifiedBus.close();
|
||||
}).
|
||||
then(_ => console.log('ok - busses')).
|
||||
catch(console.log);
|
||||
|
||||
const open = _ => {
|
||||
const bus = i2c.open(1, err => {
|
||||
assert(!err, 'can\'t open i2c bus');
|
||||
|
||||
assert.strictEqual(
|
||||
bus, bus.promisifiedBus().bus(),
|
||||
'expected bus.promisifiedBus().bus() to return bus'
|
||||
);
|
||||
|
||||
const promisifiedBus = bus.promisifiedBus();
|
||||
assert.strictEqual(
|
||||
promisifiedBus, promisifiedBus.bus().promisifiedBus(),
|
||||
'expected promisifiedBus.bus().promisifiedBus() to return promisifiedBus'
|
||||
);
|
||||
|
||||
openPromisified();
|
||||
});
|
||||
};
|
||||
|
||||
open();
|
||||
|
||||
17
node_modules/i2c-bus/integration-test/deviceid.js
generated
vendored
Normal file
17
node_modules/i2c-bus/integration-test/deviceid.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
const i2c1 = i2c.openSync(42);
|
||||
|
||||
const address = 0x50;
|
||||
|
||||
i2c1.deviceId(address, (err, id) => {
|
||||
if (err) {
|
||||
console.log('error', err);
|
||||
} else {
|
||||
console.log('id for address', '0x' + address.toString(16), id);
|
||||
}
|
||||
|
||||
i2c1.closeSync();
|
||||
});
|
||||
|
||||
338
node_modules/i2c-bus/integration-test/errors.js
generated
vendored
Normal file
338
node_modules/i2c-bus/integration-test/errors.js
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
const i2c1 = i2c.openSync(1);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Methods
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// open(busNumber [, options], cb)
|
||||
assert.throws(_ => i2c.open('not an integer'), /Invalid I2C bus number/, 'open');
|
||||
assert.throws(_ => i2c.open(-1), /Invalid I2C bus number/, 'open');
|
||||
|
||||
// openSync(busNumber [, options])
|
||||
assert.throws(_ => i2c.openSync('not an integer'), /Invalid I2C bus number/, 'openSync');
|
||||
assert.throws(_ => i2c.openSync(-1), /Invalid I2C bus number/, 'openSync');
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Free resources
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// close(cb)
|
||||
assert.throws(_ => i2c1.close('not a cb'), /Invalid callback/, 'close');
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Information
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// i2cFuncs(cb)
|
||||
assert.throws(_ => i2c1.i2cFuncs('not a cb'), /Invalid callback/, 'i2cFuncs');
|
||||
|
||||
// scan(cb)
|
||||
assert.throws(_ => i2c1.scan('not a cb'), /Invalid callback/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(0, 'not a cb'), /Invalid callback/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(0, 0, 'not a cb'), /Invalid callback/, 'scan');
|
||||
assert.throws(_ => i2c1.scan('not an addr', 'not a cb'), /Invalid callback/, 'scan');
|
||||
assert.throws(_ => i2c1.scan('not an addr', 'not an addr', 'not a cb'), /Invalid callback/, 'scan');
|
||||
|
||||
assert.throws(_ => i2c1.scan('not an addr', _ => {}), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(-1, _ => {}), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(128, _ => {}), /Invalid I2C address/, 'scan');
|
||||
|
||||
assert.throws(_ => i2c1.scan(0, 'not an addr', _ => {}), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(0, -1, _ => {}), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scan(0, 128, _ => {}), /Invalid I2C address/, 'scan');
|
||||
|
||||
// scanSync(cb)
|
||||
assert.throws(_ => i2c1.scanSync('not an addr'), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scanSync(-1), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scanSync(128), /Invalid I2C address/, 'scan');
|
||||
|
||||
assert.throws(_ => i2c1.scanSync(0, 'not an addr'), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scanSync(0, -1), /Invalid I2C address/, 'scan');
|
||||
assert.throws(_ => i2c1.scanSync(0, 128), /Invalid I2C address/, 'scan');
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Plain I2C
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// i2cRead(addr, length, buffer, cb)
|
||||
assert.throws(_ => i2c1.i2cRead('not an addr', 100, Buffer.alloc(100), _ => {}), /Invalid I2C address/, 'i2cRead');
|
||||
assert.throws(_ => i2c1.i2cRead(-1, 100, Buffer.alloc(100), _ => {}), /Invalid I2C address/, 'i2cRead');
|
||||
assert.throws(_ => i2c1.i2cRead(128, 100, Buffer.alloc(100), _ => {}), /Invalid I2C address/, 'i2cRead');
|
||||
|
||||
assert.throws(_ => i2c1.i2cRead(0, 'not a length', Buffer.alloc(100), _ => {}), /Invalid buffer length/, 'i2cRead');
|
||||
assert.throws(_ => i2c1.i2cRead(0, -1, Buffer.alloc(100), _ => {}), /Invalid buffer length/, 'i2cRead');
|
||||
|
||||
assert.throws(_ => i2c1.i2cRead(0, 100, 'not a buffer', _ => {}), /Invalid buffer/, 'i2cRead');
|
||||
|
||||
assert.throws(_ => i2c1.i2cRead(0, 101, Buffer.alloc(100), _ => {}), /Buffer must contain at least/, 'i2cRead');
|
||||
|
||||
assert.throws(_ => i2c1.i2cRead(0, 100, Buffer.alloc(100), 'not a cb'), /Invalid callback/, 'i2cRead');
|
||||
|
||||
// i2cReadSync(addr, length, buffer)
|
||||
assert.throws(_ => i2c1.i2cReadSync('not an addr', 0), /Invalid I2C address/, 'i2cReadSync');
|
||||
assert.throws(_ => i2c1.i2cReadSync(-1, 0), /Invalid I2C address/, 'i2cReadSync');
|
||||
assert.throws(_ => i2c1.i2cReadSync(128, 0), /Invalid I2C address/, 'i2cReadSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cReadSync(0, 'not a length', Buffer.alloc(100)), /Invalid buffer length/, 'i2cReadSync');
|
||||
assert.throws(_ => i2c1.i2cReadSync(0, -1, Buffer.alloc(100)), /Invalid buffer length/, 'i2cReadSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cReadSync(0, 100, 'not a buffer'), /Invalid buffer/, 'i2cReadSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cReadSync(0, 101, Buffer.alloc(100)), /Buffer must contain at least/, 'i2cReadSync');
|
||||
|
||||
// i2cWrite(addr, length, buffer, cb)
|
||||
assert.throws(_ => i2c1.i2cWrite('not an addr', 0, _ => {}), /Invalid I2C address/, 'i2cWrite');
|
||||
assert.throws(_ => i2c1.i2cWrite(-1, 0, _ => {}), /Invalid I2C address/, 'i2cWrite');
|
||||
assert.throws(_ => i2c1.i2cWrite(128, 0, _ => {}), /Invalid I2C address/, 'i2cWrite');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWrite(0, 'not a length', Buffer.alloc(100), _ => {}), /Invalid buffer length/, 'i2cWrite');
|
||||
assert.throws(_ => i2c1.i2cWrite(0, -1, Buffer.alloc(100), _ => {}), /Invalid buffer length/, 'i2cWrite');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWrite(0, 100, 'not a buffer', _ => {}), /Invalid buffer/, 'i2cWrite');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWrite(0, 101, Buffer.alloc(100), _ => {}), /Buffer must contain at least/, 'i2cWrite');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWrite(0, 100, Buffer.alloc(100), 'not a cb'), /Invalid callback/, 'i2cWrite');
|
||||
|
||||
// i2cWriteSync(addr, length, buffer)
|
||||
assert.throws(_ => i2c1.i2cWriteSync('not an addr', 0), /Invalid I2C address/, 'i2cWriteSync');
|
||||
assert.throws(_ => i2c1.i2cWriteSync(-1, 0), /Invalid I2C address/, 'i2cWriteSync');
|
||||
assert.throws(_ => i2c1.i2cWriteSync(128, 0), /Invalid I2C address/, 'i2cWriteSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWriteSync(0, 'not a length', Buffer.alloc(100)), /Invalid buffer length/, 'i2cWriteSync');
|
||||
assert.throws(_ => i2c1.i2cWriteSync(0, -1, Buffer.alloc(100)), /Invalid buffer length/, 'i2cWriteSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWriteSync(0, 100, 'not a buffer'), /Invalid buffer/, 'i2cWriteSync');
|
||||
|
||||
assert.throws(_ => i2c1.i2cWriteSync(0, 101, Buffer.alloc(100)), /Buffer must contain at least/, 'i2cWriteSync');
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// SMBus
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// readByte(addr, cmd, cb)
|
||||
assert.throws(_ => i2c1.readByte('not an addr', 0, _ => {}), /Invalid I2C address/, 'readByte');
|
||||
assert.throws(_ => i2c1.readByte(-1, 0, _ => {}), /Invalid I2C address/, 'readByte');
|
||||
assert.throws(_ => i2c1.readByte(128, 0, _ => {}), /Invalid I2C address/, 'readByte');
|
||||
|
||||
assert.throws(_ => i2c1.readByte(0, 'not a command', _ => {}), /Invalid I2C command/, 'readByte');
|
||||
assert.throws(_ => i2c1.readByte(0, -1, _ => {}), /Invalid I2C command/, 'readByte');
|
||||
assert.throws(_ => i2c1.readByte(0, 256, _ => {}), /Invalid I2C command/, 'readByte');
|
||||
|
||||
assert.throws(_ => i2c1.readByte(0, 0, 'not a cb'), /Invalid callback/, 'readByte');
|
||||
|
||||
// readByteSync(addr, cmd)
|
||||
assert.throws(_ => i2c1.readByteSync('not an addr', 0), /Invalid I2C address/, 'readByteSync');
|
||||
assert.throws(_ => i2c1.readByteSync(-1, 0), /Invalid I2C address/, 'readByteSync');
|
||||
assert.throws(_ => i2c1.readByteSync(128, 0), /Invalid I2C address/, 'readByteSync');
|
||||
|
||||
assert.throws(_ => i2c1.readByteSync(0, 'not a command'), /Invalid I2C command/, 'readByteSync');
|
||||
assert.throws(_ => i2c1.readByteSync(0, -1), /Invalid I2C command/, 'readByteSync');
|
||||
assert.throws(_ => i2c1.readByteSync(0, 256), /Invalid I2C command/, 'readByteSync');
|
||||
|
||||
// readWord(addr, cmd, cb)
|
||||
assert.throws(_ => i2c1.readWord('not an addr', 0, _ => {}), /Invalid I2C address/, 'readWord');
|
||||
assert.throws(_ => i2c1.readWord(-1, 0, _ => {}), /Invalid I2C address/, 'readWord');
|
||||
assert.throws(_ => i2c1.readWord(128, 0, _ => {}), /Invalid I2C address/, 'readWord');
|
||||
|
||||
assert.throws(_ => i2c1.readWord(0, 'not a command', _ => {}), /Invalid I2C command/, 'readWord');
|
||||
assert.throws(_ => i2c1.readWord(0, -1, _ => {}), /Invalid I2C command/, 'readWord');
|
||||
assert.throws(_ => i2c1.readWord(0, 256, _ => {}), /Invalid I2C command/, 'readWord');
|
||||
|
||||
assert.throws(_ => i2c1.readWord(0, 0, 'not a cb'), /Invalid callback/, 'readWord');
|
||||
|
||||
// readWordSync(addr, cmd)
|
||||
assert.throws(_ => i2c1.readWordSync('not an addr', 0), /Invalid I2C address/, 'readWordSync');
|
||||
assert.throws(_ => i2c1.readWordSync(-1, 0), /Invalid I2C address/, 'readWordSync');
|
||||
assert.throws(_ => i2c1.readWordSync(128, 0), /Invalid I2C address/, 'readWordSync');
|
||||
|
||||
assert.throws(_ => i2c1.readWordSync(0, 'not a command'), /Invalid I2C command/, 'readWordSync');
|
||||
assert.throws(_ => i2c1.readWordSync(0, -1), /Invalid I2C command/, 'readWordSync');
|
||||
assert.throws(_ => i2c1.readWordSync(0, 256), /Invalid I2C command/, 'readWordSync');
|
||||
|
||||
// readI2cBlock(addr, cmd, length, buffer, cb)
|
||||
assert.throws(_ => i2c1.readI2cBlock('not an addr', 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(-1, 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(128, 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'readI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 'not a command', 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, -1, 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 256, 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'readI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, 'not a length', Buffer.alloc(10), _ => {}), /Invalid buffer length/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, -1, Buffer.alloc(10), _ => {}), /Invalid buffer length/, 'readI2cBlock');
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, 33, Buffer.alloc(33), _ => {}), /Invalid buffer length/, 'readI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, 10, 'not a buffer', _ => {}), /Invalid buffer/, 'readI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, 11, Buffer.alloc(10), _ => {}), /Buffer must contain at least/, 'readI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlock(0, 0, 10, Buffer.alloc(10), 'not a cb'), /Invalid callback/, 'readI2cBlock');
|
||||
|
||||
// readI2cBlockSync(addr, cmd, length, buffer)
|
||||
assert.throws(_ => i2c1.readI2cBlockSync('not an addr', 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(-1, 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(128, 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'readI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 'not a command', 10, Buffer.alloc(10)), /Invalid I2C command/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, -1, 10, Buffer.alloc(10)), /Invalid I2C command/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 256, 10, Buffer.alloc(10)), /Invalid I2C command/, 'readI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 0, 'not a length', Buffer.alloc(10)), /Invalid buffer length/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 0, -1, Buffer.alloc(10)), /Invalid buffer length/, 'readI2cBlockSync');
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 0, 33, Buffer.alloc(33)), /Invalid buffer length/, 'readI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 0, 10, 'not a buffer'), /Invalid buffer/, 'readI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.readI2cBlockSync(0, 0, 11, Buffer.alloc(10)), /Buffer must contain at least/, 'readI2cBlockSync');
|
||||
|
||||
// receiveByte(addr, cb)
|
||||
assert.throws(_ => i2c1.receiveByte('not an addr', _ => {}), /Invalid I2C address/, 'receiveByte');
|
||||
assert.throws(_ => i2c1.receiveByte(-1, _ => {}), /Invalid I2C address/, 'receiveByte');
|
||||
assert.throws(_ => i2c1.receiveByte(128, _ => {}), /Invalid I2C address/, 'receiveByte');
|
||||
|
||||
assert.throws(_ => i2c1.receiveByte(0, 'not a cb'), /Invalid callback/, 'receiveByte');
|
||||
|
||||
// receiveByteSync(addr)
|
||||
assert.throws(_ => i2c1.receiveByteSync('not an addr'), /Invalid I2C address/, 'receiveByteSync');
|
||||
assert.throws(_ => i2c1.receiveByteSync(-1), /Invalid I2C address/, 'receiveByteSync');
|
||||
assert.throws(_ => i2c1.receiveByteSync(128), /Invalid I2C address/, 'receiveByteSync');
|
||||
|
||||
// sendByte(addr, byte, cb)
|
||||
assert.throws(_ => i2c1.sendByte('not an addr', 0, _ => {}), /Invalid I2C address/, 'sendByte');
|
||||
assert.throws(_ => i2c1.sendByte(-1, 0, _ => {}), /Invalid I2C address/, 'sendByte');
|
||||
assert.throws(_ => i2c1.sendByte(128, 0, _ => {}), /Invalid I2C address/, 'sendByte');
|
||||
|
||||
assert.throws(_ => i2c1.sendByte(0, 'not a byte', _ => {}), /Invalid byte/, 'sendByte');
|
||||
assert.throws(_ => i2c1.sendByte(0, -1, _ => {}), /Invalid byte/, 'sendByte');
|
||||
assert.throws(_ => i2c1.sendByte(0, 256, _ => {}), /Invalid byte/, 'sendByte');
|
||||
|
||||
assert.throws(_ => i2c1.sendByte(0, 0, 'not a cb'), /Invalid callback/, 'sendByte');
|
||||
|
||||
// sendByteSync(addr, byte)
|
||||
assert.throws(_ => i2c1.sendByteSync('not an addr', 0), /Invalid I2C address/, 'sendByteSync');
|
||||
assert.throws(_ => i2c1.sendByteSync(-1, 0), /Invalid I2C address/, 'sendByteSync');
|
||||
assert.throws(_ => i2c1.sendByteSync(128, 0), /Invalid I2C address/, 'sendByteSync');
|
||||
|
||||
assert.throws(_ => i2c1.sendByteSync(0, 'not a byte'), /Invalid byte/, 'sendByteSync');
|
||||
assert.throws(_ => i2c1.sendByteSync(0, -1), /Invalid byte/, 'sendByteSync');
|
||||
assert.throws(_ => i2c1.sendByteSync(0, 256), /Invalid byte/, 'sendByteSync');
|
||||
|
||||
// writeByte(addr, cmd, byte, cb)
|
||||
assert.throws(_ => i2c1.writeByte('not an addr', 0, 0, _ => {}), /Invalid I2C address/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(-1, 0, 0, _ => {}), /Invalid I2C address/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(128, 0, 0, _ => {}), /Invalid I2C address/, 'writeByte');
|
||||
|
||||
assert.throws(_ => i2c1.writeByte(0, 'not a command', 0, _ => {}), /Invalid I2C command/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(0, -1, 0, _ => {}), /Invalid I2C command/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(0, 256, 0, _ => {}), /Invalid I2C command/, 'writeByte');
|
||||
|
||||
assert.throws(_ => i2c1.writeByte(0, 0, 'not a byte', _ => {}), /Invalid byte/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(0, 0, -1, _ => {}), /Invalid byte/, 'writeByte');
|
||||
assert.throws(_ => i2c1.writeByte(0, 0, 256, _ => {}), /Invalid byte/, 'writeByte');
|
||||
|
||||
assert.throws(_ => i2c1.writeByte(0, 0, 0, 'not a cb'), /Invalid callback/, 'writeByte');
|
||||
|
||||
// writeByteSync(addr, cmd, byte)
|
||||
assert.throws(_ => i2c1.writeByteSync('not an addr', 0, 0), /Invalid I2C address/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(-1, 0, 0), /Invalid I2C address/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(128, 0, 0), /Invalid I2C address/, 'writeByteSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeByteSync(0, 'not a command', 0), /Invalid I2C command/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(0, -1, 0), /Invalid I2C command/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(0, 256, 0), /Invalid I2C command/, 'writeByteSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeByteSync(0, 0, 'not a byte'), /Invalid byte/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(0, 0, -1), /Invalid byte/, 'writeByteSync');
|
||||
assert.throws(_ => i2c1.writeByteSync(0, 0, 256), /Invalid byte/, 'writeByteSync');
|
||||
|
||||
// writeWord(addr, cmd, word, cb)
|
||||
assert.throws(_ => i2c1.writeWord('not an addr', 0, 0, _ => {}), /Invalid I2C address/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(-1, 0, 0, _ => {}), /Invalid I2C address/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(128, 0, 0, _ => {}), /Invalid I2C address/, 'writeWord');
|
||||
|
||||
assert.throws(_ => i2c1.writeWord(0, 'not a command', 0, _ => {}), /Invalid I2C command/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(0, -1, 0, _ => {}), /Invalid I2C command/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(0, 256, 0, _ => {}), /Invalid I2C command/, 'writeWord');
|
||||
|
||||
assert.throws(_ => i2c1.writeWord(0, 0, 'not a word', _ => {}), /Invalid word/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(0, 0, -1, _ => {}), /Invalid word/, 'writeWord');
|
||||
assert.throws(_ => i2c1.writeWord(0, 0, 0xffff+1, _ => {}), /Invalid word/, 'writeWord');
|
||||
|
||||
assert.throws(_ => i2c1.writeWord(0, 0, 0, 'not a cb'), /Invalid callback/, 'writeWord');
|
||||
|
||||
// writeWordSync(addr, cmd, word)
|
||||
assert.throws(_ => i2c1.writeWordSync('not an addr', 0, 0), /Invalid I2C address/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(-1, 0, 0), /Invalid I2C address/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(128, 0, 0), /Invalid I2C address/, 'writeWordSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeWordSync(0, 'not a command', 0), /Invalid I2C command/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(0, -1, 0), /Invalid I2C command/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(0, 256, 0), /Invalid I2C command/, 'writeWordSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeWordSync(0, 0, 'not a word'), /Invalid word/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(0, 0, -1), /Invalid word/, 'writeWordSync');
|
||||
assert.throws(_ => i2c1.writeWordSync(0, 0, 0xffff+1), /Invalid word/, 'writeWordSync');
|
||||
|
||||
// writeQuick(addr, bit, cb)
|
||||
assert.throws(_ => i2c1.writeQuick('not an addr', 0, _ => {}), /Invalid I2C address/, 'writeQuick');
|
||||
assert.throws(_ => i2c1.writeQuick(-1, 0, _ => {}), /Invalid I2C address/, 'writeQuick');
|
||||
assert.throws(_ => i2c1.writeQuick(128, 0, _ => {}), /Invalid I2C address/, 'writeQuick');
|
||||
|
||||
assert.throws(_ => i2c1.writeQuick(0, 'not a word', _ => {}), /Invalid bit/, 'writeQuick');
|
||||
assert.throws(_ => i2c1.writeQuick(0, -1, _ => {}), /Invalid bit/, 'writeQuick');
|
||||
assert.throws(_ => i2c1.writeQuick(0, 2, _ => {}), /Invalid bit/, 'writeQuick');
|
||||
|
||||
assert.throws(_ => i2c1.writeQuick(0, 0, 'not a cb'), /Invalid callback/, 'writeQuick');
|
||||
|
||||
// writeQuickSync(addr, bit)
|
||||
assert.throws(_ => i2c1.writeQuickSync('not an addr', 0), /Invalid I2C address/, 'writeQuickSync');
|
||||
assert.throws(_ => i2c1.writeQuickSync(-1, 0), /Invalid I2C address/, 'writeQuickSync');
|
||||
assert.throws(_ => i2c1.writeQuickSync(128, 0), /Invalid I2C address/, 'writeQuickSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeQuickSync(0, 'not a word'), /Invalid bit/, 'writeQuickSync');
|
||||
assert.throws(_ => i2c1.writeQuickSync(0, -1), /Invalid bit/, 'writeQuickSync');
|
||||
assert.throws(_ => i2c1.writeQuickSync(0, 2), /Invalid bit/, 'writeQuickSync');
|
||||
|
||||
// writeI2cBlock(addr, cmd, length, buffer, cb)
|
||||
assert.throws(_ => i2c1.writeI2cBlock('not an addr', 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(-1, 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(128, 0, 10, Buffer.alloc(10), _ => {}), /Invalid I2C address/, 'writeI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 'not a command', 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, -1, 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 256, 10, Buffer.alloc(10), _ => {}), /Invalid I2C command/, 'writeI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, 'not a length', Buffer.alloc(10), _ => {}), /Invalid buffer length/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, -1, Buffer.alloc(10), _ => {}), /Invalid buffer length/, 'writeI2cBlock');
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, 33, Buffer.alloc(33), _ => {}), /Invalid buffer length/, 'writeI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, 10, 'not a buffer', _ => {}), /Invalid buffer/, 'writeI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, 11, Buffer.alloc(10), _ => {}), /Buffer must contain at least/, 'writeI2cBlock');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlock(0, 0, 10, Buffer.alloc(10), 'not a cb'), /Invalid callback/, 'writeI2cBlock');
|
||||
|
||||
// writeI2cBlockSync(addr, cmd, length, buffer)
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync('not an addr', 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(-1, 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(128, 0, 10, Buffer.alloc(10)), /Invalid I2C address/, 'writeI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 'not a command', 10, Buffer.alloc(10)), /Invalid I2C command/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, -1, 10, Buffer.alloc(10)), /Invalid I2C command/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 256, 10, Buffer.alloc(10)), /Invalid I2C command/, 'writeI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 0, 'not a length', Buffer.alloc(10)), /Invalid buffer length/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 0, -1, Buffer.alloc(10)), /Invalid buffer length/, 'writeI2cBlockSync');
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 0, 33, Buffer.alloc(33)), /Invalid buffer length/, 'writeI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 0, 10, 'not a buffer'), /Invalid buffer/, 'writeI2cBlockSync');
|
||||
|
||||
assert.throws(_ => i2c1.writeI2cBlockSync(0, 0, 11, Buffer.alloc(10)), /Buffer must contain at least/, 'writeI2cBlockSync');
|
||||
|
||||
console.log('ok - errors');
|
||||
|
||||
11
node_modules/i2c-bus/integration-test/i2c-functionality-available.js
generated
vendored
Normal file
11
node_modules/i2c-bus/integration-test/i2c-functionality-available.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
const i2c1 = i2c.openSync(1);
|
||||
const i2cfuncs = i2c1.i2cFuncsSync();
|
||||
const platform = i2cfuncs.smbusQuick ? 'Raspberry Pi?' : 'BeagleBone?';
|
||||
|
||||
i2c1.closeSync();
|
||||
|
||||
console.log('ok - i2c-functionality-available - ' + platform);
|
||||
|
||||
14
node_modules/i2c-bus/integration-test/run-tests
generated
vendored
Executable file
14
node_modules/i2c-bus/integration-test/run-tests
generated
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
node async
|
||||
node async-performance
|
||||
node async-promise
|
||||
node async-promise-performance
|
||||
node busses
|
||||
node errors
|
||||
node i2c-functionality-available
|
||||
node scan
|
||||
node sync
|
||||
node sync-many-instances
|
||||
node sync-performance
|
||||
node sync-plain-i2c-performance
|
||||
|
||||
27
node_modules/i2c-bus/integration-test/scan-leak-check.js
generated
vendored
Normal file
27
node_modules/i2c-bus/integration-test/scan-leak-check.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const lodash = require('lodash');
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const bus = i2c.openSync(1);
|
||||
let count = 0;
|
||||
|
||||
const next = _ => {
|
||||
const addresses = bus.scanSync();
|
||||
|
||||
bus.scan((err, devices) => {
|
||||
assert(!err, 'can\'t scan for devices');
|
||||
assert(lodash.isEqual(addresses, devices), 'sync and async scan differ');
|
||||
|
||||
count += 1;
|
||||
if (count % 10 === 0) {
|
||||
console.log(count);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
next();
|
||||
|
||||
82
node_modules/i2c-bus/integration-test/scan.js
generated
vendored
Normal file
82
node_modules/i2c-bus/integration-test/scan.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
const lodash = require('lodash');
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const TSL2561_ADDR = 0x39;
|
||||
const DS1621_ADDR = 0x48;
|
||||
|
||||
const bus = i2c.openSync(1);
|
||||
|
||||
const scanSyncRange = _ => {
|
||||
const devices = bus.scanSync(TSL2561_ADDR, DS1621_ADDR);
|
||||
|
||||
assert(devices.length === 2, 'expected 2 devices');
|
||||
assert(
|
||||
devices[0] === TSL2561_ADDR,
|
||||
'expected device at address 0x' + TSL2561_ADDR.toString(16)
|
||||
);
|
||||
assert(
|
||||
devices[1] === DS1621_ADDR,
|
||||
'expected device at address 0x' + DS1621_ADDR.toString(16)
|
||||
);
|
||||
|
||||
console.log('ok - scan');
|
||||
};
|
||||
|
||||
const scanSyncForSingleDevice = _ => {
|
||||
const devices = bus.scanSync(DS1621_ADDR);
|
||||
|
||||
assert(devices.length === 1, 'expected 1 device');
|
||||
assert(
|
||||
devices[0] === DS1621_ADDR,
|
||||
'expected device at address 0x' + DS1621_ADDR.toString(16)
|
||||
);
|
||||
|
||||
scanSyncRange();
|
||||
};
|
||||
|
||||
const scanRange = _ => {
|
||||
bus.scan(TSL2561_ADDR, DS1621_ADDR, (err, devices) => {
|
||||
assert(!err, 'can\'t scan range');
|
||||
assert(devices.length === 2, 'expected 2 devices');
|
||||
assert(
|
||||
devices[0] === TSL2561_ADDR,
|
||||
'expected device at address 0x' + TSL2561_ADDR.toString(16)
|
||||
);
|
||||
assert(
|
||||
devices[1] === DS1621_ADDR,
|
||||
'expected device at address 0x' + DS1621_ADDR.toString(16)
|
||||
);
|
||||
|
||||
scanSyncForSingleDevice();
|
||||
});
|
||||
};
|
||||
|
||||
const scanForSingleDevice = _ => {
|
||||
bus.scan(DS1621_ADDR, (err, devices) => {
|
||||
assert(!err, 'can\'t scan for single device');
|
||||
assert(devices.length === 1, 'expected 1 device');
|
||||
assert(
|
||||
devices[0] === DS1621_ADDR,
|
||||
'expected device at address 0x' + DS1621_ADDR.toString(16)
|
||||
);
|
||||
|
||||
scanRange();
|
||||
});
|
||||
};
|
||||
|
||||
const scanDefaultRange = _ => {
|
||||
const addresses = bus.scanSync();
|
||||
|
||||
bus.scan((err, devices) => {
|
||||
assert(!err, 'can\'t scan default range');
|
||||
assert(lodash.isEqual(addresses, devices), 'sync and async scan differ');
|
||||
|
||||
scanForSingleDevice();
|
||||
});
|
||||
};
|
||||
|
||||
scanDefaultRange();
|
||||
|
||||
21
node_modules/i2c-bus/integration-test/sync-brute-force-leak-check.js
generated
vendored
Normal file
21
node_modules/i2c-bus/integration-test/sync-brute-force-leak-check.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const i2c1 = i2c.openSync(1);
|
||||
|
||||
for (let i = 1; i <= 1000000; i += 1) {
|
||||
const tlbuf = Buffer.alloc(1000000);
|
||||
const bytesRead = i2c1.readI2cBlockSync(DS1621_ADDR, CMD_ACCESS_TL, 2, tlbuf);
|
||||
assert.strictEqual(bytesRead, 2, 'expected readI2cBlockSync to read 2 bytes');
|
||||
if (i % 1000 === 0) {
|
||||
console.log(i);
|
||||
}
|
||||
}
|
||||
|
||||
i2c1.closeSync();
|
||||
|
||||
26
node_modules/i2c-bus/integration-test/sync-deviceid.js
generated
vendored
Normal file
26
node_modules/i2c-bus/integration-test/sync-deviceid.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const address = 0x50;
|
||||
const invalid = 0x42;
|
||||
|
||||
const readDeviceId = _ => {
|
||||
const i2c1 = i2c.openSync(42);
|
||||
const id = i2c1.deviceIdSync(address);
|
||||
|
||||
console.log('id for address', '0x' + address.toString(16), id);
|
||||
|
||||
//
|
||||
try {
|
||||
i2c1.deviceIdSync(invalid);
|
||||
} catch(e) {
|
||||
i2c1.closeSync();
|
||||
return;
|
||||
}
|
||||
|
||||
throw Error('should have exited though catch');
|
||||
};
|
||||
|
||||
readDeviceId();
|
||||
|
||||
51
node_modules/i2c-bus/integration-test/sync-many-instances.js
generated
vendored
Normal file
51
node_modules/i2c-bus/integration-test/sync-many-instances.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const DS1621_CMD_ACCESS_TH = 0xa1;
|
||||
const DS1621_CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const TSL2561_ADDR = 0x39;
|
||||
const TSL2561_CMD = 0x80;
|
||||
const TSL2561_REG_ID = 0x0a;
|
||||
|
||||
const useBusMoreThanMaxFdTimes = _ => {
|
||||
// Assuming that less than 2000 files can be opened at the same time,
|
||||
// open and close /dev/i2c-1 2000 times to make sure it works and to ensure
|
||||
// that file descriptors are being freed.
|
||||
for (let i = 1; i <= 2000; i += 1) {
|
||||
const i2c1 = i2c.openSync(1);
|
||||
i2c1.readWordSync(DS1621_ADDR, DS1621_CMD_ACCESS_TL);
|
||||
i2c1.closeSync();
|
||||
}
|
||||
};
|
||||
|
||||
const useMultipleObjectsForSameBusConcurrently = _ => {
|
||||
const buses = [];
|
||||
|
||||
// Make sure many Bus objects can be opened and used for the same I2C bus at
|
||||
// the same time.
|
||||
for (let i = 1; i <= 128; i += 1) {
|
||||
buses.push(i2c.openSync(1));
|
||||
}
|
||||
buses.forEach(bus => bus.readWordSync(DS1621_ADDR, DS1621_CMD_ACCESS_TL));
|
||||
buses.forEach(bus => bus.closeSync());
|
||||
};
|
||||
|
||||
const useTwoObjectsForSameBusConcurrently = _ => {
|
||||
const ds1621 = i2c.openSync(1);
|
||||
const tsl2561 = i2c.openSync(1);
|
||||
const ds1621TempHigh = ds1621.readWordSync(DS1621_ADDR, DS1621_CMD_ACCESS_TH);
|
||||
const tsl2561Id = tsl2561.readByteSync(TSL2561_ADDR, TSL2561_CMD | TSL2561_REG_ID);
|
||||
|
||||
console.log(' ds1621TempHigh: ' + ds1621TempHigh);
|
||||
console.log(' tsl2561Id: ' + tsl2561Id);
|
||||
};
|
||||
|
||||
useBusMoreThanMaxFdTimes();
|
||||
useMultipleObjectsForSameBusConcurrently();
|
||||
useTwoObjectsForSameBusConcurrently();
|
||||
|
||||
console.log('ok - sync-many-instances');
|
||||
|
||||
24
node_modules/i2c-bus/integration-test/sync-performance.js
generated
vendored
Normal file
24
node_modules/i2c-bus/integration-test/sync-performance.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const ITERATIONS = 5000;
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const i2c1 = i2c.openSync(1);
|
||||
|
||||
let time = process.hrtime();
|
||||
|
||||
for (let reads = 1; reads <= ITERATIONS; reads += 1) {
|
||||
i2c1.readWordSync(DS1621_ADDR, CMD_ACCESS_TL);
|
||||
}
|
||||
|
||||
time = process.hrtime(time);
|
||||
const readsPerSec = Math.floor(ITERATIONS / (time[0] + time[1] / 1E9));
|
||||
|
||||
i2c1.closeSync();
|
||||
|
||||
console.log('ok - sync-performance - ' + readsPerSec + ' reads per second');
|
||||
|
||||
28
node_modules/i2c-bus/integration-test/sync-plain-i2c-performance.js
generated
vendored
Normal file
28
node_modules/i2c-bus/integration-test/sync-plain-i2c-performance.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const i2c = require('../');
|
||||
|
||||
const ITERATIONS = 5000;
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const i2c1 = i2c.openSync(1);
|
||||
const cmdGetTL = Buffer.from([CMD_ACCESS_TL]);
|
||||
const tl = Buffer.alloc(2);
|
||||
|
||||
let time = process.hrtime();
|
||||
|
||||
// one operation is an i2cWriteSync and an i2cReadSync, i.e., two calls
|
||||
for (let operations = 1; operations <= ITERATIONS; operations += 1) {
|
||||
i2c1.i2cWriteSync(DS1621_ADDR, cmdGetTL.length, cmdGetTL);
|
||||
i2c1.i2cReadSync(DS1621_ADDR, 2, tl);
|
||||
}
|
||||
|
||||
time = process.hrtime(time);
|
||||
const opsPerSec = Math.floor(ITERATIONS / (time[0] + time[1] / 1E9));
|
||||
|
||||
i2c1.closeSync();
|
||||
|
||||
console.log('ok - sync-plain-i2c-performance - ' + opsPerSec + ' (x 2) operations per second');
|
||||
|
||||
103
node_modules/i2c-bus/integration-test/sync.js
generated
vendored
Normal file
103
node_modules/i2c-bus/integration-test/sync.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const i2c = require('../');
|
||||
|
||||
const DS1621_ADDR = 0x48;
|
||||
const CMD_ACCESS_CONFIG = 0xac;
|
||||
const CMD_ACCESS_TL = 0xa2;
|
||||
|
||||
const i2c1 = i2c.openSync(1);
|
||||
|
||||
// Wait while non volatile memory busy
|
||||
const waitForWrite = _ => {
|
||||
while (i2c1.readByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG) & 0x10) {
|
||||
}
|
||||
};
|
||||
|
||||
// Test writeByteSync & readByteSync
|
||||
// Enter one shot mode and verify that one shot mode has been entered
|
||||
const readWriteByte = _ => {
|
||||
const self = i2c1.writeByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG, 0x01);
|
||||
assert.strictEqual(self, i2c1, 'expected writeByteSync to return this');
|
||||
waitForWrite();
|
||||
const config = i2c1.readByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG);
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted readByteSync to read a byte');
|
||||
assert.strictEqual(config & 0x1, 1, 'one shot mode not eneterd');
|
||||
};
|
||||
|
||||
// Test sendByteSync & receiveByteSync
|
||||
// Read config using different techniques and verify that 1st and 2nd read
|
||||
// are identical
|
||||
const sendReceiveByte = _ => {
|
||||
const expectedConfig = i2c1.readByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG);
|
||||
assert(typeof expectedConfig === 'number' && expectedConfig <= 0xff, 'expeted readByteSync to read a byte');
|
||||
|
||||
const self = i2c1.sendByteSync(DS1621_ADDR, CMD_ACCESS_CONFIG);
|
||||
assert.strictEqual(self, i2c1, 'expected sendByteSync to return this');
|
||||
|
||||
const config = i2c1.receiveByteSync(DS1621_ADDR);
|
||||
assert(typeof config === 'number' && config <= 0xff, 'expeted receiveByteSync to receive a byte');
|
||||
assert.strictEqual(config, expectedConfig, '1st and 2nd config read differ');
|
||||
};
|
||||
|
||||
// Test writeWordSync & readWordSync
|
||||
// Change value of tl and verify that tl has been changed
|
||||
const readWriteWord = _ => {
|
||||
const oldtl = i2c1.readWordSync(DS1621_ADDR, CMD_ACCESS_TL);
|
||||
assert(typeof oldtl === 'number' && oldtl <= 0xffff, 'expeted readWordSync to read a word');
|
||||
|
||||
const tl = (oldtl === 24 ? 23 : 24);
|
||||
|
||||
const self = i2c1.writeWordSync(DS1621_ADDR, CMD_ACCESS_TL, tl);
|
||||
assert.strictEqual(self, i2c1, 'expected writeWordSync to return this');
|
||||
waitForWrite();
|
||||
|
||||
const newtl = i2c1.readWordSync(DS1621_ADDR, CMD_ACCESS_TL);
|
||||
assert(typeof newtl === 'number' && newtl <= 0xffff, 'expeted readWordSync to read a word');
|
||||
assert.strictEqual(tl, newtl, 'expected to read word written');
|
||||
};
|
||||
|
||||
// Test writeI2cBlockSync & readI2cBlockSync
|
||||
// Change value of tl to 22 and verify that tl has been changed
|
||||
const readWriteI2cBlock = _ => {
|
||||
const tlbuf = Buffer.alloc(10);
|
||||
tlbuf.writeUInt16LE(22, 0);
|
||||
const self = i2c1.writeI2cBlockSync(DS1621_ADDR, CMD_ACCESS_TL, 2, tlbuf);
|
||||
assert.strictEqual(self, i2c1, 'expected writeI2cBlockSync to return this');
|
||||
waitForWrite();
|
||||
|
||||
const newtl = Buffer.alloc(10);
|
||||
const bytesRead = i2c1.readI2cBlockSync(DS1621_ADDR, CMD_ACCESS_TL, 2, newtl);
|
||||
assert.strictEqual(bytesRead, 2, 'expected readI2cBlockSync to read 2 bytes');
|
||||
assert.strictEqual(newtl.readUInt16LE(0), 22, 'expected readI2cBlockSync to read value 22');
|
||||
};
|
||||
|
||||
// Test i2cWriteSync & i2cReadSync
|
||||
// Change value of tl to 25 and verify that tl has been changed
|
||||
const i2cPlainReadWrite = _ => {
|
||||
const cmdSetTL = Buffer.from([CMD_ACCESS_TL, 25, 0]);
|
||||
let bytesWritten = i2c1.i2cWriteSync(DS1621_ADDR, cmdSetTL.length, cmdSetTL);
|
||||
assert.strictEqual(bytesWritten, 3, 'expected i2cWriteSync to write 3 bytes');
|
||||
waitForWrite();
|
||||
|
||||
const cmdGetTL = Buffer.from([CMD_ACCESS_TL]);
|
||||
bytesWritten = i2c1.i2cWriteSync(DS1621_ADDR, cmdGetTL.length, cmdGetTL);
|
||||
assert.strictEqual(bytesWritten, 1, 'expected i2cWriteSync to write 1 byte');
|
||||
|
||||
const tl = Buffer.alloc(2);
|
||||
const bytesRead = i2c1.i2cReadSync(DS1621_ADDR, 2, tl);
|
||||
assert.strictEqual(bytesRead, 2, 'expected i2cReadSync to read 2 bytes');
|
||||
assert.strictEqual(tl.readUInt16LE(0), 25, 'expected i2cReadSync to read value 25');
|
||||
};
|
||||
|
||||
readWriteByte();
|
||||
sendReceiveByte();
|
||||
readWriteWord();
|
||||
readWriteI2cBlock();
|
||||
i2cPlainReadWrite();
|
||||
|
||||
i2c1.closeSync();
|
||||
|
||||
console.log('ok - sync');
|
||||
|
||||
Reference in New Issue
Block a user