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U,SAAW,SAAS,EAAG,EAAG,EAAO,GAC9C,KAAK,QAAQ,SAAS,EAAG,EAAG,EAAI,EAAQ,EAAG,EAAI,EAAS,EAC5D,EAUA,UAAU,UAAY,OAAO,OAAO,OAAO,WAC3C,UAAU,UAAU,YAAc,OAOlC,UAAU,UAAU,WAAa,SAAS,GACtC,IAAI,EAAQ,GACZ,EAAW,SAAQ,SAAS,GACxB,EAAM,KAAK,GACX,EAAM,KAAK,EACf,IACA,KAAK,QAAQ,OAAS,IAAI,WAAW,EACzC,EAMA,UAAU,UAAU,OAAS,WACzB,KAAK,QAAQ,KAAK,QAAS,EAExB,IAAK,WAAW,KAAK,QAAQ,QAAS,IAAI,KAAK,QAEtD,EAEA,OAAO,QAAQ,UAAY,UAU3B,WAAW,UAAY,OAAO,OAAO,OAAO,WAC5C,WAAW,UAAU,YAAc,OAgBnC,WAAW,UAAU,WAAa,SAAS,GACvC,IAAI,EAAQ,GACZ,EAAW,SAAQ,SAAS,GACxB,EAAM,KAAK,EACf,IACA,KAAK,QAAQ,OAAS,IAAI,WAAW,EACzC,EAEA,OAAO,QAAQ,WAAa","file":"/npm/espruino-adafruit-led-backpack@1.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/espruino-adafruit-led-backpack@1.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * Constructor for Adafruit LED Matrix Backpacks which can be used as a base for 8x8 and 16x8 matrices.\n * Provides drawing capabilities like the Adafruit Arduino Library API.\n *\n * @param options. An object literal with the keys of `scl` and `sda` for the clock and data I2C pins. The option `address`\n * is a hexadecimal address of the device. A 7-bit address between 0x70-0x77. The key `brightness` is a number 0 through 15.\n * @constructor\n */\nfunction Matrix(options) {\n    if(typeof options.scl === \"undefined\" ||\n        typeof options.sda === \"undefined\" ||\n        typeof options.brightness === \"undefined\" ||\n        typeof options.address === \"undefined\") {\n        throw new Error(\"Required option of `scl`, `sda`, `brightness` and/or `address` is missing.\");\n    }\n    this.address = options.address;\n    I2C1.setup({scl: options.scl, sda: options.sda });\n    I2C1.writeTo(this.address, 0x21); // turn on oscillator\n    I2C1.writeTo(this.address, 0x81); // disp on\n    this.setBrightness(options.brightness);\n    this.context = Graphics.createArrayBuffer(16,8,1);\n}\n\n\n/**\n * Set the brightnes of the LEDs. A number 0 through 15.\n * @param brightness\n */\nMatrix.prototype.setBrightness = function(brightness) {\n    // brightness 0-15\n    I2C1.writeTo(this.address, 0xE0 | brightness);\n};\n\n\n/**\n * Renders buffer/graphics context to the display.\n */\nMatrix.prototype.render = function() {\n    I2C1.writeTo(this.address, 0, this.context.buffer);\n};\n\n\n/**\n * Rotates an 8-bit binary value right one bit.\n *\n * Example: 0b00000011 -> 0b10000001\n *\n * @param value. 8-bit unsidgned integer (0-127).\n * @returns {uint8} rotated value\n */\nMatrix.prototype.rotate = function(value) {\n    //Shift everything right 1 bit\n    //Then shift last bit over if switched on it'll switch on 2^7\n    var rotated = (value >> 1) | (value << 7);\n    //Casting the 16-bit integer to 8-bit\n    var eightBitArray = new Uint8Array([rotated]);\n    //return the 8-bit value\n    return eightBitArray[0];\n};\n\n\n/**\n * Clears graphics buffer.\n */\nMatrix.prototype.clear = function() {\n    this.context.clear();\n};\n\n\n/**\n * Same as `render()`.\n */\nMatrix.prototype.writeDisplay = function(){\n    this.render();\n};\n\n\n/**\n * Draws a pixel at the co-ordinates.\n * @param x is the x co-ordinate. 0-7.\n * @param y is the y co-ordinate. 0-7.\n * @param state. 1 for on. 0 for off.\n */\nMatrix.prototype.drawPixel = function (x, y, state) {\n    this.context.setPixel(x, y, state);\n};\n\n\n/**\n * Draws a line from one set of co-ordinates to another\n *\n * @param x1 is the x value for the first set of co-ordinates\n * @param y1 is the y value for the first set of co-ordinates\n * @param x2 is the x value for the second set of co-ordinates\n * @param y2 is the y value for the second set of co-ordinates\n */\nMatrix.prototype.drawLine = function(x1, y1, x2, y2) {\n    this.context.drawLine(x1, y1, x2, y2);\n};\n\n\n/**\n * Draws a rectangle at a set of co-ordinates of a given width and height\n *\n * @param x is the x value where you want to start\n * @param y is the y value where you want to start\n * @param width is the width of the rectangle\n * @param height is the height of the rectangle\n */\nMatrix.prototype.drawRect = function(x, y, width, height) {\n    this.context.drawRect(x, y,  x + width - 1, y + height - 1);\n};\n\n\n/**\n * Draws a filled in rectangle at a set of co-ordinates of a given width and height\n * @param x is the x value where you want to start\n * @param y is the y value where you want to start\n * @param width is the width of the rectangle\n * @param height is the height of the rectangle\n */\nMatrix.prototype.fillRect = function(x, y, width, height) {\n    this.context.fillRect(x, y, x + width - 1, y + height - 1);\n};\n\n\n/**\n * Constructor for an Adafruit 8x8 LED Matrix Backpack.\n */\nfunction Matrix8x8(options) {\n    Matrix.call(this, options);\n}\n\nMatrix8x8.prototype = Object.create(Matrix.prototype);\nMatrix8x8.prototype.constructor = Matrix;\n\n\n/**\n * Writes an array of 8 8-bit values to the display graphics context\n * @param uint8array\n */\nMatrix8x8.prototype.drawBitmap = function(uint8array){\n    var array = [];\n    uint8array.forEach(function(i){\n        array.push(i);\n        array.push(i);\n    });\n    this.context.buffer = new Uint8Array(array);\n};\n\n\n/**\n * Renders buffer/graphics context to the display.\n */\nMatrix8x8.prototype.render = function() {\n    I2C1.writeTo(this.address, 0,\n       //Because of how the 8x8 Matrix is wired you need to rotate right by one bit\n       (new Uint8Array(this.context.buffer)).map(this.rotate)\n   );\n};\n\nmodule.exports.Matrix8x8 = Matrix8x8;\n\n\n/**\n * Constructor for an Adafruit 16x8 LED Matrix Backpack.\n */\nfunction Matrix16x8(options) {\n    Matrix.call(this, options);\n}\n\nMatrix16x8.prototype = Object.create(Matrix.prototype);\nMatrix16x8.prototype.constructor = Matrix;\n\n\n/**\n * Writes an array of 16 8-bit values to the display graphics context\n *\n * The first two bytes of the array represent the first line and so on.\n * This: drawBitmap([0b00000000, 0b1111111, 0b00001111, 0b00110011, ...])\n * ends up like this in a 16x8 Matrix:\n *\n * 0000000011111111\n * 0000111100110011\n * ...\n *\n * @param uint8array\n */\nMatrix16x8.prototype.drawBitmap = function(uint8array) {\n    var array = [];\n    uint8array.forEach(function(i){\n        array.push(i);\n    });\n    this.context.buffer = new Uint8Array(array);\n};\n\nmodule.exports.Matrix16x8 = Matrix16x8;"]}