You are reading a single comment by @fanoush and its replies. Click here to read the full conversation.
  • Thanks. In fact I do have one P8 with BMA421 so will test. I am not good at JS so cannot comment style, just few optimization tips

    • byte/sign conversions can be done also via various JS array types, with KX023 I used something like

      var coords=new Int16Array(accRead(0x06,6).buffer);
      return {x:coords[0],y:coords[1],z:coords[2]};

      which does same thing as your lines 36-42. The array constructor with buffer shares same underlying data with no copy so you just get different view on same data (also any write to such arrays is shared so conversion can work in both directions). Of course it works only if you are sure about endianness and it matches what sensor uses. Or there is DataView­iew

    • line 103 (var config = new ...) is not needed, you replace it with the read result anyway (and you could possibly read whole file at once as discussed but it doesn't matter)


Avatar for fanoush @fanoush started