X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_input_devices.c;h=7cff5a0b8d59c58b3dff81d64bb6c13ea32698f8;hb=0cf70b776640b9fda4e620c7553ff8168be2b8e1;hp=50eeac72765013d3ecdacfb30dd085ab786cfea9;hpb=d2f7ea29ea6d946f455f4363c3f058ff2bdfba35;p=freeglut diff --git a/src/Common/freeglut_input_devices.c b/src/Common/freeglut_input_devices.c index 50eeac7..7cff5a0 100644 --- a/src/Common/freeglut_input_devices.c +++ b/src/Common/freeglut_input_devices.c @@ -35,32 +35,8 @@ #include #include "freeglut_internal.h" -#if TARGET_HOST_POSIX_X11 -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#include -#include -#include -#include -#include - -typedef struct { - int fd; - struct termios termio, termio_save; -} SERIALPORT; +typedef struct _serialport SERIALPORT; -#elif TARGET_HOST_MS_WINDOWS -#include -#include -typedef struct { - HANDLE fh; - COMMTIMEOUTS timeouts_save; - DCB dcb_save; -} SERIALPORT; - -#endif /********************* Dialbox definitions ***********************/ @@ -99,12 +75,13 @@ typedef struct { /*****************************************************************/ -static SERIALPORT *serial_open ( const char *device ); -static void serial_close ( SERIALPORT *port ); -static int serial_getchar ( SERIALPORT *port ); -static int serial_putchar ( SERIALPORT *port, unsigned char ch ); -static void serial_flush ( SERIALPORT *port ); +extern SERIALPORT *serial_open ( const char *device ); +extern void serial_close ( SERIALPORT *port ); +extern int serial_getchar ( SERIALPORT *port ); +extern int serial_putchar ( SERIALPORT *port, unsigned char ch ); +extern void serial_flush ( SERIALPORT *port ); +extern void fgPlatformRegisterDialDevice ( const char *dial_device ); static void send_dial_event(int dial, int value); static void poll_dials(int id); @@ -138,20 +115,8 @@ void fgInitialiseInputDevices ( void ) { const char *dial_device=NULL; dial_device = getenv ( "GLUT_DIALS_SERIAL" ); -#if TARGET_HOST_MS_WINDOWS - if (!dial_device){ - static char devname[256]; - DWORD size=sizeof(devname); - DWORD type = REG_SZ; - HKEY key; - if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) { - if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){ - dial_device=devname; - } - RegCloseKey(key); - } - } -#endif + fgPlatformRegisterDialDevice ( dial_device ); + if ( !dial_device ) return; if ( !( dialbox_port = serial_open ( dial_device ) ) ) return; serial_putchar(dialbox_port,DIAL_INITIALIZE); @@ -246,133 +211,3 @@ static void poll_dials ( int id ) glutTimerFunc ( 2, poll_dials, 0 ); } - -/******** OS Specific Serial I/O routines *******/ -#if TARGET_HOST_POSIX_X11 /* ==> Linux/BSD/UNIX POSIX serial I/O */ -static SERIALPORT *serial_open ( const char *device ) -{ - int fd; - struct termios termio; - SERIALPORT *port; - - fd = open(device, O_RDWR | O_NONBLOCK ); - if (fd <0) { - perror(device); - return NULL; - } - - port = malloc(sizeof(SERIALPORT)); - memset(port, 0, sizeof(SERIALPORT)); - port->fd = fd; - - /* save current port settings */ - tcgetattr(fd,&port->termio_save); - - memset(&termio, 0, sizeof(termio)); - termio.c_cflag = CS8 | CREAD | HUPCL ; - termio.c_iflag = IGNPAR | IGNBRK ; - termio.c_cc[VTIME] = 0; /* inter-character timer */ - termio.c_cc[VMIN] = 1; /* block read until 1 chars received, when blocking I/O */ - - cfsetispeed(&termio, B9600); - cfsetospeed(&termio, B9600); - tcsetattr(fd,TCSANOW,&termio); - - serial_flush(port); - return port; -} - -static void serial_close(SERIALPORT *port) -{ - if (port) - { - /* restore old port settings */ - tcsetattr(port->fd,TCSANOW,&port->termio_save); - close(port->fd); - free(port); - } -} - -static int serial_getchar(SERIALPORT *port) -{ - unsigned char ch; - if (!port) return EOF; - if (read(port->fd,&ch,1)) return ch; - return EOF; -} - -static int serial_putchar(SERIALPORT *port, unsigned char ch){ - if (!port) return 0; - return write(port->fd,&ch,1); -} - -static void serial_flush ( SERIALPORT *port ) -{ - tcflush ( port->fd, TCIOFLUSH ); -} - -#elif TARGET_HOST_MS_WINDOWS - -static SERIALPORT *serial_open(const char *device){ - HANDLE fh; - DCB dcb={sizeof(DCB)}; - COMMTIMEOUTS timeouts; - SERIALPORT *port; - - fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL, - OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); - if (!fh) return NULL; - - port = malloc(sizeof(SERIALPORT)); - ZeroMemory(port, sizeof(SERIALPORT)); - port->fh = fh; - - /* save current port settings */ - GetCommState(fh,&port->dcb_save); - GetCommTimeouts(fh,&port->timeouts_save); - - dcb.DCBlength=sizeof(DCB); - BuildCommDCB("96,n,8,1",&dcb); - SetCommState(fh,&dcb); - - ZeroMemory(&timeouts,sizeof(timeouts)); - timeouts.ReadTotalTimeoutConstant=1; - timeouts.WriteTotalTimeoutConstant=1; - SetCommTimeouts(fh,&timeouts); - - serial_flush(port); - - return port; -} - -static void serial_close(SERIALPORT *port){ - if (port){ - /* restore old port settings */ - SetCommState(port->fh,&port->dcb_save); - SetCommTimeouts(port->fh,&port->timeouts_save); - CloseHandle(port->fh); - free(port); - } -} - -static int serial_getchar(SERIALPORT *port){ - DWORD n; - unsigned char ch; - if (!port) return EOF; - if (!ReadFile(port->fh,&ch,1,&n,NULL)) return EOF; - if (n==1) return ch; - return EOF; -} - -static int serial_putchar(SERIALPORT *port, unsigned char ch){ - DWORD n; - if (!port) return 0; - return WriteFile(port->fh,&ch,1,&n,NULL); -} - -static void serial_flush ( SERIALPORT *port ) -{ - FlushFileBuffers(port->fh); -} - -#endif