aboutsummaryrefslogtreecommitdiff
path: root/hidio.h
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-11-30 05:53:41 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-11-30 05:53:41 +0000
commitd82e6551de2b9f3215fd5f58085097d47a6864b9 (patch)
tree2767ad063d08b39618be1bede360c274bb6adc63 /hidio.h
parentfaa02ea1a208dccdc0df2c9ba567c09ca6c2e957 (diff)
did lots of renaming to the new [hidio] name, removed a little bit of cruft. Builds on Mac OS X, but doesn't load yet :-/. hidio_setup() gets called successfully, but for some reason hidio_new() does not seem to get called
svn path=/trunk/externals/io/hidio/; revision=6533
Diffstat (limited to 'hidio.h')
-rw-r--r--hidio.h153
1 files changed, 153 insertions, 0 deletions
diff --git a/hidio.h b/hidio.h
new file mode 100644
index 0000000..7b709ad
--- /dev/null
+++ b/hidio.h
@@ -0,0 +1,153 @@
+#ifndef _HIDIO_H
+#define _HIDIO_H
+
+#include <stdio.h>
+#include <sys/syslog.h>
+
+#ifdef __linux__
+#include <linux/types.h>
+#endif /* __linux__ */
+
+#include <m_pd.h>
+
+/*
+ * this is automatically generated from linux/input.h by
+ * make-arrays-from-input.h.pl to be the cross-platform event types and codes
+ */
+#include "input_arrays.h"
+
+#define HIDIO_MAJOR_VERSION 0
+#define HIDIO_MINOR_VERSION 0
+
+/* static char *version = "$Revision: 1.1 $"; */
+
+/*------------------------------------------------------------------------------
+ * GLOBAL DEFINES
+ */
+
+#define DEFAULT_DELAY 5
+
+/* this is set to simplify data structures (arrays instead of linked lists) */
+#define MAX_DEVICES 128
+
+/* I think 64 is the limit per device as defined in the OS <hans@at.or.at> */
+#define MAX_ELEMENTS 64
+
+/* this is limited so that the object doesn't cause a click getting too many
+ * events from the OS's event queue */
+#define MAX_EVENTS_PER_POLL 64
+
+/*------------------------------------------------------------------------------
+ * CLASS DEF
+ */
+typedef struct _hidio
+
+{
+ t_object x_obj;
+ 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;
+ t_int x_delay;
+ t_clock *x_clock;
+ t_outlet *x_data_outlet;
+ t_outlet *x_status_outlet;
+} t_hidio;
+
+
+
+/*------------------------------------------------------------------------------
+ * GLOBAL VARIABLES
+ */
+
+/* count the number of instances of this object so that certain free()
+ * functions can be called only after the final instance is detroyed.
+ */
+t_int hidio_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 */
+typedef struct _hid_element
+{
+#ifdef __linux__
+ /* GNU/Linux store type and code to compare against */
+ __u16 linux_type;
+ __u16 linux_code;
+#endif /* __linux__ */
+#ifdef _WIN32
+ /* this should be pointers to the UsagePage and Usage */
+#endif /* _WIN32 */
+#ifdef __APPLE__
+ void *pHIDElement; // pRecElement on Mac OS X; ... on Windows
+#endif /* __APPLE__ */
+ t_symbol *type; // Linux "type"; HID "usagePage"
+ t_symbol *name; // Linux "code"; HID "usage"
+ unsigned char polled; // is it polled or queued? (maybe only on Mac OS X?)
+ unsigned char relative; // relative data gets output everytime
+ t_int min; // from device report
+ t_int max; // from device report
+ t_float instance; // usage page/usage instance # ([absolute throttle 2 163(
+ t_int value; // output the sum of events in a poll for relative axes
+ t_int previous_value; //only output on change on abs and buttons
+} t_hid_element;
+
+/* mostly for status querying */
+unsigned short device_count;
+
+/* store element structs to eliminate symbol table lookups, etc. */
+t_hid_element *element[MAX_DEVICES][MAX_ELEMENTS];
+/* number of active elements per device */
+unsigned short element_count[MAX_DEVICES];
+
+/*------------------------------------------------------------------------------
+ * FUNCTION PROTOTYPES FOR DIFFERENT PLATFORMS
+ */
+
+/* support functions */
+void debug_print(t_int debug_level, const char *fmt, ...);
+void debug_error(t_hidio *x, t_int debug_level, const char *fmt, ...);
+void hidio_output_event(t_hidio *x, t_hid_element *output_data);
+
+
+/* generic, cross-platform functions implemented in a separate file for each
+ * platform
+ */
+t_int hidio_open_device(t_hidio *x, short device_number);
+t_int hidio_close_device(t_hidio *x);
+void hidio_build_device_list(void);
+void hidio_get_events(t_hidio *x);
+void hidio_print(t_hidio* x); /* print info to the console */
+void hidio_platform_specific_info(t_hidio* x); /* device info on the status outlet */
+void hidio_platform_specific_free(t_hidio *x);
+short get_device_number_by_id(unsigned short vendor_id, unsigned short product_id);
+/* TODO: this function should probably accept the single unsigned for the combined usage_page and usage, instead of two separate variables */
+short get_device_number_from_usage(short device_number,
+ unsigned short usage_page,
+ unsigned short usage);
+
+
+/* cross-platform force feedback functions */
+t_int hidio_ff_autocenter(t_hidio *x, t_float value);
+t_int hidio_ff_gain(t_hidio *x, t_float value);
+t_int hidio_ff_motors(t_hidio *x, t_float value);
+t_int hidio_ff_continue(t_hidio *x);
+t_int hidio_ff_pause(t_hidio *x);
+t_int hidio_ff_reset(t_hidio *x);
+t_int hidio_ff_stopall(t_hidio *x);
+
+// these are just for testing...
+t_int hidio_ff_fftest (t_hidio *x, t_float value);
+void hidio_ff_print(t_hidio *x);
+
+
+
+
+
+#endif /* #ifndef _HIDIO_H */