home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
cybermax
/
c
/
cybermxx.c
next >
Wrap
C/C++ Source or Header
|
1996-03-19
|
3KB
|
98 lines
/* cybermxx.c */
/* Written in Pascal by Robin Hollands, March 1995 */
/* Ported to C by Robin Hollands, January 1996 */
/* Redistribute at will, but charge nothing and give credit where due */
#include <stdio.h>
#include <dos.h>
/* Serial support */
const base=0x3F8; /* base address of serial port */
int irq; /* irq number (usually 3 or 4) */
void serial_setup()
{
char junk;
outportb(base + 4,(inportb(base + 4) | 0xEF)); /* turn off loop-back */
junk=inportb(base); junk=inportb(base); /* clear the port */
/* set the baud rate by storing a value in the divisor latch */
outportb((base + 3),(inportb(base + 3) | 0x80)); /* access divisor latch */
/* set divisor to 6, for 19200 baud */
outportb((base + 0),6); /* low byte */
outportb((base + 1),0); /* high byte */
outportb((base + 3),(inportb(base + 3) & 0x7F)); /* un-access divisor latch */
outportb((base + 3),0x03); /* 8 bit data */
}
unsigned char serial_char_waiting()
{
unsigned char temp_scr, in_val;
in_val=inportb(base+5);
temp_scr=(in_val & 0x01); /* return non-zero if byte waiting */
return(temp_scr);
}
unsigned char serial_getchar()
{
unsigned char temp_char;
while (serial_char_waiting()==0);
temp_char=inportb(base); /* read an actual byte from the serial port */
return(temp_char);
}
int serial_getword()
{
int tempword=0;
while (serial_char_waiting()==0) ;
tempword=inportb(base); /* read an actual byte from the serial port */
while (serial_char_waiting()==0) ;
tempword=(tempword << 8) + inportb(base); /* read an actual byte from the serial port */
return(tempword);
}
void serial_putchar(char c)
{
while ((inportb(base + 5) & 0x20) == 0); /* first wait till it's okay */
outportb(base,c); /* write the byte to the port */
}
void Initialise_CyberMaxx()
{
serial_setup();
serial_putchar('F'); /* set binary mode */
}
void Get_CyberMaxx_Data(float *yaw, float *pitch, float *roll)
{
do
{
while (serial_getchar()!=0xFF);
}
while (serial_getchar()!=0xFF);
*yaw=serial_getword()*(359.959/0x7FFF);
if (*yaw>180) *yaw=*yaw-360;
*pitch=((float)serial_getword()-((float)0x7fff/2.0))*180.0/((float)0x7fff);
*roll=((float)serial_getword()-((float)0x7fff/2.0))*180.0/((float)0x7fff);
}
main()
{
float y,p,r;
char j;
printf("This program will read and display tracking data from a CyberMaxx 1 (120K) \n");
printf("HMD connected to COM1. For CyberMaxx 2 (180K) use the Cybertrk utility first\n");
printf("Press Enter to continue \n");
j=getchar();
Initialise_CyberMaxx();
do
{
Get_CyberMaxx_Data(&y,&p,&r);
printf("Yaw = %5.1f Pitch = %5.1f Roll = %5.1f \r ",y,p,r);
/* printf("%c",serial_getchar()); */
}
while (1==1);
}