this.slaveAddress = slaveAddress; }; BME280.prototype = { init: function(){ return new Promise((resolve, reject)=>{ this.i2cPort.open(this.slaveAddress).then((i2cSlave)=>{ this.i2cSlave = i2cSlave; //console.log("init ok:"+this.i2cSlave); this.digT = []; this.digP = []; this.digH = []; this.temp = 0.0; this.pres = 0.0; this.hum = 0.0; this.t_fine = 0.0; var osrs_t = 1; // Temperature oversampling x 1 var osrs_p = 1; // Pressure oversampling x 1 var osrs_h = 1; // Humidity oversampling x 1 var mode = 3; // Normal mode var t_sb = 5; // Tstandby 1000ms var filter = 0; // Filter off var spi3w_en = 0; // 3-wire SPI Disable var ctrl_meas_reg = (osrs_t << 5) | (osrs_p << 2) | mode; var config_reg = (t_sb << 5) | (filter << 2) | spi3w_en; var ctrl_hum_reg = osrs_h; this.writeReg(0xF2,ctrl_hum_reg) this.writeReg(0xF4,ctrl_meas_reg) this.writeReg(0xF5,config_reg) resolve(); },(err)=>{ reject(err); }); }); }, writeReg: function(reg_address, data){ return new Promise(async (resolve, reject)=>{ if(this.i2cSlave == null){ reject("i2cSlave Address does'nt yet open!"); } else { await this.i2cSlave.write8(reg_address,data); resolve(); } }); }, callibParam: function(){ return new Promise(async (resolve, reject)=>{ if(this.i2cSlave == null){ reject("i2cSlave Address does'nt yet open!"); }else{ var calib = []; for(var i=0x88; i<0x88+24; i++){ calib.push(await this.i2cSlave.read8(i)); } calib.push(await this.i2cSlave.read8(0xA1)); for(i=0xE1; i<0xE1+7; i++){ calib.push(await this.i2cSlave.read8(i)); } this.digT.push((calib[1] << 8) | calib[0]); this.digT.push((calib[3] << 8) | calib[2]); this.digT.push((calib[5] << 8) | calib[4]); this.digP.push((calib[7] << 8) | calib[6]); this.digP.push((calib[9] << 8) | calib[8]); this.digP.push((calib[11]<< 8) | calib[10]); this.digP.push((calib[13]<< 8) | calib[12]); this.digP.push((calib[15]<< 8) | calib[14]); this.digP.push((calib[17]<< 8) | calib[16]); this.digP.push((calib[19]<< 8) | calib[18]); this.digP.push((calib[21]<< 8) | calib[20]); this.digP.push((calib[23]<< 8) | calib[22]); this.digH.push(calib[24]); this.digH.push((calib[26]<< 8) | calib[25]); this.digH.push(calib[27]); this.digH.push((calib[28]<< 4) | (0x0F & calib[29])); this.digH.push((calib[30]<< 4) | ((calib[29] >> 4) & 0x0F)); #.&໘͘͞ա͗