Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-bit-rot so tests/app.js works again. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/components/lcd-digit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const LCDchars = require('./7segment_chars.json');
const LCDchars = require('../7segment_chars.json');

function LCDDigit(config,controller) {
var char = ' ';
Expand Down Expand Up @@ -54,4 +54,4 @@ function LCDDigit(config,controller) {
}
};

module.exports = LCDDigit;
module.exports = LCDDigit;
2 changes: 1 addition & 1 deletion lib/components/led-rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ var LED_RGB = function(config,controller) {
};
};

module.exports = LED_RGB;
module.exports = LED_RGB;
2 changes: 1 addition & 1 deletion lib/components/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function Slider(name,config,controller) {
}
};

module.exports = Slider;
module.exports = Slider;
35 changes: 22 additions & 13 deletions lib/traktor_f1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

const HID = require('node-hid');
const util = require('util');
const Emitter = require('events').EventEmitter,
const = require('lodash'),
const Emitter = require('events').EventEmitter;
const _ = require('lodash');

const f1Config = require('./traktor_f1_config.json'),
const Button = require('./components/button');
const StepWheel = require('./components/stepwheel');
const Slider = require('./components/slider');
const LED = require('./components/led');
const LED_RGB = require('./components/led-rgb');
const LCDDigit = require('./components/lcd-digit');

const f1Config = require('./traktor_f1_config.json');

var VENDOR_ID = 6092;
var PRODUCT_ID = 4384;
Expand Down Expand Up @@ -42,28 +49,27 @@ function TraktorF1() {
for(var key in f1Config.output.lcd)
this.lcd[key] = new LCDDigit(f1Config.output.lcd[key],this);


this.outPacket = new Buffer(81);
this.outPacket = new Array(81);
this.outPacket[0] = 0x80;
this.outPacket.fill(0,1);
for (let i = 1; i < 81; i++) {
this.outPacket[i] = 0;
}

var sendOutput = function() {
var sendOutput = () => {
try {
this.device.write(this.outPacket);
dirty = false;
}
catch(ex) {
console.log("Error");
console.log(ex)
console.log("failed write", ex);
}
};


var boundSendOutput = sendOutput.bind(this);
this.invalidateOutput = function() {
if(!dirty) {
dirty = true;
setImmediate(boundSendOutput);
setImmediate(sendOutput);
}
};

Expand All @@ -74,7 +80,10 @@ function TraktorF1() {
console.log('Could not connect to F1',e);
}

this.device.on("data",this.parseInput.bind(this));
this.device.on("data", this.parseInput.bind(this));
this.device.on("error", (ex) => {
console.log("device error:", ex);
});
}

util.inherits(TraktorF1, Emitter);
Expand All @@ -83,7 +92,7 @@ TraktorF1.prototype.parseInput = function(data) {
for(var key in this.buttons) {
this.buttons[key].parseInput(data);
}

this.stepper.parseInput(data);

for(var key in this.knobs) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "./lib/traktor_f1",
"dependencies": {
"lodash": "^4.5.1",
"node-hid": "^0.5.1"
"node-hid": "^0.7.0",
"tinycolor2": "^1.4.1"
},
"devDependencies": {},
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ f1.on('stepper:step',function(e) {
f1.setLCDString(Number(bpm%100).toString());
f1.setLCDDot("l",(bpm >= 100));
f1.setLCDDot("r",(bpm >= 200));

});

f1.setLED("l1_r",1);
Expand Down Expand Up @@ -147,19 +147,19 @@ var setRGBsToCanvas = function() {
for(var i=0; i<16; i++) {
var pixIndex = i*4;
var alpha = pixels[pixIndex+3]/255;
f1.setRGB('p'+(i+1),alpha*pixels[pixIndex],alpha*pixels[pixIndex+1],alpha*pixels[pixIndex+2]);
f1.setRGB('p'+(i+1),alpha*pixels[pixIndex],alpha*pixels[pixIndex+1],alpha*pixels[pixIndex+2]);
}*/
};


var setAllRGBs = function() {
for(var a=1; a<=16; a++)
for(var a=1; a<=16; a++)
f1.setRGB('p'+a,0,0,0);
var colors = tinycolor.analogous(tinycolor({h:hue,s:sat,v:val}),17,dist);
var colors = tinycolor({h:hue,s:sat,v:val}).analogous(17,dist);
for(var a=0, b=1; a < 16; a++, b = (b+1)%colors.length) {
//var c = (Math.floor(a/4)+b)%4;
var c = b;
f1.setRGB('p'+(a+1),colors[c]._r,colors[c]._g,colors[c]._b);
f1.setRGB('p'+(a+1),colors[c]._r,colors[c]._g,colors[c]._b);
}
};

Expand Down Expand Up @@ -202,12 +202,12 @@ var strobeOffCount = 0;
f1.on('shift:pressed',function() {
strobeInterval = setInterval(function() {
if(strobeOffCount < 3) {
for(var a=1; a<=16; a++)
for(var a=1; a<=16; a++)
f1.setRGB('p'+a,0,0,0);
strobeOffCount++;
strobeOffCount++;
}
else {
for(var a=1; a<=16; a++)
for(var a=1; a<=16; a++)
f1.setRGB('p'+a,255,255,255);
strobeOffCount = 0;
}
Expand Down