Espruino/libs/js/OPT3001.min.js
2023-06-13 09:22:21 +01:00

2 lines
643 B
JavaScript

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