You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Looks good - there are a few bits you need though:

    • i2c_address could be in C.i2c_address as it's just a constant
    • You need to fill in the values in the C structures, but I guess this is kind of a work in progress?
    • To define a constructor function up the top: function DS3231(_i2c) { this.i2c = _i2c; }
    • Replace every occurrance of I2C1 with this.i2c
    • You need to export it at the end. With Espruino I generally export a function called connect, which takes the device name that you attach it to. For example: exports.connect = function(i2c) { return new DS3231(i2c); }

    Then to use it, you just do var rtc = require("DS3231").connect(I2C1)

    To test it, I'd just put exports = {}; right at the top, and var rtc = exports.connect(I2C1) at the bottom instead of the require. Then, you can develop it all on the right-hand side of the Web IDE.

About

Avatar for Gordon @Gordon started