moved common files back to src root
[freeglut] / src / x11 / freeglut_input_devices_x11.c
index ebd99eb..a94e52a 100644 (file)
-/*\r
- * freeglut_input_devices_x11.c\r
- *\r
- * Handles miscellaneous input devices via direct serial-port access.\r
- * Proper X11 XInput device support is not yet supported.\r
- * Also lacks Mac support.\r
- *\r
- * Written by Joe Krahn <krahn@niehs.nih.gov> 2005\r
- *\r
- * Copyright (c) 2005 Stephen J. Baker. All Rights Reserved.\r
- * Copied for Platform code by Evan Felix <karcaw at gmail.com>\r
- * Creation date: Thur Feb 2 2012\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * PAWEL W. OLSZTA OR STEPHEN J. BAKER BE LIABLE FOR ANY CLAIM, DAMAGES OR\r
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
- * DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-#    include "config.h"\r
-#endif\r
-\r
-#include <GL/freeglut.h>\r
-#include "freeglut_internal.h"\r
-\r
-#ifdef HAVE_ERRNO_H\r
-#include <errno.h>\r
-#endif\r
-#include <sys/ioctl.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <termios.h>\r
-#include <fcntl.h>\r
-\r
-struct _serialport {\r
-   int fd;\r
-   struct termios termio, termio_save;\r
-};\r
-\r
-typedef struct _serialport SERIALPORT;\r
-\r
-void serial_flush ( SERIALPORT *port );\r
-\r
-/* local variables */\r
-static SERIALPORT *dialbox_port=NULL;\r
-\r
-/*****************************************************************/\r
-\r
-/*\r
- * Try initializing the input device(s)\r
- */\r
-void fgPlatformRegisterDialDevice ( const char *dial_device )\r
-{\r
-}\r
-\r
-SERIALPORT *serial_open ( const char *device )\r
-{\r
-    int fd;\r
-    struct termios termio;\r
-    SERIALPORT *port;\r
-\r
-    fd = open(device, O_RDWR | O_NONBLOCK );\r
-    if (fd <0) {\r
-        perror(device);\r
-        return NULL;\r
-    }\r
-\r
-    port = malloc(sizeof(SERIALPORT));\r
-    memset(port, 0, sizeof(SERIALPORT));\r
-    port->fd = fd;\r
-\r
-    /* save current port settings */\r
-    tcgetattr(fd,&port->termio_save);\r
-\r
-    memset(&termio, 0, sizeof(termio));\r
-    termio.c_cflag = CS8 | CREAD | HUPCL ;\r
-    termio.c_iflag = IGNPAR | IGNBRK ;\r
-    termio.c_cc[VTIME]    = 0;   /* inter-character timer */\r
-    termio.c_cc[VMIN]     = 1;   /* block read until 1 chars received, when blocking I/O */\r
-\r
-    cfsetispeed(&termio, B9600);\r
-    cfsetospeed(&termio, B9600);\r
-    tcsetattr(fd,TCSANOW,&termio);\r
-\r
-    serial_flush(port);\r
-    return port;\r
-}\r
-\r
-void serial_close(SERIALPORT *port)\r
-{\r
-    if (port)\r
-    {\r
-        /* restore old port settings */\r
-        tcsetattr(port->fd,TCSANOW,&port->termio_save);\r
-        close(port->fd);\r
-        free(port);\r
-    }\r
-}\r
-\r
-int serial_getchar(SERIALPORT *port)\r
-{\r
-    unsigned char ch;\r
-    if (!port) return EOF;\r
-    if (read(port->fd,&ch,1)) return ch;\r
-    return EOF;\r
-}\r
-\r
-int serial_putchar(SERIALPORT *port, unsigned char ch)\r
-{\r
-    if (!port) return 0;\r
-    return write(port->fd,&ch,1);\r
-}\r
-\r
-void serial_flush ( SERIALPORT *port )\r
-{\r
-    tcflush ( port->fd, TCIOFLUSH );\r
-}\r
+/*
+ * 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 <krahn@niehs.nih.gov> 2005
+ *
+ * Copyright (c) 2005 Stephen J. Baker. All Rights Reserved.
+ * Copied for Platform code by Evan Felix <karcaw at gmail.com>
+ * 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 <GL/freeglut.h>
+#include "../fg_internal.h"
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <fcntl.h>
+
+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 );
+}