Skip to content

Commit

Permalink
devLib support
Browse files Browse the repository at this point in the history
  • Loading branch information
nekuz0r committed Jul 4, 2014
1 parent 97e2ac1 commit 2df87c1
Show file tree
Hide file tree
Showing 22 changed files with 829 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
* **Add:** CHANGELOG.md `nekuz0r`
* **Add:** wiringPiI2C support `nekuz0r`
* **Add:** wiring-pi install gpio utilty (required for interrupts) `nekuz0r`
* **Add:** ds1302 support `nekuz0r`
* **Add:** gertboard support `nekuz0r`
* **Add:** lcd support `nekuz0r`
* **Add:** lcd128x64 support `nekuz0r`
* **Add:** maxdetect support `nekuz0r`
* **Add:** piFace support `nekuz0r`
* **Add:** piGlow support `nekuz0r`
* **Add:** piNes support `nekuz0r`
* **Fictitious:** this release eats Pi(e)s :)

## v1.1.1 *[not released yet]*
* **Fix:** missing constant in pinModeCheck `nekuz0r`
Expand Down
13 changes: 12 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@
'src/extensions/sn3218.cc',
'src/extensions/sr595.cc',
'src/extensions/pca9685.cc'

'src/devlib/devlib.cc',
'src/devlib/ds1302.cc',
'src/devlib/gertboard.cc',
'src/devlib/lcd.cc',
'src/devlib/lcd128x64.cc',
'src/devlib/maxdetect.cc',
'src/devlib/piFace.cc',
'src/devlib/piGlow.cc',
'src/devlib/piNes.cc',
],
'include_dirs': [
'wiringpi/wiringPi'
],
'libraries': [
'<!(pwd)/wiringpi/wiringPi/libwiringPi.a'
'<!(pwd)/wiringpi/wiringPi/libwiringPi.a',
'<!(pwd)/wiringpi/devLib/libwiringPiDev.a'
],
'cflags': [
'-Wall'
Expand Down
21 changes: 21 additions & 0 deletions src/devlib/devlib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "devlib.h"

#include "ds1302.h"
#include "gertboard.h"
#include "lcd.h"
#include "lcd128x64.h"
#include "maxdetect.h"
#include "piFace.h"
#include "piGlow.h"
#include "piNew.h"

IMPLEMENT_EXPORT_INIT(devlib) {
INIT(ds1302);
INIT(gertboard);
INIT(lcd);
INIT(lcd128x64);
INIT(maxdetect);
INIT(piFace);
INIT(piGlow);
INIT(piNes);
}
8 changes: 8 additions & 0 deletions src/devlib/devlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _WPI_DEV_LIB_H_
#define _WPI_DEV_LIB_H_

#include "../addon.h"

DECLARE_EXPORT_INIT(devlib);

#endif
176 changes: 176 additions & 0 deletions src/devlib/ds1302.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#EXPORT_FUNCTION "ds1302.h"
#include <ds1302.h>

DECLARE(ds1302rtcRead);
DECLARE(ds1302rtcWrite);
DECLARE(ds1302ramRead);
DECLARE(ds1302ramWrite);
DECLARE(ds1302clockRead);
DECLARE(ds1302clockWrite);
DECLARE(ds1302trickleCharge);
DECLARE(ds1302setup);

// Func: unsigned int ds1302rtcRead (const int reg)
// Description: Reads the data to/from the RTC register

IMPLEMENT(ds1302rtcRead) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, reg);

CHECK_ARGUMENTS_LENGTH_EQUAL(1);

CHECK_ARGUMENT_TYPE_INT32(0);

int reg = GET_ARGUMENT_AS_INT32(0);

unsigned int res = ::ds1302rtcRead(reg);

SCOPE_CLOSE(UINT32(res));
}

// Func: void ds1302rtcWrite (int reg, unsigned int data)
// Description: Writes the data to/from the RTC register

IMPLEMENT(ds1302rtcWrite) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, reg);
SET_ARGUMENT_NAME(1, data);

CHECK_ARGUMENTS_LENGTH_EQUAL(2);

CHECK_ARGUMENT_TYPE_INT32(0);

int reg = GET_ARGUMENT_AS_INT32(0);
unsigned int data = GET_ARGUMENT_AS_UINT32(1);

::ds1302rtcWrite(reg, data);

SCOPE_CLOSE(UNDEFINED());
}

IMPLEMENT(ds1302ramRead) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, address);

CHECK_ARGUMENTS_LENGTH_EQUAL(1);

CHECK_ARGUMENT_TYPE_INT32(0);

int address = GET_ARGUMENT_AS_INT32(0);

unsigned int res = ::ds1302ramRead(address);

SCOPE_CLOSE(UINT32(res));
}

IMPLEMENT(ds1302ramWrite) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, address);
SET_ARGUMENT_NAME(1, data);

CHECK_ARGUMENTS_LENGTH_EQUAL(2);

CHECK_ARGUMENT_TYPE_INT32(0);
CHECK_ARGUMENT_TYPE_UINT32(1);

int address = GET_ARGUMENT_AS_INT32(0);
unsigned int data = GET_ARGUMENT_AS_UINT32(1);

::ds1302ramWrite(address, data);

SCOPE_CLOSE(UNDEFINED());
}

IMPLEMENT(ds1302clockRead) {
SCOPE_OPEN();

CHECK_ARGUMENTS_LENGTH_EQUAL(0);

int clockData[8];
::ds1302clockRead(clockData);

v8::Local<v8::Array> res = v8::Array::New(8);
for (int i = 0; i < 8; i++) {
res->Set(i, v8::Int32::New(clockData[i]));
}

SCOPE_CLOSE(res);
}

IMPLEMENT(ds1302clockWrite) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, clockData);

CHECK_ARGUMENTS_LENGTH_EQUAL(1);

CHECK_ARGUMENT_TYPE_ARRAY(0);
CHECK_ARGUMENT_ARRAY_LENGTH(0, 8);

v8::Local<v8::Array> clockData = v8::Local<v8::Array>::Cast(args[0]);

int ar[8];
for (int i = 0; i < 8; i++) {
ar[i] = clockData->Get(i)->Int32Value();
}

::ds1302clockWrite(ar);

SCOPE_CLOSE(UNDEFINED());
}

IMPLEMENT(ds1302trickleCharge) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, diodes);
SET_ARGUMENT_NAME(1, resistors);

CHECK_ARGUMENTS_LENGTH_EQUAL(2);

CHECK_ARGUMENT_TYPE_INT32(0);
CHECK_ARGUMENT_TYPE_INT32(1);

int diodes = GET_ARGUMENT_AS_INT32(0);
int resistors = GET_ARGUMENT_AS_INT32(1);

::ds1302trickleCharge(diodes, resistors);

SCOPE_CLOSE(UNDEFINED());
}

IMPLEMENT(ds1302setup) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, clockPin);
SET_ARGUMENT_NAME(1, dataPin);
SET_ARGUMENT_NAME(2, csPin);

CHECK_ARGUMENTS_LENGTH_EQUAL(3);

CHECK_ARGUMENT_TYPE_INT32(0);
CHECK_ARGUMENT_TYPE_INT32(1);
CHECK_ARGUMENT_TYPE_INT32(2);

int clockPin = GET_ARGUMENT_AS_INT32(0);
int dataPin = GET_ARGUMENT_AS_INT32(1);
int csPin = GET_ARGUMENT_AS_INT32(2);

::ds1302setup(clockPin, dataPin, csPin);

SCOPE_CLOSE(UNDEFINED());
}

IMPLEMENT_EXPORT_INIT(ds1302) {
EXPORT_FUNCTION(ds1302rtcRead);
EXPORT_FUNCTION(ds1302rtcWrite);
EXPORT_FUNCTION(ds1302ramRead);
EXPORT_FUNCTION(ds1302ramWrite);
EXPORT_FUNCTION(ds1302clockRead);
EXPORT_FUNCTION(ds1302clockWrite);
EXPORT_FUNCTION(ds1302trickleCharge);
EXPORT_FUNCTION(ds1302setup);
}
8 changes: 8 additions & 0 deletions src/devlib/ds1302.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _WPI_DS1302_H_
#define _WPI_DS1302_H_

#include "../addon.h"

DECLARE_EXPORT_INIT(ds1302);

#endif
24 changes: 24 additions & 0 deletions src/devlib/gertboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "gertboard.h"
#include <gertboard.h>

DECLARE(gertboardAnalogSetup);

IMPLEMENT(gertboardAnalogSetup) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, pinBase);

CHECK_ARGUMENTS_LENGTH_EQUAL(1);

CHECK_ARGUMENT_TYPE_INT32(0);

int pinBase = GET_ARGUMENT_AS_INT32(0);

int res = ::getboardAnalogSetup(pinBase);

SCOPE_CLOSE(INT32(res));
}

IMPLEMENT_EXPORT_INIT(gertboard) {
EXPORT_FUNCTION(gertboardAnalogSetup);
}
8 changes: 8 additions & 0 deletions src/devlib/gertboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _WPI_GERTBOARD_H_
#define _WPI_GERTBOARD_H_

#include "../addon.h"

DECLARE_EXPORT_INIT(gertboard);

#endif
Loading

0 comments on commit 2df87c1

Please sign in to comment.