Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chirimen/ads1015

Package Overview
Dependencies
Maintainers
8
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chirimen/ads1015 - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

index.js

82

ads1015.js

@@ -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"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc