From 204ae74aebe11f1adbf3f76b4aea335afacdeaa9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 2 Jun 2006 23:41:36 +0000 Subject: first attempt at having one instance do all of the device polling, based on clock_getlogicaltime(). It works for multiple instances in one patch, but does not work for multiple instances in different patches (i.e. they both still seem to get events...) svn path=/trunk/externals/hcs/hid/; revision=5159 --- TODO | 2 ++ hid.c | 44 +++++++++++++++++++++++--------------------- hid.h | 6 +++++- hid_darwin.c | 8 -------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/TODO b/TODO index 27394fd..0bb8fa6 100644 --- a/TODO +++ b/TODO @@ -65,6 +65,8 @@ ______________________________________________________________________________ - for relative axes, sum up all events and output one http://lists.apple.com/archives/mac-games-dev/2005/Oct/msg00060.html +- current method only works for instances in the same patch... + ______________________________________________________________________________ = [poll 1( message set to exact delay based on block size diff --git a/hid.c b/hid.c index 4b61bce..5f7fcdd 100644 --- a/hid.c +++ b/hid.c @@ -339,9 +339,27 @@ static void hid_open(t_hid *x, t_symbol *s, int argc, t_atom *argv) t_int hid_read(t_hid *x, int fd) { // debug_print(LOG_DEBUG,"hid_read"); - - hid_get_events(x); + unsigned int i; + double right_now = clock_getlogicaltime(); + t_hid_element *current_element; + if(right_now > last_execute_time[x->x_device_number]) + { + hid_get_events(x); + last_execute_time[x->x_device_number] = right_now; +/* post("executing: instance %d/%d at %ld", + x->x_instance, hid_instance_count, right_now);*/ + } + for(i=0; i< element_count[x->x_device_number]; ++i) + { + current_element = element[x->x_device_number][i]; + if(current_element->previous_value != current_element->value) + { + hid_output_event(x, current_element); + if(!current_element->relative) + current_element->previous_value = current_element->value; + } + } if (x->x_started) { clock_delay(x->x_clock, x->x_delay); @@ -351,25 +369,6 @@ t_int hid_read(t_hid *x, int fd) return 1; } -/* eventually, this will be used to open devices by long name -static void hid_anything(t_hid *x, t_symbol *s, t_int argc, t_atom *argv) -{ - int i; - t_symbol *my_symbol; - //char device_name[MAXPDSTRING]; - - startpost("ANYTHING! selector: %s data:"); - for(i=0; is_name); - else - post(" %f",atom_getfloatarg(i,argc,argv)); - } -} -*/ - static void hid_info(t_hid *x) { output_open_status(x); @@ -411,6 +410,7 @@ static void hid_free(t_hid* x) static void *hid_new(t_symbol *s, int argc, t_atom *argv) { t_hid *x = (t_hid *)pd_new(hid_class); + unsigned int i; debug_print(LOG_DEBUG,"hid_%s",s->s_name); @@ -434,6 +434,7 @@ static void *hid_new(t_symbol *s, int argc, t_atom *argv) x->x_device_open = 0; x->x_started = 0; x->x_delay = DEFAULT_DELAY; + for(i=0; ix_clock = clock_new(x, (t_method)hid_read); @@ -443,6 +444,7 @@ static void *hid_new(t_symbol *s, int argc, t_atom *argv) x->x_device_number = get_device_number_from_arguments(argc, argv); + x->x_instance = hid_instance_count; hid_instance_count++; return (x); diff --git a/hid.h b/hid.h index 23b65a4..6a2fd8c 100644 --- a/hid.h +++ b/hid.h @@ -15,7 +15,7 @@ #define HID_MAJOR_VERSION 0 #define HID_MINOR_VERSION 7 -/* static char *version = "$Revision: 1.25 $"; */ +/* static char *version = "$Revision: 1.26 $"; */ /*------------------------------------------------------------------------------ * GLOBAL DEFINES @@ -42,6 +42,7 @@ typedef struct _hid t_int x_fd; void *x_ff_device; short x_device_number; + short x_instance; t_int x_has_ff; t_int x_started; t_int x_device_open; @@ -62,6 +63,9 @@ typedef struct _hid */ t_int hid_instance_count; +/* this is used to test for the first instance to execute */ +double last_execute_time[MAX_DEVICES]; + extern unsigned short global_debug_level; /* built up when the elements of an open device are enumerated */ diff --git a/hid_darwin.c b/hid_darwin.c index b03eaa7..ba8e0ff 100644 --- a/hid_darwin.c +++ b/hid_darwin.c @@ -624,8 +624,6 @@ void hid_platform_specific_info(t_hid *x) void hid_get_events(t_hid *x) { - //debug_print(LOG_DEBUG,"hid_get_events"); - unsigned int i; pRecDevice pCurrentHIDDevice; t_hid_element *current_element; @@ -660,12 +658,6 @@ void hid_get_events(t_hid *x) HIDGetElementValue(pCurrentHIDDevice, (pRecElement)current_element->os_pointer); } - if(current_element->previous_value != current_element->value) - { - hid_output_event(x, current_element); - if(!current_element->relative) - current_element->previous_value = current_element->value; - } } } -- cgit v1.2.1