All Projects → fivdi → epoll

fivdi / epoll

Licence: MIT license
A low-level Node.js binding for the Linux epoll API

Programming Languages

javascript
184084 projects - #8 most used programming language
C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
shell
77523 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to epoll

gobot
Golang framework for robotics, drones, and the Internet of Things (IoT)
Stars: ✭ 7,869 (+9860.76%)
Mutual labels:  beaglebone-black, gpio, beaglebone
Cylon
JavaScript framework for robotics, drones, and the Internet of Things (IoT)
Stars: ✭ 3,862 (+4788.61%)
Mutual labels:  beaglebone-black, gpio
Periph
Go·Hardware·Lean
Stars: ✭ 1,700 (+2051.9%)
Mutual labels:  gpio, beaglebone
moon c
문c 블로그 with ARM64 Linux Kernel 5.x
Stars: ✭ 17 (-78.48%)
Mutual labels:  gpio, interrupt
beagleg
G-code interpreter and stepmotor controller for crazy fast coordinated moves of up to 8 steppers. Uses the Programmable Realtime Unit (PRU) of the Beaglebone.
Stars: ✭ 107 (+35.44%)
Mutual labels:  beaglebone-black, beaglebone
Johnny Five
JavaScript Robotics and IoT programming framework, developed at Bocoup.
Stars: ✭ 12,498 (+15720.25%)
Mutual labels:  beaglebone-black, gpio
node-beagle-boot
A node.js USB bootloader server for BeagleBone for booting it into mass storage mode
Stars: ✭ 17 (-78.48%)
Mutual labels:  beaglebone-black, beaglebone
go-hd44780
Golang library to interact with liquid-crystal display driven by Hitachi HD44780 IC via I2C-bus driver from Raspberry PI.
Stars: ✭ 31 (-60.76%)
Mutual labels:  gpio
stm8s-sdcc-examples
Example codes using sdcc to target STM8S MCUs.
Stars: ✭ 31 (-60.76%)
Mutual labels:  interrupt
ESP8266TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board. It now supports 16 ISR-based timers, while consuming only 1 hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tas…
Stars: ✭ 85 (+7.59%)
Mutual labels:  interrupt
jean-pierre
A Raspberry Pi robot that helps people make their grocery list.
Stars: ✭ 41 (-48.1%)
Mutual labels:  gpio
cloud4rpi
Cloud4RPi Client Library
Stars: ✭ 21 (-73.42%)
Mutual labels:  beaglebone-black
STM32 TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an STM32F/L/H/G/WB/MP1-based board. These STM32F/L/H/G/WB/MP1 Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micr…
Stars: ✭ 27 (-65.82%)
Mutual labels:  interrupt
awesome-embedded-swift
⚡️🛠🧰 A curated list for Embedded and Low-Level development in the Swift programming language.
Stars: ✭ 57 (-27.85%)
Mutual labels:  gpio
Acapela
Acapela is... a-cape-for-Bela, and a box.
Stars: ✭ 15 (-81.01%)
Mutual labels:  beaglebone-black
saklarku
Aplikasi mobile remote control untuk mengendalikan saklar/relay yang terhubung dengan port LED/GPIO di router berbasis OpenWRT
Stars: ✭ 20 (-74.68%)
Mutual labels:  gpio
TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an Arduino, such as Nano, UNO, Mega, etc. It now supports 16 ISR-based timers, while consuming only 1 hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behavin…
Stars: ✭ 76 (-3.8%)
Mutual labels:  interrupt
Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Stars: ✭ 43 (-45.57%)
Mutual labels:  gpio
hx711
HX711 full function driver for general MCU and Linux.
Stars: ✭ 67 (-15.19%)
Mutual labels:  gpio
go-bsbmp
Golang library to interact with Bosch Sensortec BMP180/BMP280/BME280/BMP388 temperature, pressure and humidity sensors via I2C-bus from Raspberry PI.
Stars: ✭ 41 (-48.1%)
Mutual labels:  gpio

Build Status npm Version Downloads Per Month

epoll

A low-level Node.js binding for the Linux epoll API for monitoring multiple file descriptors to see if I/O is possible on any of them.

This module was initially written to detect EPOLLPRI events indicating that urgent data is available for reading. EPOLLPRI events are triggered by interrupt generating GPIO pins. The epoll module is used by onoff to detect such interrupts.

epoll supports Node.js versions 10, 12, 14, 15 and 16.

Installation

Note that although it should be possible to install epoll on non-Linux systems the functionality offered by epoll is only available on Linux systems.

npm install epoll

API

  • Epoll(callback) - Constructor. The callback is called when epoll events occur and it gets three arguments (err, fd, events).
  • add(fd, events) - Register file descriptor fd for the event types specified by events.
  • remove(fd) - Deregister file descriptor fd.
  • modify(fd, events) - Change the event types associated with file descriptor fd to those specified by events.
  • close() - Deregisters all file descriptors and free resources.

Event Types

  • Epoll.EPOLLIN
  • Epoll.EPOLLOUT
  • Epoll.EPOLLRDHUP
  • Epoll.EPOLLPRI
  • Epoll.EPOLLERR
  • Epoll.EPOLLHUP
  • Epoll.EPOLLET
  • Epoll.EPOLLONESHOT

Event types can be combined with | when calling add or modify. For example, Epoll.EPOLLPRI | Epoll.EPOLLONESHOT could be passed to add to detect a single GPIO interrupt.

Example - Watching Buttons

The following example shows how epoll can be used to detect interrupts from a momentary push-button connected to GPIO4 (pin P1-7) on the Raspberry Pi. The source code is available in the example directory and can easily be modified for using a different GPIO on the Pi or a different platform such as the BeagleBone.

The first step is to export GPIO4 as an interrupt generating input using the export bash script from the examples directory.

./export

export:

#!/bin/sh
echo 4 > /sys/class/gpio/export
sleep 1
echo in > /sys/class/gpio/gpio4/direction
echo both > /sys/class/gpio/gpio4/edge

Then run watch-button to be notified every time the button is pressed and released. If there is no hardware debounce circuit for the push-button, contact bounce issues are very likely to be visible on the console output. watch-button terminates automatically after 30 seconds.

node watch-button

watch-button:

const Epoll = require('epoll').Epoll;
const fs = require('fs');

const valuefd = fs.openSync('/sys/class/gpio/gpio4/value', 'r');
const buffer = Buffer.alloc(1);

// Create a new Epoll. The callback is the interrupt handler.
const poller = new Epoll((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(_ => {
  poller.remove(valuefd).close();
}, 30000);

When watch-button has terminated, GPIO4 can be unexported using the unexport bash script.

./unexport

unexport:

#!/bin/sh
echo 4 > /sys/class/gpio/unexport

Example - Interrupts Per Second

The following example shows how epoll can be used to determine the number of hardware interrupts that can be handled per second on the Raspberry Pi. The source code is available in the example directory and can easily be modified to use different GPIOs on the Raspberry Pi or a different platform such as the BeagleBone.

In this example, GPIO7 is wired to one end of a 1kΩ current limiting resistor and GPIO8 is wired to the other end of the resistor. GPIO7 is an input and GPIO8 is an output.

The first step is to export GPIOs #7 and #8 using the export bash script from the examples directory.

./export

export:

#!/bin/sh
echo 7 > /sys/class/gpio/export
echo 8 > /sys/class/gpio/export
sleep 1
echo in > /sys/class/gpio/gpio7/direction
echo both > /sys/class/gpio/gpio7/edge
echo out > /sys/class/gpio/gpio8/direction

Then run interrupts-per-second. interrupts-per-second toggles the state of the output every time it detects an interrupt on the input. Each toggle will trigger the next interrupt. After five seconds, interrupts-per-second prints the number of interrupts it detected per second.

node interrupts-per-second

interrupts-per-second:

const Epoll = require('../../').Epoll;
const fs = require('fs');

const value = Buffer.alloc(1); // The three Buffers here are global
const zero = Buffer.from('0'); // to improve performance.
const one = Buffer.from('1');

const inputfd = fs.openSync('/sys/class/gpio/gpio7/value', 'r+');
const outputfd = fs.openSync('/sys/class/gpio/gpio8/value', 'r+');

let count = 0;

// Create a new Epoll. The callback is the interrupt handler.
const poller = new Epoll((err, fd, events) => {
  count += 1;

  // Read GPIO value file. Reading also clears the interrupt.
  fs.readSync(inputfd, value, 0, 1, 0);

  // Toggle GPIO value. This will eventually result
  // in the next interrupt being triggered.
  const nextValue = value[0] === zero[0] ? one : zero;
  fs.writeSync(outputfd, nextValue, 0, nextValue.length, 0);
});

let time = process.hrtime(); // Get start time.

// Start watching for interrupts. This will trigger the first interrupt
// as the value file already has data waiting for a read.
poller.add(inputfd, Epoll.EPOLLPRI);

// Print interrupt rate to console after 5 seconds.
setTimeout(_ => {
  time = process.hrtime(time); // Get run time.
  const rate = Math.floor(count / (time[0] + time[1] / 1E9));
  console.log(rate + ' interrupts per second');

  // Stop watching.
  poller.remove(inputfd).close();
}, 5000);

When interrupts-per-second has terminated, GPIOs #7 and #8 can be unexported using the unexport bash script.

./unexport

unexport:

#!/bin/sh
echo 7 > /sys/class/gpio/unexport
echo 8 > /sys/class/gpio/unexport

Here are some results from the "Interrupts Per Second" example.

Raspberry Pi 4 Model B, Raspberry Pi OS (March 4th 2021, Debian 10.8):

node epoll kernel interrupts / sec
v16.0.0 v4.0.1 5.10.17-v7l+ 20112
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].