mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
build
This commit is contained in:
parent
4dd786679b
commit
64278cb7fa
1 changed files with 7 additions and 6 deletions
13
index.js
13
index.js
|
@ -1,5 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.requestI2CAccess = exports.OperationError = exports.I2CPort = exports.I2CPortMap = exports.I2CAccess = void 0;
|
||||||
const i2c_bus_1 = require("i2c-bus");
|
const i2c_bus_1 = require("i2c-bus");
|
||||||
const I2CPortMapSizeMax = 32;
|
const I2CPortMapSizeMax = 32;
|
||||||
const Uint16Max = 65535;
|
const Uint16Max = 65535;
|
||||||
|
@ -38,15 +39,15 @@ class I2CPort {
|
||||||
return `i2c-${this.portNumber}`;
|
return `i2c-${this.portNumber}`;
|
||||||
}
|
}
|
||||||
async open(slaveAddress) {
|
async open(slaveAddress) {
|
||||||
const bus = await i2c_bus_1.openPromisified(this.portNumber).catch(error => {
|
const bus = await i2c_bus_1.openPromisified(this.portNumber).catch((error) => {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
slaveAddress,
|
slaveAddress,
|
||||||
read8: cmd => bus.readByte(slaveAddress, cmd).catch(error => {
|
read8: (cmd) => bus.readByte(slaveAddress, cmd).catch((error) => {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}),
|
}),
|
||||||
read16: cmd => bus.readWord(slaveAddress, cmd).catch(error => {
|
read16: (cmd) => bus.readWord(slaveAddress, cmd).catch((error) => {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}),
|
}),
|
||||||
write8: async (cmd, byte) => {
|
write8: async (cmd, byte) => {
|
||||||
|
@ -106,7 +107,7 @@ class I2CPort {
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new OperationError(error);
|
throw new OperationError(error);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,9 +120,9 @@ class OperationError extends Error {
|
||||||
}
|
}
|
||||||
exports.OperationError = OperationError;
|
exports.OperationError = OperationError;
|
||||||
async function requestI2CAccess() {
|
async function requestI2CAccess() {
|
||||||
const ports = new I2CPortMap([...Array(I2CPortMapSizeMax).keys()].map(portNumber => [
|
const ports = new I2CPortMap([...Array(I2CPortMapSizeMax).keys()].map((portNumber) => [
|
||||||
portNumber,
|
portNumber,
|
||||||
new I2CPort(portNumber)
|
new I2CPort(portNumber),
|
||||||
]));
|
]));
|
||||||
return new I2CAccess(ports);
|
return new I2CAccess(ports);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue