initial
This commit is contained in:
5
node_modules/epoll/example/watch-button/export
generated
vendored
Executable file
5
node_modules/epoll/example/watch-button/export
generated
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
echo 4 > /sys/class/gpio/export
|
||||
echo in > /sys/class/gpio/gpio4/direction
|
||||
echo both > /sys/class/gpio/gpio4/edge
|
||||
|
3
node_modules/epoll/example/watch-button/unexport
generated
vendored
Executable file
3
node_modules/epoll/example/watch-button/unexport
generated
vendored
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo 4 > /sys/class/gpio/unexport
|
||||
|
26
node_modules/epoll/example/watch-button/watch-button.js
generated
vendored
Normal file
26
node_modules/epoll/example/watch-button/watch-button.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var Epoll = require('../../build/Release/epoll').Epoll,
|
||||
fs = require('fs'),
|
||||
valuefd = fs.openSync('/sys/class/gpio/gpio4/value', 'r'),
|
||||
buffer = new Buffer(1);
|
||||
|
||||
// Create a new Epoll. The callback is the interrupt handler.
|
||||
var poller = new Epoll(function (err, fd, events) {
|
||||
// Read GPIO value file. Reading also clears the interrupt.
|
||||
fs.readSync(fd, buffer, 0, 1, 0);
|
||||
console.log(buffer.toString() === '1' ? 'pressed' : 'released');
|
||||
});
|
||||
|
||||
// Read the GPIO value file before watching to
|
||||
// prevent an initial unauthentic interrupt.
|
||||
fs.readSync(valuefd, buffer, 0, 1, 0);
|
||||
|
||||
// Start watching for interrupts.
|
||||
poller.add(valuefd, Epoll.EPOLLPRI);
|
||||
|
||||
// Stop watching after 30 seconds.
|
||||
setTimeout(function () {
|
||||
poller.remove(valuefd).close();
|
||||
}, 30000);
|
||||
|
Reference in New Issue
Block a user