Skip to content

Commit

Permalink
tcs34725, dac7678
Browse files Browse the repository at this point in the history
ADD: dac7678 support
ADD: tcs34725 readHSV
  • Loading branch information
nekuz0r committed Dec 25, 2014
1 parent fbe4f01 commit 2dbc525
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/devlib/tcs34725.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ IMPLEMENT(tcs34725ReadRGBC) {
SCOPE_CLOSE(obj);
}

IMPLEMENT(tcs34725ReadHSV) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, id);

CHECK_ARGUMENTS_LENGTH_EQUAL(1);

CHECK_ARGUMENT_TYPE_INT32(0);

int id = GET_ARGUMENT_AS_INT32(0);
unsigned short h, s, v;

::tcs34725ReadHSV(id, &h, &s, &v);

Local<Object> obj = Object::New();
obj->Set(String::NewSymbol("h"), UINT32(h));
obj->Set(String::NewSymbol("s"), UINT32(s));
obj->Set(String::NewSymbol("v"), UINT32(v));

SCOPE_CLOSE(obj);
}

IMPLEMENT(tcs34725GetCorrelatedColorTemperature) {
SCOPE_OPEN();

Expand Down Expand Up @@ -194,6 +216,7 @@ IMPLEMENT(tcs34725Setup) {

IMPLEMENT_EXPORT_INIT(tcs34725) {
EXPORT_FUNCTION(tcs34725ReadRGBC);
EXPORT_FUNCTION(tcs34725ReadHSV);
EXPORT_FUNCTION(tcs34725GetCorrelatedColorTemperature);
EXPORT_FUNCTION(tcs34725GetIlluminance);
EXPORT_FUNCTION(tcs34725SetInterrupt);
Expand Down
43 changes: 43 additions & 0 deletions src/extensions/dac7678.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "dac7678.h"
#include <wiringPi.h>
#include <dac7678.h>

DECLARE(dac7678Setup);

IMPLEMENT(dac7678Setup) {
SCOPE_OPEN();

SET_ARGUMENT_NAME(0, pinBase);
SET_ARGUMENT_NAME(1, i2cAddress);
SET_ARGUMENT_NAME(2, vrefMode);

CHECK_ARGUMENTS_LENGTH_EQUAL(3);

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

CHECK_ARGUMENT_IN_INTS(2, vrefMode, (DAC7678_VREF_MODE_STATIC_ON,
DAC7678_VREF_MODE_STATIC_OFF,
DAC7678_VREF_MODE_FLEXIBLE_ON,
DAC7678_VREF_MODE_FLEXIBLE_ALWAYS_ON
DAC7678_VREF_MODE_FLEXIBLE_ALWAYS_OFF));

int pinBase = GET_ARGUMENT_AS_INT32(0);
int i2cAddress = GET_ARGUMENT_AS_INT32(1);
unsigned short vrefMode = GET_ARGUMENT_AS_UINT32(2);

int res = ::dac7678Setup(pinBase, i2cAddress, vrefMode);

SCOPE_CLOSE(INT32(res));
}

IMPLEMENT_EXPORT_INIT(dac7678) {
EXPORT_FUNCTION(dac7678Setup);

EXPORT_CONSTANT_INT(DAC7678_VREF_MODE_STATIC_ON);
EXPORT_CONSTANT_INT(DAC7678_VREF_MODE_STATIC_OFF);
EXPORT_CONSTANT_INT(DAC7678_VREF_MODE_FLEXIBLE_ON);
EXPORT_CONSTANT_INT(DAC7678_VREF_MODE_FLEXIBLE_ALWAYS_ON);
EXPORT_CONSTANT_INT(DAC7678_VREF_MODE_FLEXIBLE_ALWAYS_OFF);
}
8 changes: 8 additions & 0 deletions src/extensions/dac7678.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _WPI_DAC7678_H_
#define _WPI_DAC7678_H_

#include "../addon.h"

DECLARE_EXPORT_INIT(dac7678);

#endif

0 comments on commit 2dbc525

Please sign in to comment.