Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Soarez committed Dec 19, 2012
0 parents commit e3f7846
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "deps/wiringPi"]
path = deps/wiringPi
url = git://git.drogon.net/wiringPi
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
Bindings to wiringPi
25 changes: 25 additions & 0 deletions binding.gyp
@@ -0,0 +1,25 @@
{
'targets': [
{
'target_name': 'wiringPi',
'sources': [
'src/bindings.cc',
'deps/wiringPi/wiringPi/libwiringPi.a'
],
'include_dirs': [
'deps/wiringPi/wiringPi'
],
'actions': [
{
'action_name': 'MOIKA',
'inputs': [
],
'outputs': [
'deps/wiringPi/wiringPi/libwiringPi.a'
],
'action': ['echo', '"EXPERIMENT OUTFILE" > deps/wiringPi/wiringPi/libwiringPi.a']
}
]
}
]
}
9 changes: 9 additions & 0 deletions build.sh
@@ -0,0 +1,9 @@
#!/bin/bash

PWD="`pwd`"

cd `dirname $0`/deps/wiringPi/wiringPi
make
cd "$pwd"

node-gyp rebuild
1 change: 1 addition & 0 deletions deps/wiringPi
Submodule wiringPi added at 25e4ec
15 changes: 15 additions & 0 deletions lib/exports.js
@@ -0,0 +1,15 @@
function merge(obj, tgt) {
for(var p in obj)
if (obj.hasOwnProperty(p))
tgt[p] = obj[p];
}

var c = require('../build/Release/wpi');

exports = {
VERSION: require('../package').version
};

merge(c, exports);

module.exports = exports;
24 changes: 24 additions & 0 deletions package.json
@@ -0,0 +1,24 @@
{
"name": "wiringPi",
"version": "0.1.0",
"description": "Bindings to wiringPi",
"main": "lib/exports.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "./build.sh"
},
"repository": {
"type": "git",
"url": "/Users/Soarez/src/soarez/node-wiring-pi.git"
},
"keywords": [
"wiringPi",
"gpio",
"raspberry",
"pi",
"raspberrypi",
"bcm2835"
],
"author": "Igor Soarez <igorsoarez@gmail.com>",
"license": "BSD"
}
84 changes: 84 additions & 0 deletions src/bindings.cc
@@ -0,0 +1,84 @@
#include <node.h>
#include <v8.h>

#include <wiringPi.h>

using namespace v8;

#define DECLARE(name) \
static Handle<Value> name(const Arguments& args)
#define IMPLEMENT(name) \
Handle<Value> wpi::name(const Arguments& args)
#define EXPORT(name) \
target->Set(String::NewSymbol("name"), \
FunctionTemplate::New(wpi::name)->GetFunction())

namespace wpi {
DECLARE(wiringPiSetup);
DECLARE(pinMode);
DECLARE(digitalWrite);
}

IMPLEMENT(wiringPiSetup) {
HandleScope scope;
int res;

if (args.Length() != 0) {
ThrowException(Exception::TypeError(
String::New("Wrong number of arguments.")));
return scope.Close(Undefined());
}

res = ::wiringPiSetup()

return scope.Close(Int32::New(res));
}

IMPLEMENT(pinMode) {
HandleScope scope;
int res;

if (args.Length() != 2) {
ThrowException(Exception::TypeError(
String::New("Wrong number of arguments.")));
return scope.Close(Undefined());
}

if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
ThrowException(Exception::TypeError(
String::New("Incorrect argument types. Numbers expected.")));
return scope.Close(Undefined());
}

res = ::pinMode(args[0]->NumberValue(), args[1]->NumberValue());

return scope.Close(Int32::New(res));
}

IMPLEMENT(digitalWrite) {
HandleScope scope;
int res;

if (args.Length() != 2) {
ThrowException(Exception::TypeError(
String::New("Wrong number of arguments.")));
return scope.Close(Undefined());
}

if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
ThrowException(Exception::TypeError(
String::New("Incorrect argument types. Numbers expected.")));
return scope.Close(Undefined());
}

res = ::digitalWrite(args[0]->NumberValue(), args[1]->NumberValue());

return scope.Close(Int32::New(res));
}

void init(Handle<Object> target) {
EXPORT(wiringPiSetup);
EXPORT(pinMode);
EXPORT(digitalWrite);
}
NODE_MODULE(wiringPi, init)

0 comments on commit e3f7846

Please sign in to comment.