[PD-cvs] externals/hcs/rawhid rawmouse-help.pd, NONE, 1.1 rawmouse.c, NONE, 1.1 configure, 1.1, 1.2 configure.ac, 1.1, 1.2 Makefile.in, 1.1, 1.2

Hans-Christoph Steiner eighthave at users.sourceforge.net
Tue Jan 17 06:14:03 CET 2006


Update of /cvsroot/pure-data/externals/hcs/rawhid
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2067

Modified Files:
	configure configure.ac Makefile.in 
Added Files:
	rawmouse-help.pd rawmouse.c 
Log Message:
some very crufty code from my first attempt at HID objects.  It shall be deleted shortly, I just wanted to have it in CVS as a backup.


--- NEW FILE: rawmouse.c ---
/* Copyright 2003 Hans-Christoph Steiner <hans at eds.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * TODO
 * -obj argument selects device# (event.button.which/event.motion.which)
 *
 * $Id $
 */
static char *version = "$Revision $";

#include <SDL/SDL.h>
#include <m_pd.h>
#include "m_imp.h"

#if PD_MINOR_VERSION >= 37 
#include "s_stuff.h"
#endif

/* #define DEBUG(x) */
#define DEBUG(x) x 

#define RAWMOUSE_AXES     2
#define RAWMOUSE_BUTTONS  9

#define RAWMOUSE_XAXIS    0
#define RAWMOUSE_YAXIS    1

/*------------------------------------------------------------------------------
 *  SDL FUNCTIONS
 */

/* Is the cursor visible? */
static int visible = 1;

void HotKey_ToggleFullScreen(void)
{
	SDL_Surface *screen;

	screen = SDL_GetVideoSurface();
	if ( SDL_WM_ToggleFullScreen(screen) ) {
		printf("Toggled fullscreen mode - now %s\n",
		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
	} else {
		printf("Unable to toggle fullscreen mode\n");
	}
}

void HotKey_ToggleGrab(void)
{
	SDL_GrabMode mode;

	printf("Ctrl-G: toggling input grab!\n");
	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
	if ( mode == SDL_GRAB_ON ) {
		printf("Grab was on\n");
	} else {
		printf("Grab was off\n");
	}
	mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
	if ( mode == SDL_GRAB_ON ) {
		printf("Grab is now on\n");
	} else {
		printf("Grab is now off\n");
	}
}

void HotKey_Iconify(void)
{
	printf("Ctrl-Z: iconifying window!\n");
	SDL_WM_IconifyWindow();
}

void HotKey_Quit(void)
{
	SDL_Event event;

	printf("Posting internal quit request\n");
	event.type = SDL_USEREVENT;
	SDL_PushEvent(&event);
}

int FilterEvents(const SDL_Event *event)
{
	static int reallyquit = 0;
	
	switch (event->type) {
		
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			/* We want to toggle visibility on buttonpress */
			if ( event->button.state == SDL_PRESSED ) {
				visible = !visible;
				SDL_ShowCursor(visible);
			}
			printf("Mouse button %d has been %s\n",
				event->button.button,
				(event->button.state == SDL_PRESSED) ?
						"pressed" : "released");
			return(0);

		/* Show relative mouse motion */
		case SDL_MOUSEMOTION:
#if 1
			printf("Mouse relative motion: {%d,%d}\n",
				event->motion.xrel, event->motion.yrel);
#endif
			return(0);

		case SDL_KEYDOWN:
			if ( event->key.keysym.sym == SDLK_ESCAPE ) {
				HotKey_Quit();
			}
			if ( (event->key.keysym.sym == SDLK_g) &&
			     (event->key.keysym.mod & KMOD_CTRL) ) {
				HotKey_ToggleGrab();
			}
			if ( (event->key.keysym.sym == SDLK_z) &&
			     (event->key.keysym.mod & KMOD_CTRL) ) {
				HotKey_Iconify();
			}
			if ( (event->key.keysym.sym == SDLK_RETURN) &&
			     (event->key.keysym.mod & KMOD_ALT) ) {
				HotKey_ToggleFullScreen();
			}
			return(0);

		/* Pass the video resize event through .. */
		case SDL_VIDEORESIZE:
			return(1);

		/* This is important!  Queue it if we want to quit. */
		case SDL_QUIT:
			if ( ! reallyquit ) {
				reallyquit = 1;
				printf("Quit requested\n");
				return(0);
			}
			printf("Quit demanded\n");
			return(1);

		/* This will never happen because events queued directly
		   to the event queue are not filtered.
		 */
		case SDL_USEREVENT:
			return(1);

		/* Drop all other events */
		default:
			return(0);
	}
}



/*------------------------------------------------------------------------------
 *  CLASS DEF
 */
static t_class *rawmouse_class;

typedef struct _rawmouse  {
		t_object            x_obj;
		SDL_Cursor          *x_mouse;
		int                 read_ok;
		int                 started;
		int                 relative;
		t_outlet            *x_axis_out[RAWMOUSE_AXES];
		t_outlet            *x_button_num_out;
		t_outlet            *x_button_val_out;
		t_clock             *x_clock;
		double              x_delaytime;
		int                 x_buttons;
		int                 x_axes;
} t_rawmouse;

/*------------------------------------------------------------------------------
  */

static int rawmouse_close(t_rawmouse *x)  {
    DEBUG(post("rawmouse_CLOSE"));

}

static int rawmouse_open(t_rawmouse *x)  {
  rawmouse_close(x);

  DEBUG(post("rawmouse_OPEN"));

  post ("   device has %i axes and %i buttons.\n",x->x_axes,x->x_buttons);
  post ("WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING");
  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");
    
  return 1;
}

void rawmouse_start(t_rawmouse* x)
{
  DEBUG(post("rawmouse_START"));

  post("started: %f",x->started);
  if ( ! x->started ) {
/*   SDL_ShowCursor(0); */
	  SDL_WM_GrabInput(SDL_GRAB_ON);
	  
	  clock_delay(x->x_clock, 0);
	  
	  x->started = 1;
  }
}


void rawmouse_stop(t_rawmouse* x)  {
  DEBUG(post("rawmouse_STOP");)

  if ( x->started ) {
/*   SDL_ShowCursor(1); */
	  SDL_WM_GrabInput(SDL_GRAB_OFF);

	  clock_unset(x->x_clock);
	  x->started = 0;
  }
}

static int rawmouse_read(t_rawmouse *x,int fd)  {
  SDL_Event     event; 

  DEBUG(post("rawmouse_READ"));   

  while (SDL_PollEvent(&event)) {
	  post("event type: %s", event.type);
	  switch (event.type) {
		  case SDL_KEYDOWN:
			  post("SDL_KEYDOWN");
			  if ( event.key.keysym.sym == SDLK_ESCAPE )
				  rawmouse_stop(x);
			  break;		  
/* 		  case SDL_MOUSEMOTION: */
/* 			  if (x->relative) { */
/* 				  outlet_float (x->x_axis_out[RAWMOUSE_XAXIS], event.motion.xrel);	 */
/* 				  outlet_float (x->x_axis_out[RAWMOUSE_YAXIS], event.motion.yrel);	 */
/* 			  } else { */
/* 				  outlet_float (x->x_axis_out[RAWMOUSE_XAXIS], event.motion.xrel);	 */
/* 				  outlet_float (x->x_axis_out[RAWMOUSE_YAXIS], event.motion.yrel);	 */
/* 			  } */
/* 			  break; */
/* 		  case SDL_MOUSEBUTTONDOWN: */
/* 			  outlet_float (x->x_button_val_out, 1); */
/* 			  outlet_float (x->x_button_num_out, event.button.button); */
/* 			  break; */
/* 		  case SDL_MOUSEBUTTONUP: */
/* 			  outlet_float (x->x_button_val_out, 0); */
/* 			  outlet_float (x->x_button_num_out, event.button.button); */
/* 			  break; */
		  default:
			  DEBUG(post("Unhandled event."));
	  }
  } 
  
  if (x->started) 
	  clock_delay(x->x_clock, x->x_delaytime);

  return NULL;    
}

/* Actions */

static void rawmouse_bang(t_rawmouse* x)  {
    DEBUG(post("rawmouse_bang"));   
}

static void rawmouse_float(t_rawmouse* x)  {
    DEBUG(post("rawmouse_float"));   
}

void rawmouse_delay(t_rawmouse* x, t_float f)  {
	DEBUG(post("rawmouse_DELAY %f",f);)
	  
   x->x_delaytime = f;
}
void rawmouse_absolute(t_rawmouse* x)  {
	DEBUG(post("rawmouse_ABSOLUTE"));
	  
   x->relative = 0;
}
void rawmouse_relative(t_rawmouse* x)  {
	DEBUG(post("rawmouse_RELATIVE"));
	  
   x->relative = 1;
}


/* SETUP FUNCTIONS */

static void rawmouse_free(t_rawmouse* x) {
  DEBUG(post("rawmouse_free"));
    
  rawmouse_stop(x);
  
  SDL_Quit();

  clock_free(x->x_clock);
}

static void *rawmouse_new(t_float argument) {
  int i;
  t_rawmouse *x = (t_rawmouse *)pd_new(rawmouse_class);

  DEBUG(post("rawmouse_NEW"));
  post("rawHID(e) rawmouse  %s, <hans at eds.org>", version);

  /* init vars */
  x->read_ok = 1;
  x->started = 0;
  x->relative = 1;

  x->x_delaytime = 5;

  x->x_clock = clock_new(x, (t_method)rawmouse_read);

  /* Note: Video is required to start Event Loop !! */
  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 
	  post("Could not initialize SDL: %s\n", SDL_GetError());
	  // exit(-1);
	  return (0);	/* changed by olafmatt */
  }    
  atexit(SDL_Quit);
  
  SDL_WM_SetCaption(title, "rawmouse");
  
  /* create outlets for each axis */
  for (i = 0; i < RAWMOUSE_AXES; i++) 
    x->x_axis_out[i] = outlet_new(&x->x_obj, &s_float);
  
  /* create outlets for buttons */
  x->x_button_num_out = outlet_new(&x->x_obj, &s_float);
  x->x_button_val_out = outlet_new(&x->x_obj, &s_float);
  
  /* Open the device and save settings */
  if ( ! rawmouse_open(x) ) return x;
  
  return (x);
}


void rawmouse_setup(void) {
  DEBUG(post("rawmouse_setup");)
  rawmouse_class = class_new(gensym("rawmouse"), 
			     (t_newmethod)rawmouse_new, 
			     (t_method)rawmouse_free,
			     sizeof(t_rawmouse),0,A_DEFFLOAT,0);

  /* add inlet datatype methods */
  class_addfloat(rawmouse_class,(t_method) rawmouse_float);
  class_addbang(rawmouse_class,(t_method) rawmouse_bang);

  /* add inlet message methods */
  class_addmethod(rawmouse_class,(t_method) rawmouse_open,gensym("open"),0);
  class_addmethod(rawmouse_class,(t_method) rawmouse_close,gensym("close"),0);

  class_addmethod(rawmouse_class,(t_method) rawmouse_start,gensym("start"),0);
  class_addmethod(rawmouse_class,(t_method) rawmouse_stop,gensym("stop"),0);

  class_addmethod(rawmouse_class,(t_method) rawmouse_read,gensym("read"),0);

  class_addmethod(rawmouse_class,(t_method) rawmouse_delay,gensym("delay"),A_FLOAT,0);

  class_addmethod(rawmouse_class,(t_method) rawmouse_absolute,gensym("absolute"),0);
  class_addmethod(rawmouse_class,(t_method) rawmouse_relative,gensym("relative"),0);
}


--- NEW FILE: rawmouse-help.pd ---
#N canvas 108 63 748 404 10;
#X msg 95 34 start;
#X msg 110 65 stop;
#X floatatom 226 177 2 0 0 3 button# - -;
#X floatatom 277 176 2 0 0 3 button_value - -;
#X floatatom 176 177 6 0 0 3 y-axis - -;
#X floatatom 128 177 6 0 0 3 x-axis - -;
#X obj 226 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
#X obj 244 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 262 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 280 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 298 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 317 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 335 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 608 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 590 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 572 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 554 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 535 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 517 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 499 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 481 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 462 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 444 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 426 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 408 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 390 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 371 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 353 305 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
#X obj 247 213 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X msg 181 44 read;
#X msg 262 54 close;
#X msg 263 27 open;
#X text 319 28 [rawjoystick]'s timer defaults to 5 ms. You can change
it with the [delay( message:;
#X msg 353 58 delay 20;
#X obj 226 239 pack f f;
#X obj 226 259 route 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21;
#X obj 648 306 bng 35 250 50 0 empty empty empty 0 -6 0 8 -162590 -1
-1;
#X obj 192 143 rawmouse;
#X msg 353 86 absolute;
#X msg 353 107 relative;
#X connect 0 0 37 0;
#X connect 1 0 37 0;
#X connect 2 0 34 0;
#X connect 3 0 28 0;
#X connect 3 0 34 1;
#X connect 28 0 2 0;
#X connect 29 0 37 0;
#X connect 30 0 37 0;
#X connect 31 0 37 0;
#X connect 33 0 37 0;
#X connect 34 0 35 0;
#X connect 35 0 6 0;
#X connect 35 1 7 0;
#X connect 35 2 8 0;
#X connect 35 3 9 0;
#X connect 35 4 10 0;
#X connect 35 5 11 0;
#X connect 35 6 12 0;
#X connect 35 7 27 0;
#X connect 35 8 26 0;
#X connect 35 9 25 0;
#X connect 35 10 24 0;
#X connect 35 11 23 0;
#X connect 35 12 22 0;
#X connect 35 13 21 0;
#X connect 35 14 20 0;
#X connect 35 15 19 0;
#X connect 35 16 18 0;
#X connect 35 17 17 0;
#X connect 35 18 16 0;
#X connect 35 19 15 0;
#X connect 35 20 14 0;
#X connect 35 21 13 0;
#X connect 35 22 36 0;
#X connect 37 0 5 0;
#X connect 37 1 4 0;
#X connect 37 2 2 0;
#X connect 37 3 3 0;
#X connect 38 0 37 0;
#X connect 39 0 37 0;

Index: Makefile.in
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/rawhid/Makefile.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile.in	25 Apr 2003 03:39:28 -0000	1.1
--- Makefile.in	17 Jan 2006 05:14:00 -0000	1.2
***************
*** 36,45 ****
  
  .c.o:
! 	$(CC) -c -o $@ $(CFLAGS) -DPD $*.c
  
  # cp $@ $*_stat.o
  
  .o.$(EXT):
! 	$(CC) -o $@ $(PDCFLAGS) -DPD $*.o
  
  
--- 36,45 ----
  
  .c.o:
! 	$(CC) -c -o $@ $(CFLAGS) $(INCLUDE) -DPD $*.c
  
  # cp $@ $*_stat.o
  
  .o.$(EXT):
! 	$(CC) -o $@ $(PDCFLAGS) $(INCLUDE) -DPD $*.o
  
  

Index: configure.ac
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/rawhid/configure.ac,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** configure.ac	25 Apr 2003 03:39:28 -0000	1.1
--- configure.ac	17 Jan 2006 05:14:00 -0000	1.2
***************
*** 41,45 ****
  AC_FUNC_ERROR_AT_LINE
  
! LD=ld
  
  dnl
--- 41,45 ----
  AC_FUNC_ERROR_AT_LINE
  
! #LD=ld
  
  dnl
***************
*** 65,71 ****
    DEFS="-DUNIX -DMACOSX"
    EXT=pd_darwin
!   INCLUDE="-I../../../pd/src -I. -I/usr/local/include"
    LD=cc
!   LFLAGS="-bundle -undefined suppress -flat_namespace"
    STRIPFLAGS=
  fi
--- 65,71 ----
    DEFS="-DUNIX -DMACOSX"
    EXT=pd_darwin
!   INCLUDE="-I../../../pd/src -I. -I/sw/include"
    LD=cc
!   LFLAGS="-bundle -bundle_loader ../../../pd/bin/pd -flat_namespace"
    STRIPFLAGS=
  fi

Index: configure
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/rawhid/configure,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** configure	25 Apr 2003 03:39:28 -0000	1.1
--- configure	17 Jan 2006 05:14:00 -0000	1.2
***************
*** 1,6 ****
  #! /bin/sh
! # From configure.ac Revision.
  # Guess values for system-dependent variables and create Makefiles.
! # Generated by GNU Autoconf 2.53 for rawHID(e) 0.0.
  #
  # Report bugs to <hans at eds.org>.
--- 1,6 ----
  #! /bin/sh
! # From configure.ac Revision: 1.1 .
  # Guess values for system-dependent variables and create Makefiles.
[...2497 lines suppressed...]
  ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
  ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
***************
*** 3975,3980 ****
  if test "$no_create" != yes; then
    ac_cs_success=:
    exec 5>/dev/null
!   $SHELL $CONFIG_STATUS || ac_cs_success=false
    exec 5>>config.log
    # Use ||, not &&, to avoid exiting from the if with $? = 1, which
--- 4282,4290 ----
  if test "$no_create" != yes; then
    ac_cs_success=:
+   ac_config_status_args=
+   test "$silent" = yes &&
+     ac_config_status_args="$ac_config_status_args --quiet"
    exec 5>/dev/null
!   $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
    exec 5>>config.log
    # Use ||, not &&, to avoid exiting from the if with $? = 1, which





More information about the Pd-cvs mailing list