From: John F. Fay Date: Sat, 4 Feb 2012 14:14:04 +0000 (+0000) Subject: Moving the X11-specific code from "freeglut_input_devices.c" into its own file (thank... X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=0cf70b776640b9fda4e620c7553ff8168be2b8e1;p=freeglut Moving the X11-specific code from "freeglut_input_devices.c" into its own file (thank you, Evan Felix) git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1043 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/Common/freeglut_input_devices.c b/src/Common/freeglut_input_devices.c index bfb6c8c..7cff5a0 100644 --- a/src/Common/freeglut_input_devices.c +++ b/src/Common/freeglut_input_devices.c @@ -35,24 +35,6 @@ #include #include "freeglut_internal.h" -#if TARGET_HOST_POSIX_X11 -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#include -#include -#include -#include -#include - -struct { - int fd; - struct termios termio, termio_save; -} _serialport; - -#endif - typedef struct _serialport SERIALPORT; @@ -127,12 +109,6 @@ int fgInputDeviceDetect( void ) /* * Try initializing the input device(s) */ -#if TARGET_HOST_POSIX_X11 -void fgPlatformRegisterDialDevice ( const char *dial_device ) -{ -} -#endif - void fgInitialiseInputDevices ( void ) { if( !fgState.InputDevsInitialised ) @@ -235,69 +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 ); -} - -#endif diff --git a/src/x11/freeglut_input_devices_x11.c b/src/x11/freeglut_input_devices_x11.c index e69de29..ebd99eb 100644 --- a/src/x11/freeglut_input_devices_x11.c +++ b/src/x11/freeglut_input_devices_x11.c @@ -0,0 +1,132 @@ +/* + * freeglut_input_devices_x11.c + * + * Handles miscellaneous input devices via direct serial-port access. + * Proper X11 XInput device support is not yet supported. + * Also lacks Mac support. + * + * Written by Joe Krahn 2005 + * + * Copyright (c) 2005 Stephen J. Baker. All Rights Reserved. + * Copied for Platform code by Evan Felix + * Creation date: Thur Feb 2 2012 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA OR STEPHEN J. BAKER BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include "freeglut_internal.h" + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#include +#include +#include +#include +#include + +struct _serialport { + int fd; + struct termios termio, termio_save; +}; + +typedef struct _serialport SERIALPORT; + +void serial_flush ( SERIALPORT *port ); + +/* local variables */ +static SERIALPORT *dialbox_port=NULL; + +/*****************************************************************/ + +/* + * Try initializing the input device(s) + */ +void fgPlatformRegisterDialDevice ( const char *dial_device ) +{ +} + +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; +} + +void serial_close(SERIALPORT *port) +{ + if (port) + { + /* restore old port settings */ + tcsetattr(port->fd,TCSANOW,&port->termio_save); + close(port->fd); + free(port); + } +} + +int serial_getchar(SERIALPORT *port) +{ + unsigned char ch; + if (!port) return EOF; + if (read(port->fd,&ch,1)) return ch; + return EOF; +} + +int serial_putchar(SERIALPORT *port, unsigned char ch) +{ + if (!port) return 0; + return write(port->fd,&ch,1); +} + +void serial_flush ( SERIALPORT *port ) +{ + tcflush ( port->fd, TCIOFLUSH ); +}