MPU6050.js as local module

Posted on
  • I was able to use the online MPU_6050 module in my project, and now I want to use it as a local module, so I can edit it. I set up my sandbox, and followed the process here: http://forum.espruino.com/conversations/286424/

    I copied MPU_6050.js to my sandbox\modules folder and names it "MPU_b.js". Then I tried the following project code:

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    var mpu, mpuM = require("MPU_b")
    function onInit() {
      mpu = mpuM.connect(I2C1);
    }
    

    but I'm getting an error:

    Uncaught SyntaxError: Got '=' expected ','
     at line 263 col 65
    ...ction(bank, prefetchEnabled=false, userBank=false) {
    

    Is the online MPU_6050.js not formatted correctly to be used as a local module? Do I need to modify it, or change settings so I can load it in my project?

  • That's an issue with default parameter values. Online, the actual code uploaded by the IDE is the minified one but that doesn't have the default parameter value.

    As a workaround, change the MPU6050.prototype.setMemoryBank = function(bank, prefetchEnabled=false, userBank=false) { line to MPU6050.prototype.setMemoryBank = function(bank, prefetchEnabled, userBank) {

  • ...that's quite bad implementation in the original module... What do I miss here?

    Is the minified version not the minification of the non minified version?

    ...may be the minification does something Espruino (lesser ES version cannot do and it is 'shimmed' in the minification process...) has not implementd.

  • Fri 2019.12.20

    Could the missing semicolon L2 be causing a parse issue with the module?

  • That change to the code was the answer. The MPU_6050 module is working as local module now, and I can edit it. Thansks @AkosLukacs

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

MPU6050.js as local module

Posted by Avatar for barrier @barrier

Actions