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 e(a,c,d){this.r=a;this.w=c;this.options=d;if(this.r(b.WHO_AM_I,1)[0]!=b.WHO_AM_I_VALUE)throw"BH1745 WHO_AM_I check failed";this.w(b.MODE_CONTROL1,h.indexOf(160));this.w(b.MODE_CONTROL2,16);this.w(b.MODE_CONTROL3,2)}var b={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},h=[160,320,640,1280,2560,5120];e.prototype.stop=function(){this.w(b.MODE_CONTROL2,0)};e.prototype.read=function(){var a=
|
|
this.r(b.RED_DATA_LSB,8);return{r:a[0]<<8|a[1],g:a[2]<<8|a[3],b:a[4]<<8|a[5],c:a[6]<<8|a[7]}};exports.connectI2C=function(a,c){c=c||{};var d=c.addr||56;return new e(function(f,g){a.writeTo(d,f);return a.readFrom(d,g)},function(f,g){a.writeTo(d,f,g)},c)} |