From 51985f6defbc62998f4b18ecb3d2b2db8b7d5165 Mon Sep 17 00:00:00 2001
From: Hans-Christoph Steiner <eighthave@users.sourceforge.net>
Date: Wed, 14 Apr 2004 23:50:44 +0000
Subject: make objects be dummies on non-Linux

svn path=/trunk/externals/hcs/; revision=1604
---
 ifeel.c         |  7 +++++++
 linuxevent.c    | 15 ++++++++++++++-
 linuxhid.h      | 10 +++++++---
 linuxjoystick.c | 19 +++++++++++++++++--
 linuxmouse.c    | 28 ++++++++++++++++++++++------
 5 files changed, 67 insertions(+), 12 deletions(-)

diff --git a/ifeel.c b/ifeel.c
index 2b13576..bec1148 100644
--- a/ifeel.c
+++ b/ifeel.c
@@ -66,12 +66,14 @@ void ifeel_playcommand(t_ifeel *x) {
 /*   const struct timespec *requested_time; */
 /*   struct timespec *remaining; */
 
+#ifdef __linux__
   if (ioctl(x->x_fd, USB_IFEEL_BUZZ_IOCTL, &x->x_ifeel_command) < 0) {
     post("x->x_fd: %d",x->x_fd);
     post("level: %d   interval: %d   count: %d",x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count);
     post("ERROR %s", strerror(errno));
     close(x->x_fd);  
   }
+#endif
 
   DEBUG(
   post("level: %d   interval: %d   count: %d",x->x_ifeel_command.strength,x->x_ifeel_command.delay,x->x_ifeel_command.count);
@@ -169,6 +171,11 @@ void *ifeel_new(t_symbol *device, t_floatarg level, t_floatarg interval, t_float
   post ("As I write cross-platform versions, the interface might have to change.");
   post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING");
   post("");
+#ifndef __linux__
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+	post("     This is a dummy, since this object only works with a Linux kernel!");
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+#endif
   
   /* 
    * init to zero so I can use the ifeel_* methods to set the 
diff --git a/linuxevent.c b/linuxevent.c
index 73261c6..fcd53a5 100644
--- a/linuxevent.c
+++ b/linuxevent.c
@@ -2,7 +2,7 @@
 
 #define LINUXEVENT_DEVICE   "/dev/input/event0"
 
-static char *version = "$Revision: 1.5 $";
+static char *version = "$Revision: 1.6 $";
 
 /*------------------------------------------------------------------------------
  *  CLASS DEF
@@ -17,7 +17,9 @@ typedef struct _linuxevent {
   int                 read_ok;
   int                 started;
   int                 x_delaytime;
+#ifdef __gnu_linux__
   struct input_event  x_input_event; 
+#endif
   t_outlet            *x_input_event_time_outlet;
   t_outlet            *x_input_event_type_outlet;
   t_outlet            *x_input_event_code_outlet;
@@ -53,7 +55,9 @@ static int linuxevent_close(t_linuxevent *x) {
 
 static int linuxevent_open(t_linuxevent *x, t_symbol *s) {
   int eventType, eventCode, buttons, rel_axes, abs_axes, ff;
+#ifdef __gnu_linux__
   unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
+#endif
   char devicename[256] = "Unknown";
   DEBUG(post("linuxevent_open");)
 
@@ -65,6 +69,7 @@ static int linuxevent_open(t_linuxevent *x, t_symbol *s) {
   if (s != &s_)
     x->x_devname = s;
   
+#ifdef __gnu_linux__
   /* open device */
   if (x->x_devname) {
 	  /* open the device read-only, non-exclusive */
@@ -148,6 +153,7 @@ static int linuxevent_open(t_linuxevent *x, t_symbol *s) {
   post ("This object is under development!  The interface could change at anytime!");
   post ("As I write cross-platform versions, the interface might have to change.");
   post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n");
+#endif
   
   return 1;
 }
@@ -155,6 +161,7 @@ static int linuxevent_open(t_linuxevent *x, t_symbol *s) {
 static int linuxevent_read(t_linuxevent *x,int fd) {
 	if (x->x_fd < 0) return 0;
 
+#ifdef __gnu_linux__
 	while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) {
 		outlet_float (x->x_input_event_value_outlet, (int)x->x_input_event.value);
 		outlet_float (x->x_input_event_code_outlet, x->x_input_event.code);
@@ -162,6 +169,7 @@ static int linuxevent_read(t_linuxevent *x,int fd) {
 		/* input_event.time is a timeval struct from <sys/time.h> */
 		/*   outlet_float (x->x_input_event_time_outlet, x->x_input_event.time); */
 	}
+#endif
   
 	if (x->started) {
 		clock_delay(x->x_clock, x->x_delaytime);
@@ -217,6 +225,11 @@ static void *linuxevent_new(t_symbol *s) {
   DEBUG(post("linuxevent_new");)
 
   post("[linuxevent] %s, written by Hans-Christoph Steiner <hans@eds.org>",version);  
+#ifndef __linux__
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+	post("     This is a dummy, since this object only works with a Linux kernel!");
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+#endif
 
   /* init vars */
   x->x_fd = -1;
diff --git a/linuxhid.h b/linuxhid.h
index 9682503..3226535 100644
--- a/linuxhid.h
+++ b/linuxhid.h
@@ -6,7 +6,9 @@
 #include "m_imp.h"
 #endif
 
+#ifdef __gnu_linux__
 #include <linux/input.h>
+#endif
 
 #include <sys/stat.h>
 
@@ -18,8 +20,8 @@
 #include <unistd.h>
 
 
-//#define DEBUG(x)
-#define DEBUG(x) x 
+#define DEBUG(x)
+//#define DEBUG(x) x 
 
 /*------------------------------------------------------------------------------
  * from evtest.c from the ff-utils package
@@ -32,7 +34,7 @@
 #define LONG(x) ((x)/BITS_PER_LONG)
 #define test_bit(bit, array)	((array[LONG(bit)] >> OFF(bit)) & 1)
 
-
+#ifdef __gnu_linux__
 char *events[EV_MAX + 1] = { "Reset", "Key", "Relative", "Absolute", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 NULL, NULL, NULL, "LED", "Sound", NULL, "Repeat", "ForceFeedback", NULL, "ForceFeedbackStatus"};
 char *keys[KEY_MAX + 1] = { "Reserved", "Esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Minus", "Equal", "Backspace",
@@ -80,5 +82,7 @@ char *sounds[SND_MAX + 1] = { "Bell", "Click" };
 char **names[EV_MAX + 1] = { events, keys, relatives, absolutes, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 NULL, NULL, leds, sounds, NULL, repeats, NULL, NULL, NULL };
 
+#endif
+
 /*------------------------------------------------------------------------------
  */
diff --git a/linuxjoystick.c b/linuxjoystick.c
index a7be07d..aa80603 100644
--- a/linuxjoystick.c
+++ b/linuxjoystick.c
@@ -2,7 +2,7 @@
 
 #define LINUXJOYSTICK_AXES     6
 
-static char *version = "$Revision: 1.4 $";
+static char *version = "$Revision: 1.5 $";
 
 /*------------------------------------------------------------------------------
  *  CLASS DEF
@@ -17,7 +17,9 @@ typedef struct _linuxjoystick {
 		int                 read_ok;
 		int                 started;
 		int                 x_delaytime;
+#ifdef __gnu_linux__
 		struct input_event  x_input_event; 
+#endif
 		t_outlet            *x_axis_out[LINUXJOYSTICK_AXES];
 		t_outlet            *x_button_num_out;
 		t_outlet            *x_button_val_out;
@@ -54,7 +56,9 @@ static int linuxjoystick_close(t_linuxjoystick *x) {
 
 static int linuxjoystick_open(t_linuxjoystick *x, t_symbol *s) {
   int eventType, eventCode, buttons, rel_axes, abs_axes, ff;
+#ifdef __linux__
   unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
+#endif
   char devicename[256] = "Unknown";
   DEBUG(post("linuxjoystick_open");)
 
@@ -66,6 +70,7 @@ static int linuxjoystick_open(t_linuxjoystick *x, t_symbol *s) {
   if (s != &s_)
     x->x_devname = s;
   
+#ifdef __linux__
   /* open device */
   if (x->x_devname) {
 	  /* open the device read-only, non-exclusive */
@@ -149,6 +154,7 @@ static int linuxjoystick_open(t_linuxjoystick *x, t_symbol *s) {
   post ("This object is under development!  The interface could change at anytime!");
   post ("As I write cross-platform versions, the interface might have to change.");
   post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n");
+#endif
   
   return 1;
 }
@@ -160,6 +166,7 @@ static int linuxjoystick_read(t_linuxjoystick *x,int fd) {
     
 	if (x->x_fd < 0) return 0;
 
+#ifdef __linux__
 	while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) {
 		if  ( x->x_input_event.type == EV_ABS ) {
 			/* Relative Axes Event Type */
@@ -259,6 +266,7 @@ static int linuxjoystick_read(t_linuxjoystick *x,int fd) {
 			outlet_float (x->x_button_num_out, button_num);
 		}
 	}
+#endif
 	
 	if (x->started) {
 		clock_delay(x->x_clock, x->x_delaytime);
@@ -287,6 +295,7 @@ void linuxjoystick_delay(t_linuxjoystick* x, t_float f)  {
 void linuxjoystick_start(t_linuxjoystick* x) {
 	DEBUG(post("linuxjoystick_start"););
   
+#ifdef __linux__
    if (x->x_fd >= 0 && !x->started) {
 		clock_delay(x->x_clock, 5);
 		post("linuxjoystick: polling started");
@@ -294,6 +303,7 @@ void linuxjoystick_start(t_linuxjoystick* x) {
 	} else {
 		post("You need to set a input device (i.e /dev/input/event0)");
 	}
+#endif
 }
 
 /* setup functions */
@@ -314,6 +324,11 @@ static void *linuxjoystick_new(t_symbol *s) {
   DEBUG(post("linuxjoystick_new");)
 
   post("[linuxjoystick] %s, written by Hans-Christoph Steiner <hans@eds.org>",version);  
+#ifndef __linux__
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+	post("     This is a dummy, since this object only works with a Linux kernel!");
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+#endif
 
   /* init vars */
   x->x_fd = -1;
@@ -337,7 +352,7 @@ static void *linuxjoystick_new(t_symbol *s) {
   /* Open the device and save settings */
   
   if (!linuxjoystick_open(x,s)) return x;
-  
+
   return (x);
 }
 
diff --git a/linuxmouse.c b/linuxmouse.c
index 568f2ff..51e3d51 100644
--- a/linuxmouse.c
+++ b/linuxmouse.c
@@ -3,7 +3,7 @@
 #define LINUXMOUSE_DEVICE   "/dev/input/event0"
 #define LINUXMOUSE_AXES     3
 
-static char *version = "$Revision: 1.3 $";
+static char *version = "$Revision: 1.4 $";
 
 /*------------------------------------------------------------------------------
  *  CLASS DEF
@@ -16,7 +16,9 @@ typedef struct _linuxmouse {
   t_symbol            *x_devname;
   int                 read_ok;
   int                 started;
+#ifdef __gnu_linux__
   struct input_event  x_input_event; 
+#endif
   t_outlet            *x_axis_out[LINUXMOUSE_AXES];
   t_outlet            *x_button_num_out;
   t_outlet            *x_button_val_out;
@@ -32,11 +34,13 @@ typedef struct _linuxmouse {
 void linuxmouse_stop(t_linuxmouse* x) {
 	DEBUG(post("linuxmouse_stop"););
 
+#ifdef __gnu_linux__
    if (x->x_fd >= 0 && x->started) { 
 		sys_rmpollfn(x->x_fd);
 		post("[linuxmouse] stopped");
 		x->started = 0;
 	} 
+#endif
 }
 
 static int linuxmouse_close(t_linuxmouse *x) {
@@ -57,8 +61,10 @@ static int linuxmouse_close(t_linuxmouse *x) {
 
 static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) {
 	int eventType, eventCode;
-	unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
 	char devicename[256] = "Unknown";
+#ifdef __gnu_linux__
+	unsigned long bitmask[EV_MAX][NBITS(KEY_MAX)];
+#endif
 	
 	DEBUG(post("linuxmouse_open"););
 	
@@ -74,7 +80,8 @@ static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) {
 	 * otherwise set to default
 	 */  
 	if (s != &s_) x->x_devname = s;
-	
+
+#ifdef __gnu_linux__	
 	/* open device */
 	if (x->x_devname) {
 		/* open the device read-only, non-exclusive */
@@ -90,7 +97,6 @@ static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) {
 		return 1;
 	}
 	
-	
 /* read input_events from the LINUXMOUSE_DEVICE stream 
  * It seems that is just there to flush the event input buffer?
  */
@@ -138,6 +144,7 @@ static int linuxmouse_open(t_linuxmouse *x, t_symbol *s) {
 	post ("This object is under development!  The interface could change at anytime!");
 	post ("As I write cross-platform versions, the interface might have to change.");
 	post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING\n");
+#endif
 	
 	return 1;
 }
@@ -148,6 +155,7 @@ static int linuxmouse_read(t_linuxmouse *x,int fd) {
 	
 	if (x->x_fd < 0) return 0;
 	
+#ifdef __gnu_linux__
 	while (read (x->x_fd, &(x->x_input_event), sizeof(struct input_event)) > -1) {
 		if  ( x->x_input_event.type == EV_REL ) {
 			/* Relative Axes Event Type */
@@ -192,14 +200,16 @@ static int linuxmouse_read(t_linuxmouse *x,int fd) {
 			outlet_float (x->x_button_val_out, x->x_input_event.value);
 			outlet_float (x->x_button_num_out, button_num);
 		}
- 	}	 
-	
+ 	}
+#endif
+
 	return 1;    
 }
 
 void linuxmouse_start(t_linuxmouse* x) {
 	DEBUG(post("linuxmouse_start"););
 
+#ifdef __gnu_linux__
    if (x->x_fd >= 0 && !x->started) {
 		sys_addpollfn(x->x_fd, (t_fdpollfn)linuxmouse_read, x);
 		post("[linuxmouse] started");
@@ -207,6 +217,7 @@ void linuxmouse_start(t_linuxmouse* x) {
 	} else {
 		post("You need to set a input device (i.e /dev/input/event0)");
 	}
+#endif
 }
 
 /* setup functions */
@@ -225,6 +236,11 @@ static void *linuxmouse_new(t_symbol *s) {
 	DEBUG(post("linuxmouse_new"););
 	
 	post("[linuxmouse] %s, written by Hans-Christoph Steiner <hans@eds.org>",version);  
+#ifndef __gnu_linux__
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+	post("     This is a dummy, since this object only works with a Linux kernel!");
+	post("    !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!");
+#endif
 	
 	/* init vars */
 	x->x_fd = -1;
-- 
cgit v1.2.1