add touch and release threshold config

This commit is contained in:
Todd Treece 2016-06-13 17:05:49 -04:00
parent 504ed539a0
commit f9c8cbc8b2
3 changed files with 14 additions and 4 deletions

View file

@ -12,6 +12,8 @@ const NPR = require('npr-api'),
auth = require('./lib/auth'),
fs = require('fs'),
path = require('path'),
config = path.join(process.env['HOME'], '.npr-one'),
dotenv = require('dotenv').load({silent: true, path: config}),
Player = require('./lib/player'),
Story = require('./lib/story'),
UI = require('./lib/ui');
@ -39,13 +41,19 @@ npr.one
.then(story.getRecommendations.bind(story))
.then(player.load.bind(player))
.then(() => {
const ui = new UI();
const ui = new UI({
touchThreshold: process.env.MPR121_TOUCH,
releaseThreshold: process.env.MPR121_RELEASE
});
ui.on('skip', player.skip.bind(player));
ui.on('pause', player.pause.bind(player));
ui.on('rewind', player.rewind.bind(player));
ui.on('interesting', player.interesting.bind(player));
ui.on('volumeup', player.increaseVolume.bind(player));
ui.on('volumedown', player.decreaseVolume.bind(player));
})
.catch(function(err) {
console.error(err, err.stack);

View file

@ -3,7 +3,6 @@
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;

View file

@ -5,10 +5,13 @@ const EventEmitter = require('events'),
class UI extends EventEmitter {
constructor() {
constructor(config) {
super();
this.touchThreshold = config.touchThreshold || 24;
this.releaseThreshold = config.releaseThreshold || 12;
if(process.platform == 'linux' && process.arch == 'arm')
this.mprInit();
@ -40,7 +43,7 @@ class UI extends EventEmitter {
const MPR121 = require('adafruit-mpr121'),
mpr121 = new MPR121(0x5A, 1);
mpr121.setThresholds(24, 12);
mpr121.setThresholds(this.touchThreshold, this.releaseThreshold);
mpr121.on('touch', (pin) => {
if(pin === 0) this.skip();