Skip to content

Commit

Permalink
yarn build
Browse files Browse the repository at this point in the history
  • Loading branch information
kou029w committed Jan 25, 2020
1 parent 38fc23f commit 3292080
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 71 deletions.
99 changes: 48 additions & 51 deletions packages/ads1015/ads1015.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,61 @@
(global = global || self, global.ADS1015 = factory());
}(this, (function () { 'use strict';

var ADS1015 = function(i2cPort,slaveAddress){
// @ts-check

/** @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;
};

ADS1015.prototype = {
init: function(){
return new Promise((resolve, reject) => {
this.i2cPort.open(this.slaveAddress).then((i2cSlave) => {
this.i2cSlave = i2cSlave;
resolve();
},(err) => {
console.error("ADS1015.init() Error: "+error.message);
reject(err);
});
});
init: async function () {
try {
this.i2cSlave = await this.i2cPort.open(this.slaveAddress);
} catch (error) {
console.error("ADS1015.init() Error: " + error.message);
throw error;
}
},
read: function(channel){
return new Promise((resolve, reject)=>{
if(this.i2cSlave){
if((channel > 3)||(channel < 0)){
console.error("ADS1015.read: channel error"+channel);
err.code = 5;
reject(err.message);
}
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;
this.i2cSlave.write16(0x01, data).then((v) => {
setTimeout(()=>{
this.i2cSlave.read16(0).then((v) =>{
var vH = (v & 0x00ff) << 8;
var vL = (v >> 8)& 0x00ffff;
var value = (vH | vL) >> 4;
resolve(value);
},(err) => {
console.error("ADS1015.read: read16(0) error"+err.message);
err.code = 3;
reject(err.message);
});
},10);
}, (err) => {
console.error("ADS1015.read: write16(0,config) error"+err.message);
err.code = 2;
reject(err.message);
});
}else{
err.code = 1;
reject(err.message);
}
});
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;

try {
await this.i2cSlave.write16(0x01, data);
} catch (error) {
throw new Error("ADS1015.read: write16(0,config) error" + error.message);
}
await sleep(10);
var v;
try {
v = await this.i2cSlave.read16(0);
} catch (error) {
throw new Error("ADS1015.read: read16(0) error" + error.message);
}
var vH = (v & 0x00ff) << 8;
var vL = (v >> 8) & 0x00ffff;
var value = (vH | vL) >> 4;
return value;
}
};

Expand Down
7 changes: 5 additions & 2 deletions packages/ads1x15/ads1x15.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// 2018/12/22 Satoru Takagi
// 2019/10/01 Support Differential Mode

/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var ADS1x15 = function(i2cPort,slaveAddress){
this.i2cPort = i2cPort;
this.slaveAddress = slaveAddress;
Expand Down Expand Up @@ -36,9 +39,9 @@
console.log("set amplifier to +-" + this.amplifierTable[this.amplifierConf]);
var i2cSlave = await this.i2cPort.open(this.slaveAddress);
this.i2cSlave = i2cSlave;
} catch(err){
} catch(error){
console.log("ADS1015.init() Error: "+error.message);
throw Error( err );
throw Error(error);
}
},
read: async function(channel){
Expand Down
3 changes: 3 additions & 0 deletions packages/ak8963/ak8963.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// Ported from https://github.com/tuupola/micropython-mpu9250/blob/master/ak8963.py
// by Satoru Takagi

/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var AK8963 = function(i2cPort,slaveAddress){
this.devConst={
_WIA : (0x00),
Expand Down
5 changes: 4 additions & 1 deletion packages/bh1750/bh1750.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
// ported from https://gist.github.com/oskar456/95c66d564c58361ecf9f
// by Satoru Takagi

var BH1750 = function(i2cPort,slaveAddress){
/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var BH1750 = function (i2cPort, slaveAddress) {
this.digP = [];
this.i2cPort = i2cPort;
this.i2cSlave = null;
Expand Down
5 changes: 3 additions & 2 deletions packages/grove-oled-display/grove-oled-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(global = global || self, global.OledDisplay = factory());
}(this, (function () { 'use strict';

// @ts-check
// Source : http://wiki.seeedstudio.com/wiki/Grove_-_OLED_Display_128*64

const OLED_CONST = {
Expand Down Expand Up @@ -184,12 +185,12 @@
this.registerQueue(OLED_CONST.commandMode,Brightness);
},
setHorizontalModeQ: function(){
this.addressingMode = horizontalMode;
this.addressingMode = OLED_CONST.horizontalMode;
this.registerQueue(OLED_CONST.commandMode,0x20);
this.registerQueue(OLED_CONST.commandMode,0);
},
setPageModeQ: function(){
this.addressingMode = pageMode;
this.addressingMode = OLED_CONST.pageMode;
this.registerQueue(OLED_CONST.commandMode,0x20);
this.registerQueue(OLED_CONST.commandMode,0x02);
},
Expand Down
5 changes: 4 additions & 1 deletion packages/ina219/ina219.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// Ported from https://github.com/chrisb2/pi_ina219
// Programmed by Satoru Takagi

/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var INA219 = function(i2cPort, slaveAddress) {
if (!slaveAddress) {
slaveAddress = 0x40;
Expand Down Expand Up @@ -226,7 +229,7 @@
this.__GAIN_VOLTS[gain]
);
await this._configure_gain(gain);
sleep(1);
await sleep(1);
} else {
console.log("Device limit reach, gain cannot be increased");
throw "DeviceRangeError: " + this.__GAIN_VOLTS[gain];
Expand Down
4 changes: 4 additions & 0 deletions packages/mlx90614/mlx90614.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
(global = global || self, global.MLX90614 = factory());
}(this, (function () { 'use strict';

// @ts-check
// MLX90614 pyro termometer driver for CHIRIMEN raspberry pi3
// Temperature and Humidity I2C Sensor
// based on https://github.com/CRImier/python-MLX90614/blob/master/mlx90614.py
// Programmed by Satoru Takagi

/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var MLX90614 = function(i2cPort, slaveAddress) {
if (!slaveAddress) {
slaveAddress = 0x5a;
Expand Down
6 changes: 1 addition & 5 deletions packages/vl53l0x/vl53l0x.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

VL53L0X.prototype = {
_decode_timeout: function(val) {
return (val & 0xff) * math.pow(2.0, (val & 0xff00) >> 8) + 1;
return (val & 0xff) * Math.pow(2.0, (val & 0xff00) >> 8) + 1;
},
_encode_timeout: function(timeout_mclks) {
var timeout_mclks = timeout_mclks & 0xffff;
Expand Down Expand Up @@ -529,10 +529,6 @@
macro_period_ns
);
},
_decode_timeout: function(val) {
// format: "(LSByte * 2^MSByte) + 1"
return (val & 0xff) * Math.pow(2.0, (val & 0xff00) >> 8) + 1;
},
_get_spad_info: async function() {
// # Get reference SPAD count and type, returned as a 2-tuple of
// # count and boolean is_aperture. Based on code from:
Expand Down
17 changes: 8 additions & 9 deletions packages/vl53l1x/vl53l1x.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// Not VL53L0X driver
// Programmed by Satoru Takagi

/** @param {number} ms Delay for a number of milliseconds. */
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

var VL53L1X = function(i2cPort, slaveAddress) {
if (!slaveAddress) {
slaveAddress = 0x29;
Expand Down Expand Up @@ -1219,7 +1222,7 @@
VL53L1X.prototype = {
init: async function(mode, io_2v8) {
this.i2cSlave = await this.i2cPort.open(this.slaveAddress);
sleep(10);
await sleep(10);
if ((await this.readReg16Bit(this.IDENTIFICATION__MODEL_ID)) != 0xeacc) {
throw "Failed to find expected ID register values. Check wiring!";
} else {
Expand Down Expand Up @@ -1250,8 +1253,8 @@
// VL53L1_DataInit() begin
if (io_2v8) {
await this.writeReg(
PAD_I2C_HV__EXTSUP_CONFIG,
(await this.readReg(PAD_I2C_HV__EXTSUP_CONFIG)) | 0x01
this.PAD_I2C_HV__EXTSUP_CONFIG,
(await this.readReg(this.PAD_I2C_HV__EXTSUP_CONFIG)) | 0x01
);
}

Expand Down Expand Up @@ -1495,7 +1498,7 @@
await this.setMeasurementTimingBudget(budget_us);
// console.log("budget_us:",budget_us);
// save mode so it can be returned by getDistanceMode()
distance_mode = mode;
this.distance_mode = mode;
return true;
},

Expand Down Expand Up @@ -1621,11 +1624,7 @@
var IntPol = await this.getInterruptPolarity();
var Temp = await this.readReg(this.GPIO__TIO_HV_STATUS);
// console.log("IntPol,GPIO__TIO_HV_STATUS : ",IntPol,Temp);
if ((Temp & 1) == IntPol) {
isDataReady = 1;
} else {
isDataReady = 0;
}
var isDataReady = (Temp & 1) == IntPol ? 1 : 0;
return isDataReady;
},
getInterruptPolarity: async function() {
Expand Down

0 comments on commit 3292080

Please sign in to comment.