Skip to content

Commit

Permalink
updated osc example with output
Browse files Browse the repository at this point in the history
  • Loading branch information
Marije Baalman committed Oct 7, 2013
1 parent 4565ea1 commit ea7f986
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions hidapi2osc/hidapi2osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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

0 comments on commit ea7f986

Please sign in to comment.