add new mpr lib to package

This commit is contained in:
Todd Treece 2016-05-19 11:35:17 -04:00
parent 15a7b1ba68
commit b57a15918f
4 changed files with 32 additions and 57 deletions

View file

@ -23,6 +23,8 @@ const story = new Story(npr),
const logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8');
console.log(logo);
console.log('connecting to npr one...');
// silence swagger log output
process.env.NODE_ENV = 'test';

View file

@ -1,11 +1,14 @@
var inquirer = require('inquirer'),
path = require('path'),
config = path.join(process.env['HOME'], '.npr-one'),
dotenv = require('dotenv').load({silent: true, path: config}),
fs = require('fs'),
npr;
'use strict';
var client_creds = [
const inquirer = require('inquirer'),
path = require('path'),
config = path.join(process.env['HOME'], '.npr-one'),
dotenv = require('dotenv').load({silent: true, path: config}),
fs = require('fs');
let npr;
const client_creds = [
{
type: 'input',
name: 'CLIENT_ID',
@ -18,7 +21,7 @@ var client_creds = [
}
];
var device_code = [
const device_code = [
{
type: 'list',
name: 'device',
@ -27,7 +30,7 @@ var device_code = [
}
];
var requestDeviceCode = function() {
const requestDeviceCode = function() {
return new Promise(function(resolve, reject) {
@ -58,7 +61,7 @@ var requestDeviceCode = function() {
};
var requestToken = function(code) {
const requestToken = function(code) {
return new Promise(function(resolve, reject) {
@ -79,7 +82,7 @@ var requestToken = function(code) {
};
var getClientCreds = function() {
const getClientCreds = function() {
return new Promise(function(resolve, reject) {

View file

@ -9,15 +9,6 @@ class UI extends EventEmitter {
super();
this.state = {
skip: false,
pause: false,
rewind: false,
interesting: false,
volumeup: false,
volumedown: false
};
if(process.platform == 'linux' && process.arch == 'arm')
this.mprInit();
@ -47,61 +38,41 @@ class UI extends EventEmitter {
mprInit() {
const MPR121 = require('mpr121'),
touch = new MPR121(0x5A, 1);
mpr121 = new MPR121(0x5A, 1);
touch.begin();
setTimeout(() => {
if(! touch.ready) return;
setInterval(() => {
this.skip(touch.is_touched(0));
this.pause(touch.is_touched(1));;
this.rewind(touch.is_touched(2));
this.interesting(touch.is_touched(3));
this.volumeup(touch.is_touched(4));
this.volumedown(touch.is_touched(5));
}, 100);
}, 100);
}
handleChange(type, pressed) {
if(typeof pressed == 'undefined')
return this.emit(type);
if(pressed && !this.state[type])
this.emit(type);
this.state[type] = pressed;
mpr121.on('touch', (pin) => {
if(pin === 0) this.skip();
if(pin === 1) this.pause();;
if(pin === 2) this.rewind();
if(pin === 3) this.interesting();
if(pin === 4) this.volumeup();
if(pin === 5) this.volumedown();
});
}
skip(pressed) {
this.handleChange('skip', pressed);
this.emit('skip');
}
pause(pressed) {
this.handleChange('pause', pressed);
this.emit('pause');
}
rewind(pressed) {
this.handleChange('rewind', pressed);
this.emit('rewind');
}
interesting(pressed) {
this.handleChange('interesting', pressed);
this.emit('interesting');
}
volumeup(pressed) {
this.handleChange('volumeup', pressed);
this.emit('volumeup');
}
volumedown(pressed) {
this.handleChange('volumedown', pressed);
this.emit('volumedown');
}
}

View file

@ -28,7 +28,6 @@
"inquirer": "^0.9.0",
"keypress": "^0.2.1",
"mplayer": "^2.0.1",
"node-mplayer": "0.0.6",
"npmlog": "^2.0.3",
"npr-api": "^1.1.2",
"rimraf": "^2.5.2",
@ -37,6 +36,6 @@
"wget-improved": "^1.3.0"
},
"optionalDependencies": {
"mpr121": "0.0.5"
"mpr121": "adafruit/node_mpr121"
}
}