init: () => { /** * Shutdown the device if running out of power so as to not completely drain * the battery */ const battery = new Battery(); battery.init(); battery.on('out-of-power', () => { log.warn('Device ran out of power; shutting down...'); shutdown(); }); /** * Initializing the Wi-Fi module. */ wifi.init() .then(() => { return wifi.online(); }) .then(() => { log.info('Wifi initialized successfully'); }) .catch((err) => { log.error('Failed to initialize wifi', err); }); // Power key handling let input = new Input(); let vib = new Vibrator(); input.on('down', e => { vib.pattern(50); switch (e.keyId) { case 'power': log.warn('Powering down'); util.setprop('sys.powerctl', 'shutdown'); break; default: log.verbose(`Unhandled key: ${JSON.stringify(e)}`); break; } }); },
const wifi = require('silk-wifi').default; const util = require('silk-sysutils'); const Battery = require('silk-battery').default; const Movie = require('silk-movie').Movie; const Vibrator = require('silk-vibrator').default; const ntp = require('silk-ntp').default; const Input = require('silk-input').default; const lights = require('silk-lights'); const productName = util.getstrprop('ro.product.name', '(unknown?)'); log.info('Running on a ' + productName); // Shutdown the device if running out of power so as to not completely drain // the battery const battery = new Battery(); battery.init() .then(() => { battery.on('out-of-power', () => { log.warn('Device ran out of power; shutting down...'); shutdown(); }); }); // Display something on the screen (if there is one) let splash = new Movie(); splash.run(path.join(__dirname, 'splash.zip')); let vib = new Vibrator(); vib.pattern(500); // Wifi initialization