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c,SAAS,EAAK,EAAO,GAChD,IACI,EAAS,GAEb,OAAQ,GACN,IAAK,QACH,EAAO,KAAK,KAAK,yBAA0B,MAC7C,IAAK,OACH,EAAO,KAAK,KAAK,wBAAyB,MAE5C,IAAK,gBACH,EAAO,KACL,KAAK,yBAA0B,EAC/B,KAAK,oCACL,KAAK,QAEP,MAEF,IAAK,iBACH,EAAO,KACL,KAAK,yBAA0B,EAC/B,KAAK,qCACL,KAAK,QAKX,KAAK,gBAAgB,WACnB,EAAO,KACL,EAAM,EACN,EAAM,EAEN,EAAM,IACN,KAAK,iBAGP,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-i2c-bus@1.0.12/oled.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/oled-i2c-bus@1.0.12/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 Oled = function(i2c, opts) {\r\n\r\n  this.HEIGHT = opts.height || 32;\r\n  this.WIDTH = opts.width || 128;\r\n  this.ADDRESS = opts.address || 0x3C;\r\n  this.PROTOCOL = 'I2C';\r\n  this.LINESPACING = typeof opts.linespacing !== 'undefined' ? opts.linespacing : 1;\r\n  this.LETTERSPACING = typeof opts.letterspacing !== 'undefined' ? opts.letterspacing : 1;\r\n\r\n  // create command buffers\r\n  this.DISPLAY_OFF = 0xAE;\r\n  this.DISPLAY_ON = 0xAF;\r\n  this.SET_DISPLAY_CLOCK_DIV = 0xD5;\r\n  this.SET_MULTIPLEX = 0xA8;\r\n  this.SET_DISPLAY_OFFSET = 0xD3;\r\n  this.SET_START_LINE = 0x00;\r\n  this.CHARGE_PUMP = 0x8D;\r\n  this.EXTERNAL_VCC = false;\r\n  this.MEMORY_MODE = 0x20;\r\n  this.SEG_REMAP = 0xA1; // using 0xA0 will flip screen\r\n  this.COM_SCAN_DEC = 0xC8;\r\n  this.COM_SCAN_INC = 0xC0;\r\n  this.SET_COM_PINS = 0xDA;\r\n  this.SET_CONTRAST = 0x81;\r\n  this.SET_PRECHARGE = 0xd9;\r\n  this.SET_VCOM_DETECT = 0xDB;\r\n  this.DISPLAY_ALL_ON_RESUME = 0xA4;\r\n  this.NORMAL_DISPLAY = 0xA6;\r\n  this.COLUMN_ADDR = 0x21;\r\n  this.PAGE_ADDR = 0x22;\r\n  this.INVERT_DISPLAY = 0xA7;\r\n  this.ACTIVATE_SCROLL = 0x2F;\r\n  this.DEACTIVATE_SCROLL = 0x2E;\r\n  this.SET_VERTICAL_SCROLL_AREA = 0xA3;\r\n  this.RIGHT_HORIZONTAL_SCROLL = 0x26;\r\n  this.LEFT_HORIZONTAL_SCROLL = 0x27;\r\n  this.VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29;\r\n  this.VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A;\r\n\r\n  this.cursor_x = 0;\r\n  this.cursor_y = 0;\r\n\r\n  // new blank buffer\r\n  //For version <6.0.0\r\n  if(typeof Buffer.alloc == \"undefined\") {\r\n    this.buffer = new Buffer((this.WIDTH * this.HEIGHT) / 8);\r\n  }\r\n  //For version >=6.0.0\r\n  else {\r\n    this.buffer = Buffer.alloc((this.WIDTH * this.HEIGHT) / 8);\r\n  }\r\n  this.buffer.fill(0x00);\r\n\r\n  this.dirtyBytes = [];\r\n\r\n  var config = {\r\n    '128x32': {\r\n      'multiplex': 0x1F,\r\n      'compins': 0x02,\r\n      'coloffset': 0\r\n    },\r\n    '128x64': {\r\n      'multiplex': 0x3F,\r\n      'compins': 0x12,\r\n      'coloffset': 0\r\n    },\r\n    '96x16': {\r\n      'multiplex': 0x0F,\r\n      'compins': 0x2,\r\n      'coloffset': 0,\r\n    }\r\n  };\r\n\r\n  // Setup i2c\r\n  //console.log('this.ADDRESS: ' + this.ADDRESS);\r\n  this.wire = i2c;\r\n\r\n  var screenSize = this.WIDTH + 'x' + this.HEIGHT;\r\n  this.screenConfig = config[screenSize];\r\n\r\n  this._initialise();\r\n}\r\n\r\nOled.prototype._initialise = function() {\r\n\r\n  // sequence of bytes to initialise with\r\n  var initSeq = [\r\n    this.DISPLAY_OFF,\r\n    this.SET_DISPLAY_CLOCK_DIV, 0x80,\r\n    this.SET_MULTIPLEX, this.screenConfig.multiplex, // set the last value dynamically based on screen size requirement\r\n    this.SET_DISPLAY_OFFSET, 0x00, // sets offset pro to 0\r\n    this.SET_START_LINE,\r\n    this.CHARGE_PUMP, 0x14, // charge pump val\r\n    this.MEMORY_MODE, 0x00, // 0x0 act like ks0108\r\n    this.SEG_REMAP, // screen orientation\r\n    this.COM_SCAN_DEC, // screen orientation change to INC to flip\r\n    this.SET_COM_PINS, this.screenConfig.compins, // com pins val sets dynamically to match each screen size requirement\r\n    this.SET_CONTRAST, 0x8F, // contrast val\r\n    this.SET_PRECHARGE, 0xF1, // precharge val\r\n    this.SET_VCOM_DETECT, 0x40, // vcom detect\r\n    this.DISPLAY_ALL_ON_RESUME,\r\n    this.NORMAL_DISPLAY,\r\n    this.DISPLAY_ON\r\n  ];\r\n\r\n  var i, initSeqLen = initSeq.length;\r\n\r\n  // write init seq commands\r\n  for (i = 0; i < initSeqLen; i ++) {\r\n    this._transfer('cmd', initSeq[i]);\r\n  }\r\n}\r\n\r\n// writes both commands and data buffers to this device\r\nOled.prototype._transfer = function(type, val, fn) {\r\n  var control;\r\n  if (type === 'data') {\r\n    control = 0x40;\r\n  } else if (type === 'cmd') {\r\n    control = 0x00;\r\n  } else {\r\n    return;\r\n  }\r\n\r\n  var bufferForSend, sentCount;\r\n  //For version <6.0.0\r\n  if(typeof Buffer.from == \"undefined\") {\r\n    bufferForSend = new Buffer([control, val]);\r\n  }\r\n  //For version >=6.0.0\r\n  else {\r\n    bufferForSend = Buffer.from([control, val])\r\n  }\r\n\r\n  // send control and actual val\r\n  sentCount = this.wire.i2cWriteSync(this.ADDRESS, 2, bufferForSend);\r\n  if(fn) {\r\n    fn();\r\n  }\r\n}\r\n\r\n// read a byte from the oled\r\nOled.prototype._readI2C = function(fn) {\r\n  //For version <6.0.0\r\n  if(typeof Buffer.from == \"undefined\") {\r\n    this.wire.i2cRead(this.ADDRESS, 0, new Buffer([0]), function(err, bytesRead, data) {\r\n      // result is single byte\r\n      if(typeof data === \"object\") {\r\n        fn(data[0]);\r\n      }\r\n      else {\r\n        fn(0);\r\n      }\r\n    });\r\n  }\r\n  //For version >=6.0.0\r\n  else {\r\n    var data=[0];\r\n    this.wire.i2cReadSync(this.ADDRESS, 1, Buffer.from(data));\r\n    fn(data[0]);\r\n  }\r\n}\r\n\r\n// sometimes the oled gets a bit busy with lots of bytes.\r\n// Read the response byte to see if this is the case\r\nOled.prototype._waitUntilReady = function(callback) {\r\n  var done,\r\n      oled = this;\r\n\r\n  function tick(callback) {\r\n    oled._readI2C(function(byte) {\r\n      // read the busy byte in the response\r\n      busy = byte >> 7 & 1;\r\n      if (!busy) {\r\n        // if not busy, it's ready for callback\r\n        callback();\r\n      } else {\r\n        setTimeout(function () {tick(callback) }, 0);\r\n      }\r\n    });\r\n  };\r\n\r\n  setTimeout(function () {tick(callback) }, 0);\r\n}\r\n\r\n// set starting position of a text string on the oled\r\nOled.prototype.setCursor = function(x, y) {\r\n  this.cursor_x = x;\r\n  this.cursor_y = y;\r\n}\r\n\r\n// write text to the oled\r\nOled.prototype.writeString = function(font, size, string, color, wrap, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n  var wordArr = string.split(' '),\r\n      len = wordArr.length,\r\n      // start x offset at cursor pos\r\n      offset = this.cursor_x,\r\n      padding = 0;\r\n\r\n  // loop through words\r\n  for (var w = 0; w < len; w += 1) {\r\n    // put the word space back in for all in between words or empty words\r\n    if (w < len - 1 || !wordArr[w].length) {\r\n      wordArr[w] += ' ';\r\n    }\r\n    var stringArr = wordArr[w].split(''),\r\n        slen = stringArr.length,\r\n        compare = (font.width * size * slen) + (size * (len -1));\r\n\r\n    // wrap words if necessary\r\n    if (wrap && len > 1 && w > 0 && (offset >= (this.WIDTH - compare)) ) {\r\n      offset = 0;\r\n\r\n      this.cursor_y += (font.height * size) + this.LINESPACING;\r\n      this.setCursor(offset, this.cursor_y);\r\n    }\r\n\r\n    // loop through the array of each char to draw\r\n    for (var i = 0; i < slen; i += 1) {\r\n      if (stringArr[i] === '\\n') {\r\n        offset = 0;\r\n        this.cursor_y += (font.height * size) + this.LINESPACING;\r\n        this.setCursor(offset, this.cursor_y);\r\n      }\r\n      else {\r\n        // look up the position of the char, pull out the buffer slice\r\n        var charBuf = this._findCharBuf(font, stringArr[i]);\r\n        // read the bits in the bytes that make up the char\r\n        var charBytes = this._readCharBytes(charBuf, font.height);\r\n        // draw the entire character\r\n        this._drawChar(charBytes, font.height, size, false);\r\n\r\n        // calc new x position for the next char, add a touch of padding too if it's a non space char\r\n        //padding = (stringArr[i] === ' ') ? 0 : this.LETTERSPACING;\r\n        offset += (font.width * size) + this.LETTERSPACING;// padding;\r\n\r\n        // wrap letters if necessary\r\n        if (wrap && (offset >= (this.WIDTH - font.width - this.LETTERSPACING))) {\r\n          offset = 0;\r\n          this.cursor_y += (font.height * size) + this.LINESPACING;\r\n        }\r\n        // set the 'cursor' for the next char to be drawn, then loop again for next char\r\n        this.setCursor(offset, this.cursor_y);\r\n      }\r\n    }\r\n  }\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// draw an individual character to the screen\r\nOled.prototype._drawChar = function(byteArray, charHeight, size, sync) {\r\n  // take your positions...\r\n  var x = this.cursor_x,\r\n      y = this.cursor_y;\r\n\r\n  // loop through the byte array containing the hexes for the char\r\n  for (var i = 0; i < byteArray.length; i += 1) {\r\n    for (var j = 0; j < charHeight; j += 1) {\r\n      // pull color out\r\n      var color = byteArray[i][j],\r\n          xpos, ypos;\r\n      // standard font size\r\n      if (size === 1) {\r\n        xpos = x + i;\r\n        ypos = y + j;\r\n        this.drawPixel([xpos, ypos, color], false);\r\n      } else {\r\n        // MATH! Calculating pixel size multiplier to primitively scale the font\r\n        xpos = x + (i * size);\r\n        ypos = y + (j * size);\r\n        this.fillRect(xpos, ypos, size, size, color, false);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n// get character bytes from the supplied font object in order to send to framebuffer\r\nOled.prototype._readCharBytes = function(byteArray, charHeight) {\r\n  var bitArr = [],\r\n      bitCharArr = [];\r\n  // loop through each byte supplied for a char\r\n  for (var i = 0; i < byteArray.length; i += 1) {\r\n    // set current byte\r\n    var byte = byteArray[i];\r\n    // read each byte\r\n    for (var j = 0; j < charHeight; j += 1) {\r\n      // shift bits right until all are read\r\n      var bit = byte >> j & 1;\r\n      bitArr.push(bit);\r\n    }\r\n    // push to array containing flattened bit sequence\r\n    bitCharArr.push(bitArr);\r\n    // clear bits for next byte\r\n    bitArr = [];\r\n  }\r\n  return bitCharArr;\r\n}\r\n\r\n// find where the character exists within the font object\r\nOled.prototype._findCharBuf = function(font, c) {\r\n  // use the lookup array as a ref to find where the current char bytes start\r\n  var cBufPos = font.lookup.indexOf(c) * font.width;\r\n  // slice just the current char's bytes out of the fontData array and return\r\n  var cBuf = font.fontData.slice(cBufPos, cBufPos + font.width);\r\n  return cBuf;\r\n}\r\n\r\n// send the entire framebuffer to the oled\r\nOled.prototype.update = function() {\r\n  // wait for oled to be ready\r\n  this._waitUntilReady(function() {\r\n    // set the start and endbyte locations for oled display update\r\n    var displaySeq = [\r\n      this.COLUMN_ADDR,\r\n      this.screenConfig.coloffset,\r\n      this.screenConfig.coloffset + this.WIDTH - 1, // column start and end address\r\n      this.PAGE_ADDR, 0, (this.HEIGHT / 8) - 1 // page start and end address\r\n    ];\r\n\r\n    var displaySeqLen = displaySeq.length,\r\n        bufferLen = this.buffer.length,\r\n        i, v;\r\n\r\n    // send intro seq\r\n    for (i = 0; i < displaySeqLen; i += 1) {\r\n      this._transfer('cmd', displaySeq[i]);\r\n    }\r\n\r\n    // write buffer data\r\n\t\tvar bufferToSend = Buffer.concat([Buffer.from([0x40]), this.buffer]);\r\n\t\tvar sentCount = this.wire.i2cWriteSync(this.ADDRESS, bufferToSend.length, bufferToSend);\r\n\r\n  }.bind(this));\r\n}\r\n\r\n// send dim display command to oled\r\nOled.prototype.dimDisplay = function(bool) {\r\n  var contrast;\r\n\r\n  if (bool) {\r\n    contrast = 0; // Dimmed display\r\n  } else {\r\n    contrast = 0xCF; // Bright display\r\n  }\r\n\r\n  this._transfer('cmd', this.SET_CONTRAST);\r\n  this._transfer('cmd', contrast);\r\n}\r\n\r\n// turn oled off\r\nOled.prototype.turnOffDisplay = function() {\r\n  this._transfer('cmd', this.DISPLAY_OFF);\r\n}\r\n\r\n// turn oled on\r\nOled.prototype.turnOnDisplay = function() {\r\n  this._transfer('cmd', this.DISPLAY_ON);\r\n}\r\n\r\n// clear all pixels currently on the display\r\nOled.prototype.clearDisplay = function(sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n  // write off pixels\r\n  this.buffer.fill(0x00);\r\n\tif (immed) {\r\n\t\tthis.update();\r\n\t}\r\n\r\n}\r\n\r\n// invert pixels on oled\r\nOled.prototype.invertDisplay = function(bool) {\r\n  if (bool) {\r\n    this._transfer('cmd', this.INVERT_DISPLAY); // inverted\r\n  } else {\r\n    this._transfer('cmd', this.NORMAL_DISPLAY); // non inverted\r\n  }\r\n}\r\n\r\n// draw an RGBA image at the specified coordinates\r\nOled.prototype.drawRGBAImage = function(image, dx, dy, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n  // translate image data to buffer\r\n  var x, y, dataIndex, buffIndex, buffByte, bit, pixelByte;\r\n  var dyp = this.WIDTH * Math.floor(dy / 8); // calc once\r\n  var dxyp = dyp + dx;\r\n  for (x = 0; x < image.width; x++) {\r\n    var dxx = dx + x;\r\n    if (dxx < 0 || dxx >= this.WIDTH) {\r\n      // negative, off the screen\r\n      continue;\r\n    }\r\n    // start buffer index for image column\r\n    buffIndex = x + dxyp;\r\n    buffByte = this.buffer[buffIndex];\r\n    for (y = 0; y < image.height; y++) {\r\n      var dyy = dy + y; // calc once\r\n      if (dyy < 0 || dyy >= this.HEIGHT) {\r\n        // negative, off the screen\r\n        continue;\r\n      }\r\n      var dyyp = Math.floor(dyy / 8); // calc once\r\n\r\n      // check if start of buffer page\r\n      if (!(dyy % 8)) {\r\n        // check if we need to save previous byte\r\n        if ((x || y) && buffByte !== this.buffer[buffIndex]) {\r\n          // save current byte and get next buffer byte\r\n          this.buffer[buffIndex] = buffByte;\r\n          this.dirtyBytes.push(buffIndex);\r\n        }\r\n        // new buffer page\r\n        buffIndex = dx + x + this.WIDTH * dyyp;\r\n        buffByte = this.buffer[buffIndex];\r\n      }\r\n\r\n      // process pixel into buffer byte\r\n      dataIndex = (image.width * y + x) << 2; // 4 bytes per pixel (RGBA)\r\n      if (!image.data[dataIndex + 3]) {\r\n        // transparent, continue to next pixel\r\n        continue;\r\n      }\r\n\r\n      pixelByte = 0x01 << (dyy - 8 * dyyp);\r\n      bit = image.data[dataIndex] || image.data[dataIndex + 1] || image.data[dataIndex + 2];\r\n      if (bit) {\r\n        buffByte |= pixelByte;\r\n      }\r\n      else {\r\n        buffByte &= ~pixelByte;\r\n      }\r\n    }\r\n    if ((x || y) && buffByte !== this.buffer[buffIndex]) {\r\n      // save current byte\r\n      this.buffer[buffIndex] = buffByte;\r\n      this.dirtyBytes.push(buffIndex);\r\n    }\r\n  }\r\n\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// draw an image pixel array on the screen\r\nOled.prototype.drawBitmap = function(pixels, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n  var x, y,\r\n      pixelArray = [];\r\n\r\n  for (var i = 0; i < pixels.length; i++) {\r\n    x = Math.floor(i % this.WIDTH);\r\n    y = Math.floor(i / this.WIDTH);\r\n\r\n    this.drawPixel([x, y, pixels[i]], false);\r\n  }\r\n\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// draw one or many pixels on oled\r\nOled.prototype.drawPixel = function(pixels, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n\r\n  // handle lazy single pixel case\r\n  if (typeof pixels[0] !== 'object') pixels = [pixels];\r\n\r\n  pixels.forEach(function(el) {\r\n    // return if the pixel is out of range\r\n    var x = el[0], y = el[1], color = el[2];\r\n    if (x >= this.WIDTH || y >= this.HEIGHT) return;\r\n\r\n    // thanks, Martin Richards.\r\n    // I wanna can this, this tool is for devs who get 0 indexes\r\n    //x -= 1; y -=1;\r\n    var byte = 0,\r\n        page = Math.floor(y / 8),\r\n        pageShift = 0x01 << (y - 8 * page);\r\n\r\n    // is the pixel on the first row of the page?\r\n    (page == 0) ? byte = x : byte = x + (this.WIDTH * page);\r\n\r\n    // colors! Well, monochrome.\r\n    if (color === 'BLACK' || color === 0) {\r\n      this.buffer[byte] &= ~pageShift;\r\n    }\r\n    if (color === 'WHITE' || color > 0) {\r\n      this.buffer[byte] |= pageShift;\r\n    }\r\n\r\n    // push byte to dirty if not already there\r\n    if (this.dirtyBytes.indexOf(byte) === -1) {\r\n      this.dirtyBytes.push(byte);\r\n    }\r\n\r\n  }, this);\r\n\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// looks at dirty bytes, and sends the updated bytes to the display\r\nOled.prototype._updateDirtyBytes = function(byteArray) {\r\n  var blen = byteArray.length, i,\r\n      displaySeq = [];\r\n\r\n  // check to see if this will even save time\r\n  if (blen > (this.buffer.length / 7)) {\r\n    // just call regular update at this stage, saves on bytes sent\r\n    this.update();\r\n    // now that all bytes are synced, reset dirty state\r\n    this.dirtyBytes = [];\r\n\r\n  } else {\r\n\r\n    this._waitUntilReady(function() {\r\n      // iterate through dirty bytes\r\n      for (var i = 0; i < blen; i += 1) {\r\n\r\n        var byte = byteArray[i];\r\n        var page = Math.floor(byte / this.WIDTH);\r\n        var col = Math.floor(byte % this.WIDTH);\r\n\r\n        var displaySeq = [\r\n          this.COLUMN_ADDR, col, col, // column start and end address\r\n          this.PAGE_ADDR, page, page // page start and end address\r\n        ];\r\n\r\n        var displaySeqLen = displaySeq.length, v;\r\n\r\n        // send intro seq\r\n        for (v = 0; v < displaySeqLen; v += 1) {\r\n          this._transfer('cmd', displaySeq[v]);\r\n        }\r\n        // send byte, then move on to next byte\r\n        this._transfer('data', this.buffer[byte]);\r\n        this.buffer[byte];\r\n      }\r\n    }.bind(this));\r\n  }\r\n  // now that all bytes are synced, reset dirty state\r\n  this.dirtyBytes = [];\r\n}\r\n\r\n// using Bresenham's line algorithm\r\nOled.prototype.drawLine = function(x0, y0, x1, y1, color, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n\r\n  var dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1,\r\n      dy = Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1,\r\n      err = (dx > dy ? dx : -dy) / 2;\r\n\r\n  while (true) {\r\n    this.drawPixel([x0, y0, color], false);\r\n\r\n    if (x0 === x1 && y0 === y1) break;\r\n\r\n    var e2 = err;\r\n\r\n    if (e2 > -dx) {err -= dy; x0 += sx;}\r\n    if (e2 < dy) {err += dx; y0 += sy;}\r\n  }\r\n\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// draw a filled rectangle on the oled\r\nOled.prototype.fillRect = function(x, y, w, h, color, sync) {\r\n  var immed = (typeof sync === 'undefined') ? true : sync;\r\n  // one iteration for each column of the rectangle\r\n  for (var i = x; i < x + w; i += 1) {\r\n    // draws a vert line\r\n    this.drawLine(i, y, i, y+h-1, color, false);\r\n  }\r\n  if (immed) {\r\n    this._updateDirtyBytes(this.dirtyBytes);\r\n  }\r\n}\r\n\r\n// activate scrolling for rows start through stop\r\nOled.prototype.startScroll = function(dir, start, stop) {\r\n  var scrollHeader,\r\n      cmdSeq = [];\r\n\r\n  switch (dir) {\r\n    case 'right':\r\n      cmdSeq.push(this.RIGHT_HORIZONTAL_SCROLL); break;\r\n    case 'left':\r\n      cmdSeq.push(this.LEFT_HORIZONTAL_SCROLL); break;\r\n    // TODO: left diag and right diag not working yet\r\n    case 'left diagonal':\r\n      cmdSeq.push(\r\n        this.SET_VERTICAL_SCROLL_AREA, 0x00,\r\n        this.VERTICAL_AND_LEFT_HORIZONTAL_SCROLL,\r\n        this.HEIGHT\r\n      );\r\n      break;\r\n    // TODO: left diag and right diag not working yet\r\n    case 'right diagonal':\r\n      cmdSeq.push(\r\n        this.SET_VERTICAL_SCROLL_AREA, 0x00,\r\n        this.VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL,\r\n        this.HEIGHT\r\n      );\r\n      break;\r\n  }\r\n\r\n  this._waitUntilReady(function() {\r\n    cmdSeq.push(\r\n      0x00, start,\r\n      0x00, stop,\r\n      // TODO: these need to change when diagonal\r\n      0x00, 0xFF,\r\n      this.ACTIVATE_SCROLL\r\n    );\r\n\r\n    var i, cmdSeqLen = cmdSeq.length;\r\n\r\n    for (i = 0; i < cmdSeqLen; i += 1) {\r\n      this._transfer('cmd', cmdSeq[i]);\r\n    }\r\n  }.bind(this));\r\n}\r\n\r\n// stop scrolling display contents\r\nOled.prototype.stopScroll = function() {\r\n  this._transfer('cmd', this.DEACTIVATE_SCROLL); // stahp\r\n}\r\n\r\nmodule.exports = Oled;\r\n"]}