-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (58 loc) · 2.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const commands = {
up: [12.4,0.8,0.1,0.0,1.6,0.1,0.1,0.0,0.0,0.0,0.0,0.0,46.5,0.0,0.1,0.0,0.0,13.9,0.1,0.9,0.1,1.4,0.1,0.0,0.7,0.0,1.3,0.0,156.9,0.3,0.0,0.0,0.1,0.0,0.3,3.8,0.0,0.0,0.5,0.0,1.4,0.0,0.9,1428.2,0.0,0.0,1.3,0.0,0.6,0.0,16.5,0.7,2.9,0.0,0.0,0.6,0.0,0.5,0.0,0.2,0.2,0.0,0.0,0.0,0.1,0.0,0.2,0.0,0.0,0.1,0.1,0.0,0.3,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.4,0.0,0.6,0.0,0.9,0.7,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.2,0.0,0.0,0.0,0.0,0.0,0.3,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.2,0.0,0.0,0.2,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.7,0.0,0.0,0.3,44.4,0.0,18.9,0.0,0.1,0.0,3.4,0.0,4.1,0.3,0.0,0.3,0.0,0.2,0.0,0.0,0.0,2.4,0.0,0.0,1.3,0.1,0.0,2.6,0.0,0.0,0.6,0.3,0.0,0.7,0.3,13.1,0.2,0.2,0.2,0.1,0.0,0.2,0.1,0.4,0.7,0.2,0.2,0.4,0.0,0.0,0.5,0.1,0.1,0.2,0.0,0.4,0.0,0.6,0.0,0.4,0.1,0.0,0.6,394.9,0.9,0.0,348.3],
down: [0.6,0.0,0.2,3.8,0.0,0.2,2.5,0.0,0.8,0.0,0.2,0.0,0.2,0.8,0.3,1.2,0.2,0.5,0.1,0.1,0.2,0.1,0.7,0.0,1.6,0.0,0.5,0.2,1.3,0.0,1.6,2.2,0.8,0.2,0.0,0.0,1.6,0.0,0.0,0.0,0.2,0.0,0.6,0.0,0.0,0.0,0.3,0.0,1.1,0.0,1.9,0.0,0.9,0.1,0.0,0.2,0.0,1.4,0.0,1.3,0.5,0.0,0.4,1.5,1.4,0.0,0.2,0.0,0.3,0.0,5.9,0.0,0.3,0.1,115.6,0.0,0.6,1.0,0.2,0.0,0.5,0.0,0.4,0.0,0.1,0.1,0.0,0.7,0.6,0.1,1356.9,0.0,0.0,0.0,0.1,0.0,0.0,0.2,0.0,0.0,0.0,0.0,0.5,0.1,2.7,0.0,0.3,0.0,0.0,0.0,0.0,0.1,0.0,35.8,2.9,0.0,1.3,0.0,0.0,0.0,13.0,0.7,0.0,0.0,0.0,0.0,0.2,0.0,0.0,0.1,0.0,0.0,0.1,0.0,0.2,0.0,0.0,0.0,0.1,0.0,43.6,0.0,0.0,0.0,0.1,2.7,0.0,0.9,37.7,0.0,0.2,0.0,0.0,0.0,0.2,0.0,0.0,0.0,257.9,0.1,0.0,0.7,0.0,6.2,3.4,0.0,0.0,0.4,0.0,2.5,0.0,1.9,0.0,0.0,0.5,0.5,0.0,0.0,0.2,0.1,0.6,0.3,0.0,3.8,0.1,0.0,15.5,2.1,0.0,0.7,278.2,0.7,0.2,0.2,0.0,0.8,0.2,0.5,0.4,0.0,0.8,1.5,1.8,1.3,0.1,0.7,0.0,0.1,0.1,2.5,0.0,228.7,0.2,0.0,22.6,114.6,0.0,0.0]
};
let clickcount = 0;
let clickevent = null;
let isMoving = false;
const setLEDS = (LED1on, LED2on, LED3on) => {
LED1.reset();
LED2.reset();
LED3.reset();
if (LED1on) LED1.set();
if (LED2on) LED2.set();
if (LED3on) LED3.set();
};
const stopMovement = () => {
setLEDS(false, false, false);
clickcount = 0;
isMoving = false;
console.log('Movement Stopped');
};
const moveTV = (direction) => {
console.log(`Moving ${direction}`);
isMoving = true;
// Puck.IR(commands[direction]);
setTimeout(() => stopMovement(), 6000);
};
setWatch((e) => {
// Stop all movement if the button is pressed again before movement stops
if (isMoving) {
return stopMovement();
}
clickcount++;
try {
if (clickevent !== null) clearTimeout(clickevent);
} catch (e) {
console.log("Oops!", e);
}
if (clickcount === 1) {
setLEDS(false, true, false);
} else if (clickcount === 2) {
setLEDS(false, false, true);
} else {
setLEDS(false, false, false);
}
clickevent = setTimeout(() => {
if (clickcount === 1) {
moveTV('up');
} else if (clickcount === 2) {
moveTV('down');
}
clickcount = 0;
}, 350);
}, BTN, {
edge: "rising",
debounce: 10,
repeat: true
});