Put the joystick status in a struct {int x, y, b1, b2;} rather than in a

dummy array of 4 integers. Declare the struct in the header file and update
the man page.
This commit is contained in:
Jean-Marc Zucconi 1995-02-22 23:34:58 +00:00
parent f75dd51832
commit 95344a43ed
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=6644
7 changed files with 58 additions and 30 deletions

View File

@ -12,12 +12,19 @@ the PC joystick.
.Pp
This device may be opened by only one process at a time.
.Pp
The joystick status is get in an array of 4 integers via a read()
call.
.br
The X and Y positions are stored in values 0 and 1 of the array,
and the state of the 2 buttons are stores in values 2 and 3 of the
array. Positions are typically in the range 0-2000.
The joystick status is get in an structure joystick via a read()
call. The structure is defined in the header file as follows:
.Pp
.Bd -literal -offset indent
struct joystick {
int x; /* x position */
int y; /* y position */
int b1; /* button 1 status */
int b2; /* button 2 status */
};
.Ed
.Pp
Positions are typically in the range 0-2000.
.Ss One line perl example:
perl -e 'open(JOY,"/dev/joy0")||die;while(1)
.br

View File

@ -12,12 +12,19 @@ the PC joystick.
.Pp
This device may be opened by only one process at a time.
.Pp
The joystick status is get in an array of 4 integers via a read()
call.
.br
The X and Y positions are stored in values 0 and 1 of the array,
and the state of the 2 buttons are stores in values 2 and 3 of the
array. Positions are typically in the range 0-2000.
The joystick status is get in an structure joystick via a read()
call. The structure is defined in the header file as follows:
.Pp
.Bd -literal -offset indent
struct joystick {
int x; /* x position */
int y; /* y position */
int b1; /* button 1 status */
int b2; /* button 2 status */
};
.Ed
.Pp
Positions are typically in the range 0-2000.
.Ss One line perl example:
perl -e 'open(JOY,"/dev/joy0")||die;while(1)
.br

View File

@ -129,7 +129,7 @@ joyread (dev_t dev, struct uio *uio, int flag)
int port = joy[unit].port;
int i, t0, t1;
int state = 0, x = 0, y = 0;
int c[4];
struct joystick c;
disable_intr ();
outb (port, 0xff);
@ -151,12 +151,12 @@ joyread (dev_t dev, struct uio *uio, int flag)
break;
}
enable_intr ();
c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
c.x = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c.y = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
state >>= 4;
c[2] = ~state & 1;
c[3] = ~(state >> 1) & 1;
return uiomove (c, 4*sizeof(int), uio);
c.b1 = ~state & 1;
c.b2 = ~(state >> 1) & 1;
return uiomove (&c, sizeof(struct joystick), uio);
}
int joyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{

View File

@ -4,6 +4,13 @@
#include <sys/types.h>
#include <sys/ioctl.h>
struct joystick {
int x;
int y;
int b1;
int b2;
};
#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */
#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */
#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */

View File

@ -129,7 +129,7 @@ joyread (dev_t dev, struct uio *uio, int flag)
int port = joy[unit].port;
int i, t0, t1;
int state = 0, x = 0, y = 0;
int c[4];
struct joystick c;
disable_intr ();
outb (port, 0xff);
@ -151,12 +151,12 @@ joyread (dev_t dev, struct uio *uio, int flag)
break;
}
enable_intr ();
c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
c.x = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c.y = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
state >>= 4;
c[2] = ~state & 1;
c[3] = ~(state >> 1) & 1;
return uiomove (c, 4*sizeof(int), uio);
c.b1 = ~state & 1;
c.b2 = ~(state >> 1) & 1;
return uiomove (&c, sizeof(struct joystick), uio);
}
int joyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{

View File

@ -129,7 +129,7 @@ joyread (dev_t dev, struct uio *uio, int flag)
int port = joy[unit].port;
int i, t0, t1;
int state = 0, x = 0, y = 0;
int c[4];
struct joystick c;
disable_intr ();
outb (port, 0xff);
@ -151,12 +151,12 @@ joyread (dev_t dev, struct uio *uio, int flag)
break;
}
enable_intr ();
c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
c.x = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
c.y = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
state >>= 4;
c[2] = ~state & 1;
c[3] = ~(state >> 1) & 1;
return uiomove (c, 4*sizeof(int), uio);
c.b1 = ~state & 1;
c.b2 = ~(state >> 1) & 1;
return uiomove (&c, sizeof(struct joystick), uio);
}
int joyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{

View File

@ -4,6 +4,13 @@
#include <sys/types.h>
#include <sys/ioctl.h>
struct joystick {
int x;
int y;
int b1;
int b2;
};
#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */
#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */
#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */