aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hidio-help.pd47
-rw-r--r--hidio.c42
-rw-r--r--hidio.h8
-rw-r--r--hidio_darwin.c40
4 files changed, 117 insertions, 20 deletions
diff --git a/hidio-help.pd b/hidio-help.pd
index c97aeda..96a5ca7 100644
--- a/hidio-help.pd
+++ b/hidio-help.pd
@@ -1,8 +1,8 @@
#N canvas 726 139 886 611 10;
#X floatatom 27 445 5 0 0 0 - - -;
#X floatatom 83 445 5 0 0 0 - - -;
-#X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25
-;
+#X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 25
+25;
#X floatatom 765 335 5 0 0 1 value - -;
#X symbolatom 631 360 15 0 0 1 event_code - -;
#X symbolatom 544 377 15 0 0 1 event_type - -;
@@ -507,24 +507,45 @@ i_key j_key k_key l_key m_key n_key o_key p_key;
#X msg 262 104 open 0;
#N canvas 121 220 450 300 output 1;
#X obj 93 235 outlet;
-#X obj 57 71 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1
-;
#X msg 112 70 255;
#X obj 108 112 pack 0 16;
#X obj 159 92 + 16;
#X obj 157 68 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1
-1 0;
#X floatatom 171 114 5 0 0 0 - - -;
-#X msg 108 143 write 0xFACE 0xFACE \$2 \$1;
#X obj 125 175 pddp/print;
-#X connect 1 0 3 0;
-#X connect 2 0 3 0;
-#X connect 3 0 7 0;
-#X connect 4 0 3 1;
-#X connect 4 0 6 0;
-#X connect 5 0 4 0;
-#X connect 7 0 0 0;
-#X connect 7 0 8 0;
+#X msg 77 71 127;
+#X msg 47 71 0;
+#X obj 50 36 select 1 0;
+#X obj 49 13 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
+;
+#X msg 108 143 write 1 1 \$2 \$1;
+#X msg 366 86 255;
+#X msg 331 87 127;
+#X msg 301 87 0;
+#X obj 304 52 select 1 0;
+#X obj 303 29 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X msg 261 143 write led power 0 \$1;
+#X connect 1 0 2 0;
+#X connect 2 0 11 0;
+#X connect 3 0 2 1;
+#X connect 3 0 5 0;
+#X connect 4 0 3 0;
+#X connect 7 0 2 0;
+#X connect 8 0 2 0;
+#X connect 9 0 8 0;
+#X connect 9 1 1 0;
+#X connect 10 0 9 0;
+#X connect 11 0 0 0;
+#X connect 11 0 6 0;
+#X connect 12 0 17 0;
+#X connect 13 0 17 0;
+#X connect 14 0 17 0;
+#X connect 15 0 14 0;
+#X connect 15 1 12 0;
+#X connect 16 0 15 0;
+#X connect 17 0 0 0;
#X restore 373 211 pd output support;
#X connect 2 0 60 0;
#X connect 8 0 60 0;
diff --git a/hidio.c b/hidio.c
index 883e0c5..fc8ed65 100644
--- a/hidio.c
+++ b/hidio.c
@@ -302,6 +302,45 @@ void hidio_output_event(t_hidio *x, t_hid_element *output_element)
output_element->output_message);
}
+void hidio_write_event(t_hidio *x, t_symbol *s, int argc, t_atom *argv)
+{
+ debug_post(LOG_DEBUG,"hidio_write_event_symbols");
+ t_symbol *first_argument;
+ t_symbol *second_argument;
+
+ if(argc == 4)
+ {
+ first_argument = atom_getsymbolarg(0,argc,argv);
+ if(first_argument == &s_)
+ { // first float arg means all float message
+ debug_post(LOG_DEBUG,"first_argument == &s_");
+ hidio_write_event_ints(x, atom_getintarg(0,argc,argv), atom_getintarg(1,argc,argv),
+ atom_getintarg(2,argc,argv), atom_getintarg(3,argc,argv));
+ }
+ else
+ {
+ second_argument = atom_getsymbolarg(1,argc,argv);
+ if(second_argument == &s_)
+ { // symbol page and float usage
+ debug_post(LOG_DEBUG,"second_argument == &s_");
+ hidio_write_event_symbol_int(x, first_argument,
+ atom_getintarg(1,argc,argv),
+ atom_getintarg(2,argc,argv),
+ atom_getintarg(3,argc,argv));
+ }
+ else
+ { // symbol page and usage
+ hidio_write_event_symbols(x, first_argument, second_argument,
+ atom_getintarg(2,argc,argv), atom_getintarg(3,argc,argv));
+ }
+ }
+
+ }
+ else
+ {
+ pd_error(x, "[hidio] write message format not supported");
+ }
+}
/* stop polling the device */
static void hidio_stop_poll(t_hidio* x)
@@ -589,8 +628,7 @@ void hidio_setup(void)
class_addmethod(hidio_class,(t_method) hidio_poll,gensym("poll"),A_DEFFLOAT,0);
/* test function for output support */
- class_addmethod(hidio_class,(t_method) hidio_write_event, gensym("write"),
- A_DEFSYMBOL, A_DEFSYMBOL, A_FLOAT, A_FLOAT ,0);
+ class_addmethod(hidio_class,(t_method) hidio_write_event, gensym("write"), A_GIMME ,0);
post("[hidio] %d.%d, written by Hans-Christoph Steiner <hans@eds.org>",
diff --git a/hidio.h b/hidio.h
index f6695ee..649a67e 100644
--- a/hidio.h
+++ b/hidio.h
@@ -186,8 +186,12 @@ extern t_int hidio_open_device(t_hidio *x, short device_number);
extern t_int hidio_close_device(t_hidio *x);
extern void hidio_build_device_list(void);
extern void hidio_get_events(t_hidio *x);
-extern void hidio_write_event(t_hidio *x, t_symbol *type, t_symbol *code,
- t_float instance, t_float value);
+extern void hidio_write_event_symbol_int(t_hidio *x, t_symbol *type, t_int code,
+ t_int instance, t_int value);
+extern void hidio_write_event_symbols(t_hidio *x, t_symbol *type, t_symbol *code,
+ t_int instance, t_int value);
+extern void hidio_write_event_ints(t_hidio *x, t_int type, t_int code,
+ t_int instance, t_int value);
extern void hidio_print(t_hidio* x); /* print info to the console */
extern void hidio_platform_specific_info(t_hidio *x); /* device info on the status outlet */
extern void hidio_platform_specific_free(t_hidio *x);
diff --git a/hidio_darwin.c b/hidio_darwin.c
index d44f121..529dc3b 100644
--- a/hidio_darwin.c
+++ b/hidio_darwin.c
@@ -713,10 +713,44 @@ void hidio_get_events(t_hidio *x)
}
}
-void hidio_write_event(t_hidio *x, t_symbol *type, t_symbol *code,
- t_float instance, t_float value)
+void hidio_write_event_symbol_int(t_hidio *x, t_symbol *type, t_int code,
+ t_int instance, t_int value)
{
- debug_post(LOG_DEBUG,"hidio_write_event");
+ debug_post(LOG_DEBUG,"hidio_write_event_symbol_float");
+}
+
+void hidio_write_event_symbols(t_hidio *x, t_symbol *type, t_symbol *code,
+ t_int instance, t_int value)
+{
+ /* TODO handle multiple instances of the same usage, i.e. arrays */
+ debug_post(LOG_DEBUG,"hidio_write_event_symbols");
+ int i;
+ t_hid_element *current_element;
+ IOHIDEventStruct event;
+ int cookie = (int) instance;
+ pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number];
+ pRecElement pCurrentHIDElement;
+ for(i=0; i<element_count[x->x_device_number]; i++)
+ {
+ current_element = element[x->x_device_number][i];
+ if((current_element->type == type) && (current_element->name == code))
+ {
+ pCurrentHIDElement = current_element->pHIDElement;
+ break;
+ }
+ }
+ post("element usage page and usage: 0x%04x 0x%04x", pCurrentHIDElement->usagePage, pCurrentHIDElement->usage);
+ event.elementCookie = (IOHIDElementCookie)pCurrentHIDElement->cookie;
+ event.value = (SInt32)value;
+ post("pCurrentHIDElement->cookie, cookie, event.value, value: %d %d %d %f",
+ pCurrentHIDElement->cookie, cookie, event.value, value);
+ HIDSetElementValue(pCurrentHIDDevice, pCurrentHIDElement, &event);
+}
+
+void hidio_write_event_ints(t_hidio *x, t_int type, t_int code,
+ t_int instance, t_int value)
+{
+ debug_post(LOG_DEBUG,"hidio_write_event_floats");
IOHIDEventStruct event;
pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number];
pRecElement elem = HIDGetFirstDeviceElement(pCurrentHIDDevice, kHIDElementTypeOutput);