fivdi / pigpio

Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
MIT License
948 stars 89 forks source link

Adds support for waves functions #95

Closed schoero closed 4 years ago

schoero commented 4 years ago

This pull request adds Wave functionality and resolves #38 and closes #64 and is basically a continuation of #64

It also adds ticks to the interrupt event as discussed here

The following methods where added:

The wave methods where tested using a Raspberry Pi 3B+ and verified using an oscilloscope.

fivdi commented 4 years ago

@Rogerrrrrrrs thank you for submitting this PR and all the work you have done on it, @AnthonyMyatt, @bahamut657 and thank you for your work on this PR too.

@Rogerrrrrrrs

All the new wave methods are currently methods in class Gpio. Why is this the case? Would it not be better if they were functions in global?

When the PR is installed with Node.js v13.5.0 using the command npm i https://github.com/Rogerrrrrrrs/pigpio.git#Waves there are compile errors that need to be fixed.

Node.js v13.5.0 Compile Errors

``` pi@raspberrypi:~/pigpio $ npm i https://github.com/Rogerrrrrrrs/pigpio.git#Waves > pigpio@2.0.1 install /home/pi/pigpio/node_modules/pigpio > node-gyp rebuild make: Entering directory '/home/pi/pigpio/node_modules/pigpio/build' CXX(target) Release/obj.target/pigpio/src/pigpio.o ../src/pigpio.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE gpioWaveAddGeneric(Nan::NAN_METHOD_ARGS_TYPE)’: ../src/pigpio.cc:746:50: error: no matching function for call to ‘v8::Array::Get(unsigned int&)’ v8::Local element = array->Get(i); ^ In file included from /home/pi/.cache/node-gyp/13.5.0/include/node/node.h:63, from ../../nan/nan.h:54, from ../src/pigpio.cc:3: /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate expects 2 arguments, 1 provided /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate expects 2 arguments, 1 provided ../src/pigpio.cc:756:90: error: no matching function for call to ‘v8::Object::Get(v8::MaybeLocal)’ cal < v8::Value > _on = pulse->Get(v8::String::NewFromUtf8(isolate, "gpioOn")); ^ In file included from /home/pi/.cache/node-gyp/13.5.0/include/node/node.h:63, from ../../nan/nan.h:54, from ../src/pigpio.cc:3: /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate expects 2 arguments, 1 provided /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate expects 2 arguments, 1 provided ../src/pigpio.cc:757:92: error: no matching function for call to ‘v8::Object::Get(v8::MaybeLocal)’ l < v8::Value > _off = pulse->Get(v8::String::NewFromUtf8(isolate, "gpioOff")); ^ In file included from /home/pi/.cache/node-gyp/13.5.0/include/node/node.h:63, from ../../nan/nan.h:54, from ../src/pigpio.cc:3: /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate expects 2 arguments, 1 provided /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate expects 2 arguments, 1 provided ../src/pigpio.cc:758:94: error: no matching function for call to ‘v8::Object::Get(v8::MaybeLocal)’ < v8::Value > _delay = pulse->Get(v8::String::NewFromUtf8(isolate, "usDelay")); ^ In file included from /home/pi/.cache/node-gyp/13.5.0/include/node/node.h:63, from ../../nan/nan.h:54, from ../src/pigpio.cc:3: /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3594:43: note: candidate expects 2 arguments, 1 provided /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate: ‘v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)’ V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, ^~~ /home/pi/.cache/node-gyp/13.5.0/include/node/v8.h:3597:43: note: candidate expects 2 arguments, 1 provided make: *** [pigpio.target.mk:111: Release/obj.target/pigpio/src/pigpio.o] Error 1 make: Leaving directory '/home/pi/pigpio/node_modules/pigpio/build' gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/home/pi/opt/node-v13.5.0-linux-armv7l/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23) gyp ERR! stack at ChildProcess.emit (events.js:305:20) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) gyp ERR! System Linux 4.19.75-v7l+ gyp ERR! command "/home/pi/opt/node-v13.5.0-linux-armv7l/bin/node" "/home/pi/opt/node-v13.5.0-linux-armv7l/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/pi/pigpio/node_modules/pigpio gyp ERR! node -v v13.5.0 gyp ERR! node-gyp -v v5.0.5 gyp ERR! not ok npm WARN enoent ENOENT: no such file or directory, open '/home/pi/pigpio/package.json' npm WARN pigpio No description npm WARN pigpio No repository field. npm WARN pigpio No README data npm WARN pigpio No license field. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! pigpio@2.0.1 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the pigpio@2.0.1 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/pi/.npm/_logs/2020-01-10T23_08_34_457Z-debug.log pi@raspberrypi:~/pigpio $ ```

I'm in the process of reviewing the PR.

fivdi commented 4 years ago

@Rogerrrrrrrs If you're not sure how to fix the compile errors that occur when installing with with Node.js v13.5.0 please let me know and I'll take a look. There are no compile errors with Node.js v8, v10 and v12 and everything functions correctly.

schoero commented 4 years ago

@fivdi Thank you, I would be happy to take your help on the compile errors.

All the new wave methods are currently methods in class Gpio. Why is this the case? Would it not be better if they were functions in global?

You are right, there is no benefit being a member of Gpio.

I agree with the requested changes and will take a look at it now.

fivdi commented 4 years ago

@Rogerrrrrrrs please let me know when you think you're finished.

schoero commented 4 years ago

@fivdi I have moved the wave functions to the global level. I have updated the documentation, examples and tests. When I did that, I also had to update the return values of the functions that previously returned this. It also builds now without errors on node 13 thanks to your help. I think you can review it again.

fivdi commented 4 years ago

@Rogerrrrrrrs , @bahamut657, @AnthonyMyatt Thank you all very much for working on the PR.

AnthonyMyatt commented 4 years ago

Glad I could play a part.

fivdi commented 4 years ago

This PR has now been published with pigpio@3.0.0 on npm.

cinderblock commented 4 years ago

@fivdi Were there any breaking changes in the 3.0.0 release besides dropping node 6? What about the 2.0.0 release?

fivdi commented 4 years ago

There were no breaking changes in v2.0.0 or v3.0.0.