Skip to content

Commit

Permalink
Merge pull request #3 from sensestage/master
Browse files Browse the repository at this point in the history
fixes for autoconf/make system
  • Loading branch information
tonyrog committed Oct 7, 2013
2 parents 5132a38 + 2ec436d commit 4f54634
Show file tree
Hide file tree
Showing 16 changed files with 812 additions and 369 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
HIDAPI can be used under one of three licenses.

1. The GNU Public License, version 3.0, in LICENSE-gpl3.txt
1. The GNU General Public License, version 3.0, in LICENSE-gpl3.txt
2. A BSD-Style License, in LICENSE-bsd.txt.
3. The more liberal original HIDAPI license. LICENSE-orig.txt

Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

ACLOCAL_AMFLAGS = -I m4

AUTOMAKE_OPTIONS = subdir-objects

if OS_FREEBSD
pkgconfigdir=$(prefix)/libdata/pkgconfig
else
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ AC_PREREQ(2.63)

# Version number. This is currently the only place.
m4_define([HIDAPI_MAJOR], 0)
m4_define([HIDAPI_MINOR], 7)
m4_define([HIDAPI_MINOR], 8)
m4_define([HIDAPI_RELEASE], 0)
m4_define([HIDAPI_RC], +)
m4_define([HIDAPI_RC], -rc1)
m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC)

AC_INIT([hidapi],[VERSION_STRING],[[email protected]])
Expand Down
2 changes: 1 addition & 1 deletion hidapi/hidapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU Public License v3, a BSD-Style license, or the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
Expand Down
63 changes: 56 additions & 7 deletions hidapi2osc/hidapi2osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ static void osc_element_cb( struct hid_device_element *el, void *data)
lo_message_free(m1);
}

static void osc_descriptor_cb( struct hid_device_descriptor *dd, void *data)
static void osc_descriptor_cb( struct hid_dev_desc *dd, void *data)
{
lo_message m1 = lo_message_new();
lo_message_add_int32( m1, *((int*) data) );
lo_message_add_int32( m1, dd->num_elements );
lo_message_add_int32( m1, dd->device_collection->num_elements );
lo_send_message_from( t, s, "/hid/device/data", m1 );
lo_message_free(m1);
}
Expand Down Expand Up @@ -115,8 +115,8 @@ void open_device( unsigned short vendor, unsigned short product, const wchar_t *

newdevdesc->index = number_of_hids;

hid_set_descriptor_callback( newdevdesc->descriptor, (hid_descriptor_callback) osc_descriptor_cb, &newdevdesc->index );
hid_set_element_callback( newdevdesc->descriptor, (hid_element_callback) osc_element_cb, &newdevdesc->index );
hid_set_descriptor_callback( newdevdesc, (hid_descriptor_callback) osc_descriptor_cb, &newdevdesc->index );
hid_set_element_callback( newdevdesc, (hid_element_callback) osc_element_cb, &newdevdesc->index );

number_of_hids++;
}
Expand All @@ -135,6 +135,29 @@ void close_device( int joy_idx ){
}


void send_output_to_hid( int joy_idx, int reportid ){
struct hid_dev_desc * hidtosendoutput = hiddevices.find( joy_idx )->second;
hid_send_output_report( hidtosendoutput, reportid );
}

void set_element_output( int joy_idx, int elementid, int value ){
struct hid_dev_desc * devd = hiddevices.find( joy_idx )->second;

if ( devd != NULL ){
// find the right output element
struct hid_device_collection * device_collection = devd->device_collection;
struct hid_device_element * cur_element = device_collection->first_element;

while ( (cur_element->io_type != 2 || (cur_element->index != elementid)) && cur_element != NULL ){
cur_element = hid_get_next_output_element(cur_element);
}
if ( cur_element != NULL ){
cur_element->value = value;
}
}
}


/// OSC bits

void error(int num, const char *m, const char *path);
Expand All @@ -154,6 +177,13 @@ int hid_info_handler(const char *path, const char *types, lo_arg **argv,
int hid_element_info_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data);

int hid_element_output_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data);

int hid_output_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data);


int generic_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data);
int quit_handler(const char *path, const char *types, lo_arg **argv, int argc,
Expand All @@ -170,6 +200,9 @@ int init_osc( char * ip, char *outport, char * port ){
lo_server_thread_add_method(st, "/hid/info", "i", hid_info_handler, NULL);
lo_server_thread_add_method(st, "/hid/close", "i", hid_close_handler, NULL);

lo_server_thread_add_method(st, "/hid/element/output", "iii", hid_element_output_handler, NULL);
lo_server_thread_add_method(st, "/hid/output", "ii", hid_output_handler, NULL);

lo_server_thread_add_method(st, "/hidapi2osc/info", "", info_handler, NULL);
lo_server_thread_add_method(st, "/hidapi2osc/quit", "", quit_handler, NULL);
lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
Expand Down Expand Up @@ -334,10 +367,10 @@ void send_elements_hid_info(int joy_idx)

lo_message m1 = lo_message_new();
lo_message_add_int32( m1, joy_idx );
lo_message_add_int32( m1, hid->descriptor->num_elements );
lo_message_add_int32( m1, hid->device_collection->num_elements );
lo_bundle_add_message( b, "/hid/element/number", m1 );

hid_device_element * cur_element = hid->descriptor->first;
hid_device_element * cur_element = hid->device_collection->first_element;

while (cur_element) {
lo_message m2 = get_hid_element_info_msg( cur_element, joy_idx );
Expand Down Expand Up @@ -381,6 +414,22 @@ int hid_element_info_handler(const char *path, const char *types, lo_arg **argv,
return 0;
}

int hid_element_output_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data)
{
printf("hidapi2osc: joystick elements output handler\n");
set_element_output( argv[0]->i, argv[1]->i, argv[2]->i );
return 0;
}

int hid_output_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data)
{
printf("hidapi2osc: joystick output handler\n");
send_output_to_hid( argv[0]->i, argv[1]->i );
return 0;
}

int hid_open_handler(const char *path, const char *types, lo_arg **argv, int argc,
void *data, void *user_data)
{
Expand Down Expand Up @@ -570,7 +619,7 @@ int main(int argc, char** argv)
for(it=hiddevices.begin(); it!=hiddevices.end(); ++it){
res = hid_read( it->second->device, buf, sizeof(buf));
if ( res > 0 ) {
hid_parse_input_report( buf, res, it->second->descriptor );
hid_parse_input_report( buf, res, it->second );
}
}
#ifdef WIN32
Expand Down
Loading

0 comments on commit 4f54634

Please sign in to comment.