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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 4x 4x 7x 4x 4x 5x 2x 2x 2x 5x 1x 1x 1x 1x 2x 5x 1x 1x 1x 1x 1x | "use strict" import fs from 'fs'; import p from 'path'; /** * class UsbLed * usbled driver works by writing a file containing 1 (ON) or 0 (OFF) with * the colour as the file name, the file must be written to driver path. * * @param {String} path: usbled driver path, if not specified then it will try * to find driver path under /sys/bus/usb/drivers/usbled/ . */ class UsbLed { constructor(path) { this.path = path || this._find(); } /** * Switch on the specified colour by writing a colour file containing value 1. * * @param {String} colour: the colour to switch on */ on(colour) { const ON = '1'; fs.writeFileSync(p.join(this.path, colour.toLowerCase()), ON); } /** * Switch off the specified colour by writing a colour file containing value 0. * * @param {String} colour: the colour to switch off */ off(colour) { const OFF = '0'; fs.writeFileSync(p.join(this.path, colour.toLowerCase()), OFF); } /** * Find usbled driver path under /sys/bus/usb/drivers/usbled/. * If there are multiple versions installed, then it will pick the largest version number. * If there's only one version installed, that version will be used. * If there's none or if usbled is not installed, then an error will be thrown. */ _find() { const DIR = '/sys/bus/usb/drivers/usbled/'; if (!fs.existsSync(DIR)) { throw new Error('Unable to find USB LED driver installation.'); } let versions = fs.readdirSync(DIR).filter(function (dir) { return dir.match(/.+:.+/); }); if (versions.length === 0) { throw new Error('Unable to find USB LED driver installation.'); } if (versions.length > 1) { versions.sort(function (v1, v2) { return v1 < v2; }); } return p.join(DIR, versions[0]); } } export { UsbLed as default }; |