Skip to content

Commit

Permalink
Keypad: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jul 3, 2015
1 parent c572930 commit 2dc685e
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 212 deletions.
15 changes: 4 additions & 11 deletions eg/keypad-MPR121.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ board.on("ready", function() {

if (argv.show === 1) {
keypad = new five.Keypad({
controller: "MPR121",
address: 0x5A
controller: "MPR121"
});
}

if (argv.show === 2) {
keypad = new five.Keypad({
controller: "MPR121",
address: 0x5A,
keys: [
["!", "@", "#"],
["$", "%", "^"],
Expand All @@ -30,18 +28,13 @@ board.on("ready", function() {
if (argv.show === 3) {
keypad = new five.Keypad({
controller: "MPR121",
address: 0x5A,
keys: ["!", "@", "#", "$", "%", "^", "&", "-", "+", "_", "=", ":"]
});
}

["change", "press", "hold", "release"].forEach(function(event) {
keypad.on(event, function(data) {
// console.log("Event: %s, Which: %s", event, data);

if (event === "press") {
exec("say " + data);
}
["change", "press", "hold", "release"].forEach(function(eventType) {
keypad.on(eventType, function(data) {
console.log("Event: %s, Target: %s", eventType, data.which);
});
});
});
15 changes: 4 additions & 11 deletions eg/keypad-MPR121QR2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ board.on("ready", function() {

if (argv.show === 1) {
keypad = new five.Keypad({
controller: "MPR121QR2",
address: 0x5A
controller: "MPR121QR2"
});
}

if (argv.show === 2) {
keypad = new five.Keypad({
controller: "MPR121QR2",
address: 0x5A,
keys: [
["!", "@", "#"],
["$", "%", "^"],
Expand All @@ -29,18 +27,13 @@ board.on("ready", function() {
if (argv.show === 3) {
keypad = new five.Keypad({
controller: "MPR121QR2",
address: 0x5A,
keys: ["!", "@", "#", "$", "%", "^", "&", "-", "+"]
});
}

["change", "press", "hold", "release"].forEach(function(event) {
keypad.on(event, function(data) {
// console.log("Event: %s, Which: %s", event, data);

if (event === "press") {
exec("say " + data);
}
["change", "press", "hold", "release"].forEach(function(eventType) {
keypad.on(eventType, function(data) {
console.log("Event: %s, Target: %s", eventType, data.which);
});
});
});
10 changes: 3 additions & 7 deletions eg/keypad-analog-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ board.on("ready", function() {
});
}

["change", "press", "hold", "release"].forEach(function(event) {
keypad.on(event, function(data) {
console.log("Event: %s, Which: %s", event, data);

if (event === "press") {
exec("say " + data);
}
["change", "press", "hold", "release"].forEach(function(eventType) {
keypad.on(eventType, function(data) {
console.log("Event: %s, Target: %s", eventType, data.which);
});
});
});
Expand Down
10 changes: 3 additions & 7 deletions eg/keypad-analog-vkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ board.on("ready", function() {
});
}

["change", "press", "hold", "release"].forEach(function(event) {
keypad.on(event, function(data) {
console.log("Event: %s, Which: %s", event, data);

if (event === "press") {
exec("say " + data);
}
["change", "press", "hold", "release"].forEach(function(eventType) {
keypad.on(eventType, function(data) {
console.log("Event: %s, Target: %s", eventType, data.which);
});
});
});
Expand Down
87 changes: 65 additions & 22 deletions lib/definitions/mpr121.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,73 @@
module.exports = {
MAPS: {
MPR121QR2: {
8: 1,
5: 2,
2: 3,
7: 4,
4: 5,
1: 6,
6: 7,
3: 8,
0: 9,
KEYS: {
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6,
6: 7,
7: 8,
8: 9,
},
TARGETS: {
256: 0,
32: 1,
4: 2,
128: 3,
16: 4,
2: 5,
64: 6,
8: 7,
1: 8,
}
},
// MPR121: {
// 3: 1,
// 7: 2,
// 11: 3,
// 2: 4,
// 6: 5,
// 10: 6,
// 1: 7,
// 5: 8,
// 9: 9,
// 0: 10,
// 4: 11,
// 8: 12,
// },
MPR121: {
3: 1,
7: 2,
11: 3,
2: 4,
6: 5,
10: 6,
1: 7,
5: 8,
9: 9,
0: 10,
4: 11,
8: 12,
}
KEYS: {
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6,
6: 7,
7: 8,
8: 9,
9: 10,
10: 11,
11: 12,
},
TARGETS: {
8: 0,
128: 1,
2048: 2,
4: 3,
64: 4,
1024 : 5,
2: 6,
32: 7,
512: 8,
1: 9,
16: 10,
256: 11,
}
},
},
MPR121_DEFAULT_ADDRESS: 0x5A,

Expand Down
Loading

0 comments on commit 2dc685e

Please sign in to comment.