Skip to content

Commit

Permalink
added Java library wrapper, added Processing library on that, added t…
Browse files Browse the repository at this point in the history
…wo Processing examples
  • Loading branch information
todbot committed Mar 31, 2012
1 parent 3d55ff8 commit 8d4b417
Show file tree
Hide file tree
Showing 15 changed files with 2,012 additions and 0 deletions.
11 changes: 11 additions & 0 deletions commandline/blinkmusb-tool-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# you must type "make jar" before this script will work
#

if [ -e libtargets/blinkmusb.jar ]; then
#java -d32 -Djava.library.path=libtargets -jar libtargets/blinkmusb.jar $*
java -Djava.library.path=libtargets -jar libtargets/blinkmusb.jar $*
else
echo "cannot run. make the jar with 'make jar' please"
fi
100 changes: 100 additions & 0 deletions commandline/nativeBlinkMUSB.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

#include <jni.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>

#include "hiddata.h"
#include "blinkmusb-lib.h"

/* ------------------------------------------------------------------------- */

static usbDevice_t* dev = NULL; // sigh.

// the goal is to have a usbDevice_t* per LinkM instance,
// but for some reason I cannot get a LinkM instance int or long to
// store the pointer in and then retrieve it.
// So for now, there's one global 'dev', so only one LinkM per system.

// maybe one way to support multiple LinkMs per system is to have
// small array of devs (e.g "dev[8]") and then allow up to 8 devs
// BUT, also need to change C API to support more advanced query & finding
// of LinkMs.


/**
*
*/
JNIEXPORT jint JNICALL Java_thingm_blinkm_BlinkMUSB_open
(JNIEnv *env, jobject obj) //, jint vid, jint pid, jstring vstr, jstring pstr)
{
int err;

// open up linkm, get back a 'dev' to pass around
err = blinkmusb_openstatic( &dev ); // FIXME: pass in vid/pid in the future

return err;
}

/**
*
*/
JNIEXPORT void JNICALL Java_thingm_blinkm_BlinkMUSB_close
(JNIEnv *env, jobject obj)
{
blinkmusb_close(dev);
}

JNIEXPORT jint JNICALL Java_thingm_blinkm_BlinkMUSB_setRGB
(JNIEnv *env, jobject obj, jint r, jint g, jint b)
{
int err;
err = blinkmusb_setRGB(dev, r,g,b);
return err;
}

JNIEXPORT jint JNICALL Java_thingm_blinkm_BlinkMUSB_fadeToRGB
(JNIEnv *env, jobject obj, jint fadeMillis, jint r, jint g, jint b)
{
int err;
err = blinkmusb_fadeToRGB(dev, fadeMillis, r,g,b);
return err;
}

/**
*
*
JNIEXPORT void JNICALL Java_thingm_blinkm_BlinkMUSB_command
(JNIEnv *env, jobject obj, jint cmd, jbyteArray jb_send, jbyteArray jb_recv)
{
int err;
uint8_t cmdbyte = (uint8_t) cmd;
int num_send=0;
int num_recv=0;
uint8_t* byte_send = NULL;
uint8_t* byte_recv = NULL;
if( jb_send != NULL ) {
num_send = (*env)->GetArrayLength(env, jb_send );
byte_send = (uint8_t*)(*env)->GetByteArrayElements(env, jb_send,0);
}
if( jb_recv != NULL ) {
num_recv = (*env)->GetArrayLength(env, jb_recv );
byte_recv = (uint8_t*)(*env)->GetByteArrayElements(env, jb_recv,0);
}
err = blinkmusb_command(dev, cmdbyte,num_send,num_recv,byte_send,byte_recv);
if( err ) {
(*env)->ExceptionDescribe(env); // throw an exception.
(*env)->ExceptionClear(env);
jclass newExcCls = (*env)->FindClass(env,"java/io/IOException");
(*env)->ThrowNew(env, newExcCls, blinkmusb_error_msg(err));
}
if( jb_send != NULL )
(*env)->ReleaseByteArrayElements(env, jb_send, (jbyte*) byte_send, 0);
if( jb_recv != NULL )
(*env)->ReleaseByteArrayElements(env, jb_recv, (jbyte*) byte_recv, 0);
}
*/
39 changes: 39 additions & 0 deletions commandline/nativehid/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#OS ?= LINUX
#OS ?= WINDOWS
OS ?= MACOSX
#OS ?= BSD

ifeq ($(OS), LINUX) # also works on FreeBSD
CC ?= gcc
CFLAGS ?= -O2 -Wall
teensy_loader_cli: teensy_loader_cli.c
$(CC) $(CFLAGS) -s -DUSE_LIBUSB -o teensy_loader_cli teensy_loader_cli.c -lusb


else ifeq ($(OS), WINDOWS)
CC = i586-mingw32msvc-gcc
CFLAGS ?= -O2 -Wall
teensy_loader_cli.exe: teensy_loader_cli.c
$(CC) $(CFLAGS) -s -DUSE_WIN32 -o teensy_loader_cli.exe teensy_loader_cli.c -lhid -lsetupapi


else ifeq ($(OS), MACOSX)
CC ?= gcc
SDK ?= /Developer/SDKs/MacOSX10.6.sdk
CFLAGS ?= -O2 -Wall -I../../firmware
blinkmusb-tool2: blinkmusb-tool2.c blinkmusb-lib.c
$(CC) $(CFLAGS) -DUSE_APPLE_IOKIT -isysroot $(SDK) -o blinkmusb-tool2 blinkmusb-tool2.c blinkmusb-lib.c -Wl,-syslibroot,$(SDK) -framework IOKit -framework CoreFoundation


else ifeq ($(OS), BSD) # works on NetBSD and OpenBSD
CC ?= gcc
CFLAGS ?= -O2 -Wall
teensy_loader_cli: teensy_loader_cli.c
$(CC) $(CFLAGS) -s -DUSE_UHID -o teensy_loader_cli teensy_loader_cli.c


endif


clean:
rm -f *.o blinkmusb-tool2
Loading

0 comments on commit 8d4b417

Please sign in to comment.