-
Notifications
You must be signed in to change notification settings - Fork 0
/
bed-warmer-io.js
44 lines (29 loc) · 930 Bytes
/
bed-warmer-io.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
var rpio = require('rpio');
//Constants
const CONTROL_DELAY = 250;
function warmerInit(params, mock = false) {
//todo: store control pin number for future use
//Allow for mocking the io for testing purposes
if(mock){
rpio.init({mock: 'raspi-zero-w'})
};
//Initialize the desired control pin for the transistor
rpio.open(params.controlPin, rpio.OUTPUT);
}
function warmerToggle(params, done) {
//todo: replace params(.pin) with stored pin number
//Toggle the control pin high for CONTROL_DELAY ms
rpio.write(params.controlPin, rpio.HIGH);
rpio.msleep(CONTROL_DELAY);
rpio.write(params.controlPin, rpio.LOW);
done();
}
function warmerClose(params){
//Clear any pin configurations
rpio.close(params.controlPin, rpio.PIN_RESET);
}
module.exports = {
init: warmerInit,
toggle: warmerToggle,
close: warmerClose
}