Created
June 26, 2016 06:03
-
-
Save mallendeo/d2ed83b6dfa5c1c417536e5ce0479904 to your computer and use it in GitHub Desktop.
Get gpio sensors (Raspberry PI)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpio from 'gpio'; | |
export default const sensor = (pins = [ | |
{ num: 3, name: 'gate' }, | |
{ num: 4, name: 'door' } | |
]) => { | |
let sensors = []; | |
const init = () => { | |
pins.map(pin => { | |
console.log('exporting', pin.num, pin.name); | |
sensors.push({ | |
gpio: gpio.export(pin.num, { | |
direction: 'in', | |
interval: 50, | |
ready: () => {}, | |
}), | |
name: pin.name, | |
}); | |
}); | |
} | |
const getSensors = () => sensors; | |
const getSensor = name => sensors.find(s => s.name === name); | |
return { | |
init, | |
getSensors, | |
getSensor, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment