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,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,GACjB,CAAC,EAAK,EAAG,EAAK,EAAG,KAClB,GAIE,GACH,KAAK,kBAAkB,KAAK,WAE9B,EAGA,KAAK,UAAU,YAAc,SAAS,EAAK,EAAO,GAChD,IACI,EAAS,GAEb,OAAQ,GACN,IAAK,QACH,EAAO,KAAK,KAAK,yBAA0B,MAC7C,IAAK,OACH,EAAO,KAAK,KAAK,wBAAyB,MAC5C,IAAK,gBACH,EAAO,KACL,KAAK,yBACL,EACA,KAAK,OACL,KAAK,oCACL,EACA,EACA,EACA,EACA,EACA,KAAK,iBAEP,MACF,IAAK,iBACH,EAAO,KACL,KAAK,yBACL,EACA,KAAK,OACL,KAAK,qCACL,EACA,EACA,EACA,EACA,EACA,KAAK,iBAKX,KAAK,gBAAgB,WACR,UAAR,GAA2B,SAAR,GACpB,EAAO,KACL,EAAM,EACN,EAAM,EACN,EAAM,IACN,KAAK,iBAIT,IAAI,EAAG,EAAY,EAAO,OAE1B,IAAK,EAAI,EAAG,EAAI,EAAW,GAAK,EAC9B,KAAK,UAAU,MAAO,EAAO,GAEjC,EAAE,KAAK,MACT,EAGA,KAAK,UAAU,WAAa,WAC1B,KAAK,UAAU,MAAO,KAAK,kBAC7B,EAEA,OAAO,QAAU","file":"/npm/oled-ssd1306-i2c@1.0.6/oled.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/oled-ssd1306-i2c@1.0.6/oled.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var i2c = require('i2c');\n\nvar Oled = function(opts) {\n\n  if (opts == null) {\n    opts = {}\n  }\n\n  this.HEIGHT = opts.height || 32;\n  this.WIDTH = opts.width || 128;\n  this.ADDRESS = opts.address || 0x3C;\n  this.DEVICE = opts.device || '/dev/i2c-1';\n  this.MICROVIEW = opts.microview || false;\n\n  // create command buffers\n  this.DISPLAY_OFF = 0xAE;\n  this.DISPLAY_ON = 0xAF;\n  this.SET_DISPLAY_CLOCK_DIV = 0xD5;\n  this.SET_MULTIPLEX = 0xA8;\n  this.SET_DISPLAY_OFFSET = 0xD3;\n  this.SET_START_LINE = 0x00;\n  this.CHARGE_PUMP = 0x8D;\n  this.MEMORY_MODE = 0x20;\n  this.SEG_REMAP = 0xA1; // using 0xA0 will flip screen\n  this.COM_SCAN_DEC = 0xC8;\n  this.COM_SCAN_INC = 0xC0;\n  this.SET_COM_PINS = 0xDA;\n  this.SET_CONTRAST = 0x81;\n  this.SET_PRECHARGE = 0xd9;\n  this.SET_VCOM_DETECT = 0xDB;\n  this.DISPLAY_ALL_ON_RESUME = 0xA4;\n  this.NORMAL_DISPLAY = 0xA6;\n  this.COLUMN_ADDR = 0x21;\n  this.PAGE_ADDR = 0x22;\n  this.INVERT_DISPLAY = 0xA7;\n  this.ACTIVATE_SCROLL = 0x2F;\n  this.DEACTIVATE_SCROLL = 0x2E;\n  this.SET_VERTICAL_SCROLL_AREA = 0xA3;\n  this.RIGHT_HORIZONTAL_SCROLL = 0x26;\n  this.LEFT_HORIZONTAL_SCROLL = 0x27;\n  this.VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29;\n  this.VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A;\n\n  this.cursor_x = 0;\n  this.cursor_y = 0;\n\n  // new blank buffer\n  this.buffer = new Buffer((this.WIDTH * this.HEIGHT) / 8);\n  this.buffer.fill(0x00);\n\n  this.dirtyBytes = [];\n\n  var config = {\n    '128x32': {\n      'multiplex': 0x1F,\n      'compins': 0x02,\n      'coloffset': 0\n    },\n    '128x64': {\n      'multiplex': 0x3F,\n      'compins': 0x12,\n      'coloffset': 0\n    },\n    '96x16': {\n      'multiplex': 0x0F,\n      'compins': 0x2,\n      'coloffset': 0,\n    },\n    // this is blended microview / normal 64 x 48, currently wip\n    '64x48': {\n      'multiplex': 0x2F,\n      'compins': 0x12,\n      'coloffset': (this.MICROVIEW) ? 32 : 0\n    },\n};\n\n  // Setup i2c\n  this.wire = new i2c(this.ADDRESS, {device: this.DEVICE});\n\n  var screenSize = this.WIDTH + 'x' + this.HEIGHT;\n  this.screenConfig = config[screenSize];\n\n  this._initialise();\n};\n\nOled.prototype._initialise = function() {\n\n  // sequence of bytes to initialise with\n  var initSeq = [\n    this.DISPLAY_OFF,\n    this.SET_DISPLAY_CLOCK_DIV, 0x80,\n    this.SET_MULTIPLEX, this.screenConfig.multiplex, // set the last value dynamically based on screen size requirement\n    this.SET_DISPLAY_OFFSET, 0x00, // sets offset pro to 0\n    this.SET_START_LINE,\n    this.CHARGE_PUMP, 0x14, // charge pump val\n    this.MEMORY_MODE, 0x00, // 0x0 act like ks0108\n    this.SEG_REMAP, // screen orientation\n    this.COM_SCAN_DEC, // screen orientation change to INC to flip\n    this.SET_COM_PINS, this.screenConfig.compins, // com pins val sets dynamically to match each screen size requirement\n    this.SET_CONTRAST, 0x8F, // contrast val\n    this.SET_PRECHARGE, 0xF1, // precharge val\n    this.SET_VCOM_DETECT, 0x40, // vcom detect\n    this.DISPLAY_ALL_ON_RESUME,\n    this.NORMAL_DISPLAY,\n    this.DISPLAY_ON\n  ];\n\n  var i, initSeqLen = initSeq.length;\n\n  // write init seq commands\n  for (i = 0; i < initSeqLen; i ++) {\n    this._transfer('cmd', initSeq[i]);\n  }\n};\n\n// writes both commands and data buffers to this device\nOled.prototype._transfer = function(type, val) {\n  var control;\n  if (type === 'data') {\n    control = 0x40;\n  } else if (type === 'cmd') {\n    control = 0x00;\n  } else {\n    return;\n  }\n\n  this.wire.writeBytes(control, [val], function () {});\n};\n\n// read a byte from the oled\nOled.prototype._readI2C = function(fn) {\n  this.wire.readByte(function(err, data) {\n    fn(data);\n  });\n};\n\n// sometimes the oled gets a bit busy with lots of bytes.\n// Read the response byte to see if this is the case\nOled.prototype._waitUntilReady = function(callback) {\n  var done,\n      oled = this;\n\n  function tick(callback) {\n    oled._readI2C(function(byte) {\n      // read the busy byte in the response\n      busy = byte >> 7 & 1;\n      if (!busy) {\n        // if not busy, it's ready for callback\n        callback();\n      } else {\n        setTimeout(tick, 0);\n      }\n    });\n  }\n\n  setTimeout(tick(callback), 0);\n};\n\n// set starting position of a text string on the oled\nOled.prototype.setCursor = function(x, y) {\n  this.cursor_x = x;\n  this.cursor_y = y;\n};\n\n// write text to the oled\nOled.prototype.writeString = function(font, size, string, color, wrap, linespacing, sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n  var wordArr = string.split(' '),\n      len = wordArr.length,\n      // start x offset at cursor pos\n      offset = this.cursor_x,\n      padding = 0, letspace = 1;\n  var leading = linespacing || 2;\n\n  // loop through words\n  for (var w = 0; w < len; w += 1) {\n    // put the word space back in\n    wordArr[w] += ' ';\n    var stringArr = wordArr[w].split(''),\n        slen = stringArr.length,\n        compare = (font.width * size * slen) + (size * (len -1));\n\n    // wrap words if necessary\n    if (wrap && len > 1 && (offset >= (this.WIDTH - compare)) ) {\n      offset = 1;\n      this.cursor_y += (font.height * size) + size + leading;\n      this.setCursor(offset, this.cursor_y);\n    }\n\n    // loop through the array of each char to draw\n    for (var i = 0; i < slen; i += 1) {\n      // look up the position of the char, pull out the buffer slice\n      var charBuf = this._findCharBuf(font, stringArr[i]);\n      // read the bits in the bytes that make up the char\n      var charBytes = this._readCharBytes(charBuf);\n      // draw the entire character\n      this._drawChar(font, charBytes, size, false);\n\n      // calc new x position for the next char, add a touch of padding too if it's a non space char\n      padding = (stringArr[i] === ' ') ? 0 : size + letspace;\n      offset += (font.width * size) + padding;\n\n      // wrap letters if necessary\n      if (wrap && (offset >= (this.WIDTH - font.width - letspace))) {\n        offset = 1;\n        this.cursor_y += (font.height * size) + size + leading;\n      }\n      // set the 'cursor' for the next char to be drawn, then loop again for next char\n      this.setCursor(offset, this.cursor_y);\n    }\n  }\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n// draw an individual character to the screen\nOled.prototype._drawChar = function(font, byteArray, size, sync) {\n  // take your positions...\n  var x = this.cursor_x,\n      y = this.cursor_y;\n\n  var pagePos = 0;\n  var c = 0;\n  // loop through the byte array containing the hexes for the char\n  for (var i = 0; i < byteArray.length; i += 1) {\n    pagePos = Math.floor(i / font.width) * 8;\n    for (var j = 0; j < 8; j += 1) {\n      // pull color out\n      var color = byteArray[i][j],\n          xpos, ypos;\n      // standard font size\n      if (size === 1) {\n        xpos = x + c;\n        ypos = y + j + pagePos;\n        this.drawPixel([xpos, ypos, color], false);\n      } else {\n        // MATH! Calculating pixel size multiplier to primitively scale the font\n        xpos = x + (i * size);\n        ypos = y + (j * size);\n        this.fillRect(xpos, ypos, size, size, color, false);\n      }\n    }\n    c = (c < font.width -1) ? c += 1 : 0;\n  }\n};\n\n// get character bytes from the supplied font object in order to send to framebuffer\nOled.prototype._readCharBytes = function(byteArray) {\n  var bitArr = [],\n      bitCharArr = [];\n  // loop through each byte supplied for a char\n  for (var i = 0; i < byteArray.length; i += 1) {\n    // set current byte\n    var byte = byteArray[i];\n    // read each byte\n    for (var j = 0; j < 8; j += 1) {\n      // shift bits right until all are read\n      var bit = byte >> j & 1;\n      bitArr.push(bit);\n    }\n    // push to array containing flattened bit sequence\n    bitCharArr.push(bitArr);\n    // clear bits for next byte\n    bitArr = [];\n  }\n  return bitCharArr;\n};\n\n// find where the character exists within the font object\nOled.prototype._findCharBuf = function(font, c) {\n  // use the lookup array as a ref to find where the current char bytes start\n  var cBufPos = font.lookup.indexOf(c) * font.width;\n  // slice just the current char's bytes out of the fontData array and return\n  var cBuf = font.fontData.slice(cBufPos, cBufPos + font.width);\n  return cBuf;\n};\n\n// send the entire framebuffer to the oled\nOled.prototype.update = function() {\n  // wait for oled to be ready\n  this._waitUntilReady(function() {\n    // set the start and endbyte locations for oled display update\n    var displaySeq = [\n      this.COLUMN_ADDR,\n      this.screenConfig.coloffset,\n      this.screenConfig.coloffset + this.WIDTH - 1, // column start and end address\n      this.PAGE_ADDR, 0, (this.HEIGHT / 8) - 1 // page start and end address\n    ];\n\n    var displaySeqLen = displaySeq.length,\n        bufferLen = this.buffer.length,\n        i, v;\n\n    // send intro seq\n    for (i = 0; i < displaySeqLen; i += 1) {\n      this._transfer('cmd', displaySeq[i]);\n    }\n\n    // write buffer data\n    for (v = 0; v < bufferLen; v += 1) {\n      this._transfer('data', this.buffer[v]);\n    }\n\n  }.bind(this));\n\n  // now that all bytes are synced, reset dirty state\n  this.dirtyBytes = [];\n};\n\n// send dim display command to oled\nOled.prototype.dimDisplay = function(bool) {\n  var contrast;\n\n  if (bool) {\n    contrast = 0; // Dimmed display\n  } else {\n    contrast = 0xCF; // Bright display\n  }\n\n  this._transfer('cmd', this.SET_CONTRAST);\n  this._transfer('cmd', contrast);\n};\n\n// turn oled off\nOled.prototype.turnOffDisplay = function() {\n  this._transfer('cmd', this.DISPLAY_OFF);\n};\n\n// turn oled on\nOled.prototype.turnOnDisplay = function() {\n  this._transfer('cmd', this.DISPLAY_ON);\n};\n\n// clear all pixels currently on the display\nOled.prototype.clearDisplay = function(sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n  // write off pixels\n  //this.buffer.fill(0x00);\n  for (var i = 0; i < this.buffer.length; i += 1) {\n    if (this.buffer[i] !== 0x00) {\n      this.buffer[i] = 0x00;\n      if (this.dirtyBytes.indexOf(i) === -1) {\n        this.dirtyBytes.push(i);\n      }\n    }\n  }\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n// invert pixels on oled\nOled.prototype.invertDisplay = function(bool) {\n  if (bool) {\n    this._transfer('cmd', this.INVERT_DISPLAY); // inverted\n  } else {\n    this._transfer('cmd', this.NORMAL_DISPLAY); // non inverted\n  }\n};\n\n// draw an image pixel array on the screen\nOled.prototype.drawBitmap = function(pixels, sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n  var x, y,\n      pixelArray = [];\n\n  for (var i = 0; i < pixels.length; i++) {\n    x = Math.floor(i % this.WIDTH);\n    y = Math.floor(i / this.WIDTH);\n\n    this.drawPixel([x, y, pixels[i]], false);\n  }\n\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n// draw one or many pixels on oled\nOled.prototype.drawPixel = function(pixels, sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n\n  // handle lazy single pixel case\n  if (typeof pixels[0] !== 'object') pixels = [pixels];\n\n  pixels.forEach(function(el) {\n    // return if the pixel is out of range\n    var x = el[0], y = el[1], color = el[2];\n    if (x > this.WIDTH || y > this.HEIGHT) return;\n\n    // thanks, Martin Richards.\n    // I wanna can this, this tool is for devs who get 0 indexes\n    //x -= 1; y -=1;\n    var byte = 0,\n        page = Math.floor(y / 8),\n        pageShift = 0x01 << (y - 8 * page);\n\n    // is the pixel on the first row of the page?\n    (page == 0) ? byte = x : byte = x + (this.WIDTH * page);\n\n    // colors! Well, monochrome.\n    if (color === 'BLACK' || color === 0) {\n      this.buffer[byte] &= ~pageShift;\n    }\n    if (color === 'WHITE' || color > 0) {\n      this.buffer[byte] |= pageShift;\n    }\n\n    // push byte to dirty if not already there\n    if (this.dirtyBytes.indexOf(byte) === -1) {\n      this.dirtyBytes.push(byte);\n    }\n\n  }, this);\n\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n// looks at dirty bytes, and sends the updated bytes to the display\nOled.prototype._updateDirtyBytes = function(byteArray) {\n  var blen = byteArray.length, i,\n      displaySeq = [];\n\n  this._waitUntilReady(function() {\n\t  var pageStart = Infinity, pageEnd = 0;\n    var colStart = Infinity, colEnd = 0, any = false;\n\n    // iterate through dirty bytes\n    for (var i = 0; i < blen; i += 1) {\n      var b = byteArray[i];\n      if ((b >= 0) && (b < this.buffer.length)) {\n        var page = b / this.WIDTH | 0;\n        if (page < pageStart) pageStart = page;\n        if (page > pageEnd) pageEnd = page;\n        var col = b % this.WIDTH;\n        if (col < colStart) colStart = col;\n        if (col > colEnd) colEnd = col;\n        any = true;\n      }\n    }\n\n    if (!any) return;\n\n    displaySeq = [\n      this.COLUMN_ADDR, colStart, colEnd, // column start and end address\n      this.PAGE_ADDR, pageStart, pageEnd // page start and end address\n    ];\n\n    var displaySeqLen = displaySeq.length, v, vp, vc;\n\n    // send intro seq\n    for (v = 0; v < displaySeqLen; v += 1) {\n      this._transfer('cmd', displaySeq[v]);\n    }\n    // send byte, then move on to next byte\n    for (vp = pageStart; vp <= pageEnd; vp += 1) {\n      for (vc = colStart; vc <= colEnd; vc += 1) {\n        this._transfer('data', this.buffer[this.WIDTH * vp + vc]);\n      }\n    }\n\n  }.bind(this));\n\n  // now that all bytes are synced, reset dirty state\n  this.dirtyBytes = [];\n};\n\n// using Bresenham's line algorithm\nOled.prototype.drawLine = function(x0, y0, x1, y1, color, sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n\n  var dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1,\n      dy = Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1,\n      err = (dx > dy ? dx : -dy) / 2;\n\n  while (true) {\n    this.drawPixel([x0, y0, color], false);\n\n    if (x0 === x1 && y0 === y1) break;\n\n    var e2 = err;\n\n    if (e2 > -dx) {err -= dy; x0 += sx;}\n    if (e2 < dy) {err += dx; y0 += sy;}\n  }\n\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n}\n\n// Draw an outlined  rectangle\nOled.prototype.drawRect = function(x, y, w, h, color, sync){\n  var immed = (typeof sync === 'undefined') ? true : sync;\n  //top \n  this.drawLine(x, y, x + w, y,color,false);\n\n  //left\n  this.drawLine(x, y + 1, x, y + h - 1, color, false);\n\n  //right\n  this.drawLine(x + w, y + 1, x + w, y + h - 1, color, false);\n\n  //bottom\n  this.drawLine(x, y + h - 1, x + w, y + h - 1, color, false);\n\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n// draw a filled rectangle on the oled\nOled.prototype.fillRect = function(x, y, w, h, color, sync) {\n  var immed = (typeof sync === 'undefined') ? true : sync;\n  // one iteration for each column of the rectangle\n  for (var i = x; i < x + w; i += 1) {\n    // draws a vert line\n    this.drawLine(i, y, i, y+h-1, color, false);\n  }\n  if (immed) {\n    this._updateDirtyBytes(this.dirtyBytes);\n  }\n};\n\n/**\n * Draw a circle outline\n *\n * This method is ad verbatim translation from the corresponding\n * method on the Adafruit GFX library\n * https://github.com/adafruit/Adafruit-GFX-Library\n */\nOled.prototype.drawCircle = function(x0, y0, r, color, sync) {\n\tvar immed = (typeof sync === 'undefined') ? true : sync;\n\n\tvar f = 1 - r;\n\tvar ddF_x = 1;\n\tvar ddF_y = -2 * r;\n\tvar x = 0;\n\tvar y = r;\n\n\tthis.drawPixel(\n\t\t[[x0, y0 + r, color],\n\t\t\t[x0, y0 - r, color],\n\t\t\t[x0 + r, y0, color],\n\t\t\t[x0 - r, y0, color]],\n\t\tfalse\n\t);\n\n\twhile(x < y) {\n\t\tif (f >=0) {\n\t\t\ty--;\n\t\t\tddF_y += 2;\n\t\t\tf += ddF_y;\n\t\t}\n\t\tx++;\n\t\tddF_x += 2;\n\t\tf += ddF_x;\n\n\t\tthis.drawPixel(\n\t\t\t[[x0 + x, y0 + y, color],\n\t\t\t\t[x0 - x, y0 + y, color],\n\t\t\t\t[x0 + x, y0 - y, color],\n\t\t\t\t[x0 - x, y0 - y, color],\n\t\t\t\t[x0 + y, y0 + x, color],\n\t\t\t\t[x0 - y, y0 + x, color],\n\t\t\t\t[x0 + y, y0 - x, color],\n\t\t\t\t[x0 - y, y0 - x, color]],\n\t\t\tfalse\n\t\t);\n\t}\n\n\tif (immed) {\n\t\tthis._updateDirtyBytes(this.dirtyBytes);\n\t}\n};\n\n// activate scrolling for rows start through stop\nOled.prototype.startScroll = function(dir, start, stop) {\n  var scrollHeader,\n      cmdSeq = [];\n\n  switch (dir) {\n    case 'right':\n      cmdSeq.push(this.RIGHT_HORIZONTAL_SCROLL); break;\n    case 'left':\n      cmdSeq.push(this.LEFT_HORIZONTAL_SCROLL); break;\n    case 'left diagonal':\n      cmdSeq.push(\n        this.SET_VERTICAL_SCROLL_AREA,\n        0x00,\n        this.HEIGHT,\n        this.VERTICAL_AND_LEFT_HORIZONTAL_SCROLL,\n        0x00,\n        start,\n        0x00,\n        stop,\n        0x01,\n        this.ACTIVATE_SCROLL\n      );\n      break;\n    case 'right diagonal':\n      cmdSeq.push(\n        this.SET_VERTICAL_SCROLL_AREA,\n        0x00,\n        this.HEIGHT,\n        this.VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL,\n        0x00,\n        start,\n        0x00,\n        stop,\n        0x01,\n        this.ACTIVATE_SCROLL\n      );\n      break;\n  }\n\n  this._waitUntilReady(function() {\n    if(dir === 'right' || dir === 'left'){\n      cmdSeq.push(\n        0x00, start,\n        0x00, stop,\n        0x00, 0xFF,\n        this.ACTIVATE_SCROLL\n      );\n    }\n\n    var i, cmdSeqLen = cmdSeq.length;\n\n    for (i = 0; i < cmdSeqLen; i += 1) {\n      this._transfer('cmd', cmdSeq[i]);\n    }\n  }.bind(this));\n};\n\n// stop scrolling display contents\nOled.prototype.stopScroll = function() {\n  this._transfer('cmd', this.DEACTIVATE_SCROLL); // stahp\n};\n\nmodule.exports = Oled;\n"]}