Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 2x 2x 2x 2x 2x 4x 4x 4x 4x 2x 2x 2x 2x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 12x 11x 12x 1x 1x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 27x 1x 1x 27x 11x 11x 1x 1x 1x 1x 1x 1x | "use strict" import async from 'async'; import UsbLed from './drivers/usbled.js'; /** * class BuildLight * * @param {Object} opts: optional * - scheme: color scheme array, defaults to [ 'red', 'green', 'blue' ] * scheme allows flexibility to use BuildLight with various Delcom devices (RGB, RGY) * - usbled: path to usbled installation, if not specified then it will try to * find a usbled installation at /sys/bus/usb/drivers/usbled/ * - interval: continuous task (e.g. blink) interval in milliseconds * switching between displaying color and no color, default to 500ms * - gen: generation number of the build light * find the part number at the bottom of your device * and check it at Delcom product page https://www.delcomproducts.com/products_USBLMP.asp */ class BuildLight { constructor(opts) { const RGB = [ 'red', 'green', 'blue' ]; const INTERVAL = 500; const GEN = 1; this.opts = opts || {}; this.scheme = this.opts.scheme || RGB; this.interval = this.opts.interval || INTERVAL; this.platform = this.opts.platform || process.platform; this.gen = this.opts.gen || GEN; this._driver(); this._colours(); } /** * Switch on all colours in the color scheme. */ on() { const self = this; this.scheme.forEach(function (colour) { self.driver.on(colour); }); } /** * Switch off all colours in the color scheme. */ off() { const self = this; this.scheme.forEach(function (colour) { self.driver.off(colour); }); } /** * Blink the specified colour. * * @param {String} colour: a colour from the scheme, default scheme either red, green, or blue * if no colour is specified then default to display all colours from the scheme * @param {Function} cb: callback with error arg if there's any interruption */ blink(colour, cb) { if (!cb) { cb = colour; colour = null; } const self = this; this.continuous = true; function task(cb) { // only timeout if continuous, otherwise finish off a.s.a.p function _do(cb) { if (self.continuous) { setTimeout(cb, self.interval); } else { cb(); } } if (self.continuous) { self[colour || 'on'](); _do(function () { self.off(); _do(cb); }); } else { cb('Stop blinking...'); } } async.forever(task, cb); } /** * Stop blinking. * Wait for interval before calling callback to allow * in-progress blink to finish. * * @param {Function} cb: callback with error arg if there's any interruption */ unblink(cb) { this.continuous = false; setTimeout(cb, this.interval); } /** * Select a driver to use based on platform. * BuildLight currently supports Linux platform only, contributions for other platforms are welcome. * - Linux platform uses usbled driver. */ _driver() { if (this.platform === 'linux' && this.gen === 1) { this.driver = new (UsbLed)(this.opts.usbled); } else { throw new Error('Unsupported platform ' + this.platform + ' with device generation ' + this.gen); } } /** * Initialise colour method based on colour scheme. * If scheme is [ 'red', 'green', 'blue' ], then you use: * buildLight.red(); * buildLight.green(); * buildLight.blue(); * Each colour method will switch off all colours, then switch on one particular colour. */ _colours() { const self = this; this.scheme.forEach(function (colour) { BuildLight.prototype[colour] = function () { self.off(); self.driver.on(colour); }; }); } } export { BuildLight as default }; |