mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
2 lines
736 B
JavaScript
2 lines
736 B
JavaScript
function c(b,e,d){this.r=b;this.w=e;this.options=d;if(this.r(a.WHO_AM_I,1)[0]!=a.WHO_AM_I_VALUE)throw"BH1745 WHO_AM_I check failed";this.w(a.MODE_CONTROL1,f.indexOf(160));this.w(a.MODE_CONTROL2,16);this.w(a.MODE_CONTROL3,2)}var a={WHO_AM_I:146,WHO_AM_I_VALUE:224,SYSTEM_CONTROL:64,MODE_CONTROL1:65,MODE_CONTROL2:66,MODE_CONTROL3:68,RED_DATA_LSB:80,INTERRUPT:96},f=[160,320,640,1280,2560,5120];c.prototype.stop=function(){this.w(a.MODE_CONTROL2,0)};c.prototype.read=function(){var b=this.r(a.RED_DATA_LSB,
|
|
8);return{r:b[0]<<8|b[1],g:b[2]<<8|b[3],b:b[4]<<8|b[5],c:b[6]<<8|b[7]}};exports.connectI2C=function(b,a){a=a||{};var d=a.addr||56;return new c(function(a,c){b.writeTo(d,a);return b.readFrom(d,c)},function(a,c){b.writeTo(d,a,c)},a)} |