@chirimen/ads1015
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,52 +0,44 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ADS1015 = factory()); | ||
}(this, (function () { 'use strict'; | ||
// @ts-check | ||
// @ts-check | ||
/** @param {number} ms Delay for a number of milliseconds. */ | ||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
/** @param {number} ms Delay for a number of milliseconds. */ | ||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
var ADS1015 = function (i2cPort, slaveAddress) { | ||
this.i2cPort = i2cPort; | ||
this.slaveAddress = slaveAddress; | ||
this.i2cSlave = null; | ||
}; | ||
var ADS1015 = function (i2cPort, slaveAddress) { | ||
this.i2cPort = i2cPort; | ||
this.slaveAddress = slaveAddress; | ||
this.i2cSlave = null; | ||
}; | ||
ADS1015.prototype = { | ||
init: async function () { | ||
this.i2cSlave = await this.i2cPort.open(this.slaveAddress); | ||
}, | ||
read: async function (channel) { | ||
if (this.i2cSlave == null) { | ||
throw new Error("i2cSlave is not open yet."); | ||
} | ||
ADS1015.prototype = { | ||
init: async function () { | ||
this.i2cSlave = await this.i2cPort.open(this.slaveAddress); | ||
}, | ||
read: async function (channel) { | ||
if (this.i2cSlave == null) { | ||
throw new Error("i2cSlave is not open yet."); | ||
} | ||
if ((channel < 0) || (3 < channel)) { | ||
throw new Error("ADS1015.read: channel error" + channel); | ||
} | ||
var config = 0x4000 + (channel * 0x1000); // ADC channel | ||
config |= 0x8000; // Set 'start single-conversion' bit | ||
config |= 0x0003; // Disable the comparator (default val) | ||
config |= 0x0080; // 1600 samples per second (default) | ||
config |= 0x0100; // Power-down single-shot mode (default) | ||
config |= 0x0200; // +/-4.096V range = Gain 1 | ||
var confL = config >> 8; | ||
var confH = config & 0x00ff; | ||
var data = confH | confL; | ||
await this.i2cSlave.write16(0x01, data); | ||
await sleep(10); | ||
var v = await this.i2cSlave.read16(0); | ||
var vH = (v & 0x00ff) << 8; | ||
var vL = (v >> 8) & 0x00ffff; | ||
var value = (vH | vL) >> 4; | ||
return value; | ||
if ((channel < 0) || (3 < channel)) { | ||
throw new Error("ADS1015.read: channel error" + channel); | ||
} | ||
}; | ||
return ADS1015; | ||
var config = 0x4000 + (channel * 0x1000); // ADC channel | ||
config |= 0x8000; // Set 'start single-conversion' bit | ||
config |= 0x0003; // Disable the comparator (default val) | ||
config |= 0x0080; // 1600 samples per second (default) | ||
config |= 0x0100; // Power-down single-shot mode (default) | ||
config |= 0x0200; // +/-4.096V range = Gain 1 | ||
var confL = config >> 8; | ||
var confH = config & 0x00ff; | ||
var data = confH | confL; | ||
await this.i2cSlave.write16(0x01, data); | ||
await sleep(10); | ||
var v = await this.i2cSlave.read16(0); | ||
var vH = (v & 0x00ff) << 8; | ||
var vL = (v >> 8) & 0x00ffff; | ||
var value = (vH | vL) >> 4; | ||
return value; | ||
} | ||
}; | ||
}))); | ||
export default ADS1015; |
{ | ||
"name": "@chirimen/ads1015", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Driver for ADS1015 with WebI2C", | ||
"main": "ads1015.js", | ||
"module": "ads1015.mjs", | ||
"main": "index.js", | ||
"module": "ads1015.js", | ||
"license": "MIT", | ||
@@ -17,3 +17,4 @@ "repository": { | ||
"scripts": { | ||
"build": "rollup -c" | ||
"build": "rollup -c", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -23,3 +24,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "f8958ce1dadd6028397af59597b8b83313af045f" | ||
"gitHead": "bcccf29cc06de94168dd100ef2936965ff1a616e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4919