diff --git a/CHANGELOG.md b/CHANGELOG.md index 78996d4..b2eae93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/binding.gyp b/binding.gyp index 43d8d9a..3541dfe 100644 --- a/binding.gyp +++ b/binding.gyp @@ -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': [ - ' + +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 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 clockData = v8::Local::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); +} \ No newline at end of file diff --git a/src/devlib/ds1302.h b/src/devlib/ds1302.h new file mode 100644 index 0000000..349d2e5 --- /dev/null +++ b/src/devlib/ds1302.h @@ -0,0 +1,8 @@ +#ifndef _WPI_DS1302_H_ +#define _WPI_DS1302_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(ds1302); + +#endif \ No newline at end of file diff --git a/src/devlib/gertboard.cc b/src/devlib/gertboard.cc new file mode 100644 index 0000000..17387b3 --- /dev/null +++ b/src/devlib/gertboard.cc @@ -0,0 +1,24 @@ +#include "gertboard.h" +#include + +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); +} \ No newline at end of file diff --git a/src/devlib/gertboard.h b/src/devlib/gertboard.h new file mode 100644 index 0000000..f9d1ea1 --- /dev/null +++ b/src/devlib/gertboard.h @@ -0,0 +1,8 @@ +#ifndef _WPI_GERTBOARD_H_ +#define _WPI_GERTBOARD_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(gertboard); + +#endif \ No newline at end of file diff --git a/src/devlib/lcd.cc b/src/devlib/lcd.cc new file mode 100644 index 0000000..8866800 --- /dev/null +++ b/src/devlib/lcd.cc @@ -0,0 +1,284 @@ +#include "lcd.h" +#include + +DECLARE(lcdHome); +DECLARE(lcdClear); +DECLARE(lcdDisplay); +DECLARE(lcdCursor); +DECLARE(lcdCursorBlink); +DECLARE(lcdSendCommand); +DECLARE(lcdPosition); +DECLARE(lcdCharDef); +DECLARE(lcdPutchar); +DECLARE(lcdPuts); +DECLARE(lcdPrintf); +DECLARE(lcdInit); + +IMPLEMENT(lcdHome) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int fd = GET_ARGUMENT_AS_INT32(0); + + ::lcdHome(fd); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdClear) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int fd = GET_ARGUMENT_AS_INT32(0); + + ::lcdClear(fd); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdDisplay) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, state); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + int state = GET_ARGUMENT_AS_INT32(1); + + ::lcdDisplay(fd, state); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdCursor) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, state); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + int state = GET_ARGUMENT_AS_INT32(1); + + ::lcdCursor(fd, state); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdCursorBlink) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, state); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + int state = GET_ARGUMENT_AS_INT32(1); + + ::lcdCursorBlink(fd, state); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdSendCommand) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, command); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_UINT32(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + int command = GET_ARGUMENT_AS_UINT32(1); + + ::lcdSendCommand(fd, command); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdPosition) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, x); + SET_ARGUMENT_NAME(2, y); + + CHECK_ARGUMENTS_LENGTH_EQUAL(3); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + CHECK_ARGUMENT_TYPE_INT32(2); + + int fd = GET_ARGUMENT_AS_INT32(0); + int x = GET_ARGUMENT_AS_INT32(1); + int y = GET_ARGUMENT_AS_INT32(2); + + ::lcdPosition(fd, x, y); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdCharDef) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, index); + SET_ARGUMENT_NAME(2, data); + + CHECK_ARGUMENTS_LENGTH_EQUAL(3); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + CHECK_ARGUMENT_TYPE_ARRAY(2); + CHECK_ARGUMENT_ARRAY_LENGTH(8); + + int fd = GET_ARGUMENT_AS_INT32(0); + int index = GET_ARGUMENT_AS_INT32(1); + v8::Local data = v8::Local::Cast(args[2]); + + unsigned int ar[8]; + for (int i = 0; i < 8; i++) { + ar[i] = data->Get(i)->Uint32Value(); + } + + ::lcdCharDef(fd, index, ar); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdPutchar) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, data); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_UINT32(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + unsigned int data = GET_ARGUMENT_AS_UINT32(1); + + ::lcdPutchar(fd, data); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdPuts) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, fd); + SET_ARGUMENT_NAME(1, string); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_STRING(1); + + int fd = GET_ARGUMENT_AS_INT32(0); + v8::String::AsciiValue data(GET_ARGUMENT_AS_STRING(1)); + + ::lcdPuts(fd, *data); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(lcdPrintf) { + return lcdPuts(args); +} + +IMPLEMENT(lcdInit) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, rows); + SET_ARGUMENT_NAME(1, cols); + SET_ARGUMENT_NAME(2, bits); + SET_ARGUMENT_NAME(3, rs); + SET_ARGUMENT_NAME(4, strb); + SET_ARGUMENT_NAME(5, d0); + SET_ARGUMENT_NAME(6, d1); + SET_ARGUMENT_NAME(7, d2); + SET_ARGUMENT_NAME(8, d3); + SET_ARGUMENT_NAME(9, d4); + SET_ARGUMENT_NAME(10, d5); + SET_ARGUMENT_NAME(11, d6); + SET_ARGUMENT_NAME(12, d7); + + CHECK_ARGUMENTS_LENGTH_EQUAL(13); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + CHECK_ARGUMENT_TYPE_INT32(2); + CHECK_ARGUMENT_TYPE_INT32(3); + CHECK_ARGUMENT_TYPE_INT32(4); + CHECK_ARGUMENT_TYPE_INT32(5); + CHECK_ARGUMENT_TYPE_INT32(6); + CHECK_ARGUMENT_TYPE_INT32(7); + CHECK_ARGUMENT_TYPE_INT32(8); + CHECK_ARGUMENT_TYPE_INT32(9); + CHECK_ARGUMENT_TYPE_INT32(10); + CHECK_ARGUMENT_TYPE_INT32(11); + CHECK_ARGUMENT_TYPE_INT32(12); + + int rows = GET_ARGUMENT_AS_INT32(0); + int cols = GET_ARGUMENT_AS_INT32(1); + int bits = GET_ARGUMENT_AS_INT32(2); + int rs = GET_ARGUMENT_AS_INT32(3); + int strb = GET_ARGUMENT_AS_INT32(4); + int d0 = GET_ARGUMENT_AS_INT32(5); + int d1 = GET_ARGUMENT_AS_INT32(6); + int d2 = GET_ARGUMENT_AS_INT32(7); + int d3 = GET_ARGUMENT_AS_INT32(8); + int d4 = GET_ARGUMENT_AS_INT32(9); + int d5 = GET_ARGUMENT_AS_INT32(10); + int d6 = GET_ARGUMENT_AS_INT32(11); + int d7 = GET_ARGUMENT_AS_INT32(12); + + int res = ::lcdInit(rows, cols, bits, rs, strb, d0, d1, d2, d3, d4, d5, d6, d7); + + SCOPE_CLOSE(INT32(res)); +} + +IMPLEMENT_EXPORT_INIT(lcd) { + EXPORT_FUNCTION(lcdHome); + EXPORT_FUNCTION(lcdClear); + EXPORT_FUNCTION(lcdDisplay); + EXPORT_FUNCTION(lcdCursor); + EXPORT_FUNCTION(lcdCursorBlink); + EXPORT_FUNCTION(lcdSendCommand); + EXPORT_FUNCTION(lcdPosition); + EXPORT_FUNCTION(lcdCharDef); + EXPORT_FUNCTION(lcdPutchar); + EXPORT_FUNCTION(lcdPuts); + EXPORT_FUNCTION(lcdPrintf); + EXPORT_FUNCTION(lcdInit); + + EXPORT_CONSTANT_INT(MAX_LCDS); +} \ No newline at end of file diff --git a/src/devlib/lcd.h b/src/devlib/lcd.h new file mode 100644 index 0000000..1b66119 --- /dev/null +++ b/src/devlib/lcd.h @@ -0,0 +1,8 @@ +#ifndef _WPI_LCD_H_ +#define _WPI_LCD_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(lcd); + +#endif \ No newline at end of file diff --git a/src/devlib/lcd128x64.cc b/src/devlib/lcd128x64.cc new file mode 100644 index 0000000..e69de29 diff --git a/src/devlib/lcd128x64.h b/src/devlib/lcd128x64.h new file mode 100644 index 0000000..e69de29 diff --git a/src/devlib/maxdetect.cc b/src/devlib/maxdetect.cc new file mode 100644 index 0000000..3163dc3 --- /dev/null +++ b/src/devlib/maxdetect.cc @@ -0,0 +1,58 @@ +#include "maxdetect.h" +#include + +DECLARE(maxDetectRead); +DECLARE(readRHT03); + +IMPLEMENT(maxDetectRead) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, pin); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int pin = GET_ARGUMENT_AS_INT32(0); + + unsigned char buffer[4]; + int res = ::maxDetectRead(pin, buffer); + + v8::Local data = v8::Array::New(4); + for (int i = 0; i < 4; i++) { + data->Set(i, Int32::New(buffer[i])); + } + + v8::Local ret = v8::Array::New(2); + ret->Set(0, Int32::New(res)); + ret->Set(1, data); + + SCOPE_CLOSE(ret); +} + +IMPLEMENT(readRHT03) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, pin); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int pin = GET_ARGUMENT_AS_INT32; + + int temp, int rh; + int res = ::readRHT03(pin, &temp, &rh); + + v8::Local ret = v8::Array::New(3); + ret->Set(0, v8::Int32::New(res)); + ret->Set(1, v8::Int32::New(temp)); + ret->Set(2, v8::Int32::New(rh)); + + SCOPE_CLOSE(ret); +} + +IMPLEMENT_EXPORT_INIT(maxdetect) { + EXPORT_FUNCTION(maxDetectRead); + EXPORT_FUNCTION(readRHT03); +} \ No newline at end of file diff --git a/src/devlib/maxdetect.h b/src/devlib/maxdetect.h new file mode 100644 index 0000000..d9e7d38 --- /dev/null +++ b/src/devlib/maxdetect.h @@ -0,0 +1,8 @@ +#ifndef _WPI_MAXDETECT_H_ +#define _WPI_MAXDETECT_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(maxdetect); + +#endif \ No newline at end of file diff --git a/src/devlib/piFace.cc b/src/devlib/piFace.cc new file mode 100644 index 0000000..1efba8b --- /dev/null +++ b/src/devlib/piFace.cc @@ -0,0 +1,24 @@ +#include "piFace.h" +#include + +DECLARE(piFaceSetup); + +IMPLEMENT(piFaceSetup) { + 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 = ::piFaceSetup(pinBase); + + SCOPE_CLOSE(INT32(res)); +} + +IMPLEMENT_EXPORT_INIT(piFace) { + EXPORT_FUNCTION(piFaceSetup); +} \ No newline at end of file diff --git a/src/devlib/piFace.h b/src/devlib/piFace.h new file mode 100644 index 0000000..63bf848 --- /dev/null +++ b/src/devlib/piFace.h @@ -0,0 +1,8 @@ +#ifndef _WPI_PI_FACE_H_ +#define _WPI_PI_FACE_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(piFace); + +#endif \ No newline at end of file diff --git a/src/devlib/piGlow.cc b/src/devlib/piGlow.cc new file mode 100644 index 0000000..ea66211 --- /dev/null +++ b/src/devlib/piGlow.cc @@ -0,0 +1,97 @@ +#include "piGlow.h" +#include + +DECLARE(piGlow1); +DECLARE(piGlowLeg); +DECLARE(piGlowRing); +DECLARE(piGlowSetup); + +IMPLEMENT(piGlow1) { + OPEN_SCOPE(); + + SET_ARGUMENT_NAME(0, leg); + SET_ARGUMENT_NAME(1, ring); + SET_ARGUMENT_NAME(2, intensity); + + CHECK_ARGUMENTS_LENGTH_EQUAL(3); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + CHECK_ARGUMENT_TYPE_INT32(2); + + int leg = GET_ARGUMENT_AS_INT32(0); + int ring = GET_ARGUMENT_AS_INT32(1); + int intensity = GET_ARGUMENT_AS_INT32(2); + + ::piGlow1(leg, ring, intensity); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(piGlowLeg) { + OPEN_SCOPE(); + + SET_ARGUMENT_NAME(0, leg); + SET_ARGUMENT_NAME(1, intensity); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + + int leg = GET_ARGUMENT_AS_INT32(0); + int intensity = GET_ARGUMENT_AS_INT32(1); + + ::piGlowLeg(leg, intensity); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(piGlowRing) { + OPEN_SCOPE(); + + SET_ARGUMENT_NAME(0, ring); + SET_ARGUMENT_NAME(1, intensity); + + CHECK_ARGUMENTS_LENGTH_EQUAL(2); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + + int ring = GET_ARGUMENT_AS_INT32(0); + int intensity = GET_ARGUMENT_AS_INT32(1); + + ::piGlowRing(ring, intensity); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT(piGlowSetup) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, clear); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int clear = GET_ARGUMENT_AS_INT32(0); + + ::piGlowSetup(clear); + + SCOPE_CLOSE(UNDEFINED()); +} + +IMPLEMENT_EXPORT_INIT(piGlow) { + EXPORT_FUNCTION(piGlow1); + EXPORT_FUNCTION(piGlowLeg); + EXPORT_FUNCTION(piGlowRing); + EXPORT_FUNCTION(piGlowSetup); + + EXPORT_CONSTANT_INT(PIGLOW_RED); + EXPORT_CONSTANT_INT(PIGLOW_YELLOW); + EXPORT_CONSTANT_INT(PIGLOW_ORANGE); + EXPORT_CONSTANT_INT(PIGLOW_GREEN); + EXPORT_CONSTANT_INT(PIGLOW_BLUE); + EXPORT_CONSTANT_INT(PIGLOW_WHITE); +} \ No newline at end of file diff --git a/src/devlib/piGlow.h b/src/devlib/piGlow.h new file mode 100644 index 0000000..b1dd98c --- /dev/null +++ b/src/devlib/piGlow.h @@ -0,0 +1,8 @@ +#ifndef _WPI_PI_GLOW_H_ +#define _WPI_PI_GLOW_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(piGlow); + +#endif \ No newline at end of file diff --git a/src/devlib/piNes.cc b/src/devlib/piNes.cc new file mode 100644 index 0000000..f94d988 --- /dev/null +++ b/src/devlib/piNes.cc @@ -0,0 +1,58 @@ +#include "piNes.h" +#include + +DECLARE(setupNesJoystick); +DECLARE(readNesJoystick); + +IMPLEMENT(setupNesJoystick) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, dPin); + SET_ARGUMENT_NAME(1, cPin); + SET_ARGUMENT_NAME(2, lPin); + + CHECK_ARGUMENTS_LENGTH_EQUAL(3); + + CHECK_ARGUMENT_TYPE_INT32(0); + CHECK_ARGUMENT_TYPE_INT32(1); + CHECK_ARGUMENT_TYPE_INT32(2); + + int dPin = GET_ARGUMENT_AS_INT32(0); + int cPin = GET_ARGUMENT_AS_INT32(1); + int lPin = GET_ARGUMENT_AS_INT32(2); + + int res = ::setupNesJoystick(dPin, cPin, lPin); + + SCOPE_CLOSE(INT32(res)); +} + +IMPLEMENT(readNesJoystick) { + SCOPE_OPEN(); + + SET_ARGUMENT_NAME(0, joystick); + + CHECK_ARGUMENTS_LENGTH_EQUAL(1); + + CHECK_ARGUMENT_TYPE_INT32(0); + + int joystick = GET_ARGUMENT_AS_INT32(0); + + unsigned int res = ::readNesJoystick(joystick); + + SCOPE_CLOSE(UINT32(res)); +} + +IMPLEMENT_EXPORT_INIT(piNes) { + EXPORT_FUNCTION(setupNesJoystick); + EXPORT_FUNCTION(readNesJoystick); + + EXPORT_CONSTANT_INT(MAX_NES_JOYSTICKS); + EXPORT_CONSTANT_INT(NES_RIGHT); + EXPORT_CONSTANT_INT(NES_LEFT); + EXPORT_CONSTANT_INT(NES_DOWN); + EXPORT_CONSTANT_INT(NES_UP); + EXPORT_CONSTANT_INT(NES_START); + EXPORT_CONSTANT_INT(NES_SELECT); + EXPORT_CONSTANT_INT(NES_A); + EXPORT_CONSTANT_INT(NES_B); +} \ No newline at end of file diff --git a/src/devlib/piNes.h b/src/devlib/piNes.h new file mode 100644 index 0000000..f7125a8 --- /dev/null +++ b/src/devlib/piNes.h @@ -0,0 +1,8 @@ +#ifndef _WPI_PI_NES_H_ +#define _WPI_PI_NES_H_ + + #include "../addon.h" + + DECLARE_EXPORT_INIT(piNes); + +#endif \ No newline at end of file diff --git a/src/wpi.cc b/src/wpi.cc index 491f874..f04c705 100644 --- a/src/wpi.cc +++ b/src/wpi.cc @@ -13,6 +13,7 @@ NODE_MODULE_INIT() { INIT(wiringPiISR); INIT(extensions); + INIT(devlib); } NODE_MODULE_DECLARE(wiringPi); \ No newline at end of file diff --git a/src/wpi.h b/src/wpi.h index a61262b..a9c60df 100644 --- a/src/wpi.h +++ b/src/wpi.h @@ -12,5 +12,6 @@ #include "wiringPiISR.h" #include "extensions/extensions.h" + #include "devlib/devlib.h" #endif \ No newline at end of file