Espruino/libs/js/OPT3001.min.js
2018-06-15 15:33:19 +01:00

2 lines
643 B
JavaScript

function a(e,a,d){this.r=a;this.w=d;if(21577!=this.r(b.MANUFACTUREID))throw Error("Unexpected Manufacturer ID");if(12289!=this.r(b.DEVICEID))throw Error("Unexpected Device ID");this.on()}var b={RESULT:0,CONFIG:1,LOWLIMIT:2,HIGHLIMIT:3,MANUFACTUREID:126,DEVICEID:127};a.prototype.on=function(){this.w(b.CONFIG,52240)};a.prototype.off=function(){this.w(b.CONFIG,51216)};a.prototype.read=function(){var a=this.r(b.RESULT);return.01*((a&4095)<<(a>>12))};exports.OPT3001=a;exports.connectI2C=function(b,
c){var d=c&&c.addr||68;return new a(c,function(a){b.writeTo(d,a);a=b.readFrom(d,2);return a[1]|a[0]<<8},function(a,c){b.writeTo(d,[a,c>>8,c])})}