jeremyscalpello / chip-gpio Goto Github PK
View Code? Open in Web Editor NEWGPIO access for CHIP and Node.JS
License: MIT License
GPIO access for CHIP and Node.JS
License: MIT License
What this mapping actually stands for?
var MAPPING = [408, 409, 410, 411, 412, 413, 414, 415];
Does chip-gpio works with all the chip's GPIO? Perhaps shouldn't we make like a TODO list for this lib? I could help filling the missing pieces.
Hey, I love this little library. Thanks for making it!
I'm however using this with 4.4.13 and the mappings have changed. I see that you've accepted a merge request that fixes this issue. Could you please publish this change to npm?
$ npm version patch # Updates package.json to version 1.1.1 and creates a git commit and tag
$ npm publish
I think this should be marked as a "patch" as it's not technically adding any features. It's also kind of a bug that old versions of this package don't work on the newest kernel.
When terminating a node script from the terminal i receive the error below. This is happening with the test.js
Am i missing something?
^C/home/chip/Desktop/gpio/chip-gpio/gpio.js:16
gpio.unexport();
^
ReferenceError: gpio is not defined
at process.exit (/home/chip/Desktop/gpio/chip-gpio/gpio.js:16:5)
at emitNone (events.js:80:13)
at process.emit (events.js:179:7)
at Signal.wrap.onsignal (node.js:837:46)
In the README, The requirements list build-essential only, where Python is also required to be installed.
After installing Python, chip-gpio was built successfully.
# apt-get install build-essential python
I noticed that chip-gpio is based on onoff and have a question ๐
I took a look at the implementation of chip-gpio and noticed that read method is implemented as follows:
Gpio.prototype.read = function () {
fs.readSync(this.valueFd, this.readBuffer, 0, 1, 0);
var valString = fs.readFileSync(this.gpioPath + 'value', 'utf8');
return parseInt(valString.split('\n')[0]);
//return this.readBuffer[0] === new Buffer('1')[0] ? 1 : 0;
};
This is the equivalent of the readSync method in onoff which is implemented as follows:
Gpio.prototype.readSync = function () {
fs.readSync(this.valueFd, this.readBuffer, 0, 1, 0);
return this.readBuffer[0] === ONE[0] ? 1 : 0;
};
The question is, why was the implementation changed? Did the onoff version not work? I'm afraid I don't have a Chip board to try it out myself.
One more question, do you know if an unmodified version of onoff works on Chip boards?
# npm install chip-gpio --save
-
> [email protected] install /home/chip/secu/node_modules/chip-gpio/node_modules/epoll
> node-gyp rebuild
make: Entering directory '/home/chip/secu/node_modules/chip-gpio/node_modules/epoll/build'
CXX(target) Release/obj.target/epoll/src/epoll.o
In file included from ../src/epoll.cc:15:0:
../node_modules/nan/nan.h:324:47: error: 'REPLACE_INVALID_UTF8' is not a member of 'v8::String'
static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
^
epoll.target.mk:84: recipe for target 'Release/obj.target/epoll/src/epoll.o' failed
make: *** [Release/obj.target/epoll/src/epoll.o] Error 1
make: Leaving directory '/home/chip/secu/node_modules/chip-gpio/node_modules/epoll/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 4.4.13-ntc-mlc
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/chip/secu/node_modules/chip-gpio/node_modules/epoll
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the epoll package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls epoll
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 4.4.13-ntc-mlc
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "chip-gpio" "--save"
npm ERR! cwd /home/chip/secu
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/chip/secu/npm-debug.log
npm ERR! not ok code 0
I found the workaround here: https://github.com/fivdi/onoff/wiki/Node.js-v0.10.29-and-native-addons-on-the-Raspberry-Pi
Running the sample code, I get the following error:
/home/chip/secu/node_modules/chip-gpio/index.js:7
if (os.release().startsWith("4.4")) {
^
TypeError: Object 4.4.13-ntc-mlc has no method 'startsWith'
at Object.<anonymous> (/home/chip/secu/node_modules/chip-gpio/index.js:7:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/chip/secu/test.js:1:74)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
CHIP OS 1.1 (4.4 Kernel) changed the XIO sysfs numbers and they no longer start at 408. Your code will not work on the with the newer CHIP OS.
Reference https://gist.github.com/howientc/606545e0ff47e2cda61f14fca5c46eee for @howientc's python gist that allows you to correctly get the current XIO base.
I would fork, add the feature, and then submit a pull request to you, but I'm not well versed in Javascript/Node.JS code.
Just wondering if the Chip Pro board is also supported. Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.