Subject: Re: wsmouse events
To: Peter Seebach <seebs@plethora.net>
From: Nathan J. Williams <nathanw@MIT.EDU>
List: current-users
Date: 02/27/2001 00:57:56
seebs@plethora.net (Peter Seebach) writes:

> Is there a good way to snoop on wsmouse and figure out whether or not
> it's seeing anything?  I'm debugging multiple-button support in VirtualPC.
> I had it working once, but I can't get it working now... Anyway, what I'd
> ideally like to do is poke around and figure out how many buttons wsmouse0
> thinks it has, and whether or not it's getting any events...

Try the attached program. I used it and a usb trackball to debug some
wsmouse and USB stuff on my Alphas...

        - Nathan

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <dev/wscons/wsconsio.h>


void dump(int fd);
void usage(void);

int main(int argc, char *argv[])
{
  char infilename[1024];
  int fd;

  int ch;
  extern int optind;
  extern char *optarg;

  infilename[0] = 0;

  while ((ch = getopt(argc, argv, "f:")) != -1)
    switch (ch) {           
    case 'f': 
      strcpy(infilename, optarg);
      break;

    default:
      usage();
      /* NOTREACHED */
    }

  argc -= optind;
  argv += optind;

  if ((argc != 0) || infilename[0]==0)
      usage();
 

  fd = open(infilename, O_RDONLY, 0);
  if (fd == -1)
    err(1, "Couldn't open mouse device %s", infilename);

  dump(fd);

  return 0;
}

void dump(int fd)
{
  struct wscons_event evBuf;
  int nBytes;
  char *type, buf[32];

  nBytes = read (fd, (char *)&evBuf, sizeof(evBuf));
  if (nBytes == -1)
    err(1, "Could not read from device");

  while (nBytes != 0) {
    switch (evBuf.type) {
	case WSCONS_EVENT_KEY_UP:
		type = "key up";
		break;
	case WSCONS_EVENT_KEY_DOWN:
		type = "key down";
		break;
    case WSCONS_EVENT_MOUSE_UP:
      type = "mouse up";
      break;
    case WSCONS_EVENT_MOUSE_DOWN:
      type = "mouse down";
      break;
    case WSCONS_EVENT_MOUSE_DELTA_X:
      type = "x";
      break;
    case WSCONS_EVENT_MOUSE_DELTA_Y:
      type = "y";
      break;
    case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
      type = "abs x";
      break;
    case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
      type = "abs y";
      break;
    case WSCONS_EVENT_MOUSE_DELTA_Z:
      type = "z";
      break;
    case WSCONS_EVENT_MOUSE_ABSOLUTE_Z:
      type = "abs z";
      break;
    default:
      sprintf(buf, "other (%d)", evBuf.type);
	  type = buf;
    }

    printf("%9d.%06d  %12s %8x %4d\n", evBuf.time.tv_sec, 
	   evBuf.time.tv_nsec/1000, type, evBuf.value, evBuf.value);

    nBytes = read (fd, (char *)&evBuf, sizeof(evBuf));
    if (nBytes == -1)
      err(1, "Could not read from device");
  }
}
  

void usage()
{

  fprintf(stderr,"usage: wsdump [-f device]\n");
  exit(1);
}