WiringPi / WiringPi-Node

Node.js bindings to wiringPi
333 stars 94 forks source link

Clairification on what value 'delta' will have in the wiringPiISR callback. #65

Open TheNotary opened 7 years ago

TheNotary commented 7 years ago

According to the docs on interrupts the callback to wiringPiISR has a parameter (it is named delta in the example). It seems to spit out random integers when I print those to the screen. What do those ints represent?

r1ch commented 7 years ago

Yes - it's a bit of a mystery! Looking at the C code that's backing the function we've got: https://github.com/WiringPi/WiringPi-Node/blob/master/src/wiringPiISR.cc

(I've cut only the relevant lines)

unsigned int now = ::micros();
data->delta = now - data->previous_timestamp;
data->previous_timestamp = now;

It's an (educated!) guess but I think it's the microseconds elapsed since the last interrupt.

Still - I was led here by Google with the same question so... any other answers appreciated!