Skip to content

Commit 5c3dbe2

Browse files
committed
amend hot/cool logic
1 parent 7c67001 commit 5c3dbe2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ PIN_IN='[535, 539, 536, 529, 528, 534]'
1010
#GPIOS: 23, 27, 24, 17, 16, 22
1111

1212
PIN_OUT='[538]'
13-
#GPIOS: 26
13+
#GPIOS: 6
1414

1515
LABEL='["Coke", "21UP", "Bubly", "Ginger Ale", "Beer", "Cooler"]'
1616

1717
### MACHINE SETTINGS
1818

19-
WS_RECONNECT=600 #Interval in seconds that the machine pings the Websocket to ensure liveliness
19+
WS_RECONNECT=600 #Interval in seconds that the machine pings the Websocket to ensure liveliness

src/machine.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var timetaken = "Time until button was pressed:";
2222
function setupButtons() {
2323
// let button = [];
2424
for (let pin of pinIn) {
25-
button[pin] = new Gpio(pin, "in", "falling", {debounceTimeout: 500});
25+
button[pin] = new Gpio(pin, "in", "rising", {debounceTimeout: 500});
2626
console.log(`Waiting for button to be pressed. Pin ${pin}`);
2727
}
2828
}
@@ -82,7 +82,10 @@ async function makeMachineCold(pinOut) {
8282
await sleep(500);
8383
// Next, the machine will check whether the tray was previously marked unavailable
8484
if (availableTray[tray] == 1) {
85-
console.log(`Item ${label[tray]} at tray ${tray} unavailable`)
85+
// console.log(`Item ${label[tray]} at tray ${tray} unavailable`)
86+
const pino = new Gpio(pinOut, "out");
87+
pino.writeSync(0);
88+
// console.log(`Making machine cold anyway`);
8689
return;
8790
}
8891
// Third, the machine will check if it is actually hot, and only close the circuit then
@@ -93,12 +96,15 @@ async function makeMachineCold(pinOut) {
9396
// On the test relay the pins are inverted, in production they should be 0 to close
9497
pino.writeSync(0);
9598
state = 0;
96-
console.log(`Machine is now ${stateLabel[state]}.`)
99+
// console.log(`Machine is now ${stateLabel[state]}.`)
97100
checkTrays();
98101
}
99102
// If condition 0 & 1 are not met, it will do nothing.
100103
else {
101-
console.log(`Machine is already ${stateLabel[state]}. Doing nothing.`)
104+
// console.log(`Machine is already ${stateLabel[state]}. Doing nothing.`)
105+
const pino = new Gpio(pinOut, "out");
106+
pino.writeSync(0);
107+
// console.log(`Making machine cold anyway`);
102108
}
103109
}
104110

0 commit comments

Comments
 (0)