Skip to content

Commit

Permalink
no idea why the RF24 library lets us initialize two different ways, b…
Browse files Browse the repository at this point in the history
…ut it does not work without spidevice set…
  • Loading branch information
natevw committed Aug 14, 2013
1 parent 14aa4a8 commit 3a6266d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions index.js
Expand Up @@ -2,9 +2,12 @@
// see https://github.com/arunoda/node-usage as an example
var _rf24 = require("./build/Release/rf24");

exports.radio = function (ce, cs) {
ce || (ce = 8);
cs || (cs = 25);
exports.radio = function (dev, speed, ce) {
dev = "/dev/spidev0.0";
speed = 8000000;
ce = 25;
// TODO: improve argument handling

var xcvr = new _rf24.Wrapper(ce,cs),
radio = {};

Expand Down
11 changes: 6 additions & 5 deletions rf24-wrapper.cc
Expand Up @@ -15,7 +15,7 @@ class Wrapper : public node::ObjectWrap {
uv_mutex_t radioAccess;

private:
Wrapper(uint8_t ce, uint8_t cs);
Wrapper(string spi, uint32_t spd, uint8_t ce);
~Wrapper();

static Handle<Value> New(const Arguments& args);
Expand Down Expand Up @@ -100,7 +100,7 @@ void FinishRadioCall(uv_work_t* req) {
}
}

Wrapper::Wrapper(uint8_t ce, uint8_t cs) : radio(ce,cs) {
Wrapper::Wrapper(string spi, uint32_t spd, uint8_t ce) : radio(spi,spd,ce) {
uv_mutex_init(&radioAccess);
};
Wrapper::~Wrapper() {
Expand All @@ -126,11 +126,12 @@ void Wrapper::Init(Handle<Object> exports) {
Handle<Value> Wrapper::New(const Arguments& args) {
HandleScope scope;

assert(args.Length() == 2);
assert(args[0]->IsNumber());
assert(args.Length() == 3);
assert(args[0]->IsString());
assert(args[1]->IsNumber());
assert(args[2]->IsNumber());

Wrapper* obj = new Wrapper(args[0]->NumberValue(), args[1]->NumberValue());
Wrapper* obj = new Wrapper(*String::Utf8Value(args[0]->ToString()), args[1]->NumberValue(), args[2]->NumberValue());
obj->Wrap(args.This());

return args.This();
Expand Down

0 comments on commit 3a6266d

Please sign in to comment.