Code Monkey home page Code Monkey logo

Comments (8)

nekuz0r avatar nekuz0r commented on September 17, 2024

Hi,

There is actually no way to remove an interrupt once wiringPiISR has been called. libWiringPi does not provide a way to remove an interrupt handler.

I am searching a way to keep the node process running.

from wiringpi-node.

nekuz0r avatar nekuz0r commented on September 17, 2024

As a temporary fix you can use : setInterval(function(){},10000); that will call an empty callback each 10s and keep the process running.

from wiringpi-node.

nekuz0r avatar nekuz0r commented on September 17, 2024

Cancelling an interrupt handler

A little modification of the libWiringPi should allow us to cancel an interrupt handler.
Making wiringPiISR in libWiringPi returning the thread id stored in threadId by a successful call to pthread_create instead of 0.
Then we could call pthread_cancel to cancel the interrupt handler.

Interrupt handler keeps event loop running

A way to keep the node process running when calling wiringPiISR is to create a dummy event loop, something like this:

static void UV_ASYNC_NOP(uv_async_t* handler, int status) {}

wiringPiISR(pin, ...) {
  ...
  uv_async_init(uv_default_loop(), &handlers[pin], &UV_ASYNC_NOP);
  uv_ref((uv_handle_t*)&handlers[pin]);
  ...
  threadIds[pin] = ::wiringPiISR(pin, ...);
}

wiringPiCancelISR(pin) {
  ::wiringPiCancelISR(threadIds[pin]);
  uv_close((uv_handle_t*)&handlers[pin]);
}

from wiringpi-node.

eugeneware avatar eugeneware commented on September 17, 2024

LGTM

from wiringpi-node.

nekuz0r avatar nekuz0r commented on September 17, 2024

I implemented it in the incoming branch, can you test it ? I don't have a rpi within easy reach atm.
To install:
npm install git+https://github.com/nekuz0r/wiring-pi.git#incoming

wiringPiISR should keep the main event loop running
wiringPiISRCancel(pin) should cancel the interrupt handler and if it's the last one running terminates the node process

from wiringpi-node.

LouTerrailloune avatar LouTerrailloune commented on September 17, 2024

Just tested it, seems to work perfectly.

from wiringpi-node.

nekuz0r avatar nekuz0r commented on September 17, 2024

Found a way to achieve it without modify the signature of the wiringPiISR function.
I prefer doing it that way, so i leave it untouched.
I'll commit it to incoming soon.

from wiringpi-node.

LouTerrailloune avatar LouTerrailloune commented on September 17, 2024

Ping me when it's ready to test, however, I've switched to https://github.com/fivdi/onoff which deals with that interrupt issue in a better way. (no more ugly fork() !)

from wiringpi-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.