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 --- hid.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'hid.c') 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); -- cgit v1.2.1