Fixing call to "fghGetProcAddress" by giving the new name of the function
[freeglut] / src / x11 / freeglut_input_devices_x11.c
1 /*\r
2  * freeglut_input_devices_x11.c\r
3  *\r
4  * Handles miscellaneous input devices via direct serial-port access.\r
5  * Proper X11 XInput device support is not yet supported.\r
6  * Also lacks Mac support.\r
7  *\r
8  * Written by Joe Krahn <krahn@niehs.nih.gov> 2005\r
9  *\r
10  * Copyright (c) 2005 Stephen J. Baker. All Rights Reserved.\r
11  * Copied for Platform code by Evan Felix <karcaw at gmail.com>\r
12  * Creation date: Thur Feb 2 2012\r
13  *\r
14  * Permission is hereby granted, free of charge, to any person obtaining a\r
15  * copy of this software and associated documentation files (the "Software"),\r
16  * to deal in the Software without restriction, including without limitation\r
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
18  * and/or sell copies of the Software, and to permit persons to whom the\r
19  * Software is furnished to do so, subject to the following conditions:\r
20  *\r
21  * The above copyright notice and this permission notice shall be included\r
22  * in all copies or substantial portions of the Software.\r
23  *\r
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
25  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
27  * PAWEL W. OLSZTA OR STEPHEN J. BAKER BE LIABLE FOR ANY CLAIM, DAMAGES OR\r
28  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
30  * DEALINGS IN THE SOFTWARE.\r
31  */\r
32 \r
33 #ifdef HAVE_CONFIG_H\r
34 #    include "config.h"\r
35 #endif\r
36 \r
37 #include <GL/freeglut.h>\r
38 #include "../Common/freeglut_internal.h"\r
39 \r
40 #ifdef HAVE_ERRNO_H\r
41 #include <errno.h>\r
42 #endif\r
43 #include <sys/ioctl.h>\r
44 #include <stdio.h>\r
45 #include <stdlib.h>\r
46 #include <string.h>\r
47 #include <termios.h>\r
48 #include <fcntl.h>\r
49 \r
50 struct _serialport {\r
51    int fd;\r
52    struct termios termio, termio_save;\r
53 };\r
54 \r
55 typedef struct _serialport SERIALPORT;\r
56 \r
57 void serial_flush ( SERIALPORT *port );\r
58 \r
59 /* local variables */\r
60 static SERIALPORT *dialbox_port=NULL;\r
61 \r
62 /*****************************************************************/\r
63 \r
64 /*\r
65  * Try initializing the input device(s)\r
66  */\r
67 void fgPlatformRegisterDialDevice ( const char *dial_device )\r
68 {\r
69 }\r
70 \r
71 SERIALPORT *serial_open ( const char *device )\r
72 {\r
73     int fd;\r
74     struct termios termio;\r
75     SERIALPORT *port;\r
76 \r
77     fd = open(device, O_RDWR | O_NONBLOCK );\r
78     if (fd <0) {\r
79         perror(device);\r
80         return NULL;\r
81     }\r
82 \r
83     port = malloc(sizeof(SERIALPORT));\r
84     memset(port, 0, sizeof(SERIALPORT));\r
85     port->fd = fd;\r
86 \r
87     /* save current port settings */\r
88     tcgetattr(fd,&port->termio_save);\r
89 \r
90     memset(&termio, 0, sizeof(termio));\r
91     termio.c_cflag = CS8 | CREAD | HUPCL ;\r
92     termio.c_iflag = IGNPAR | IGNBRK ;\r
93     termio.c_cc[VTIME]    = 0;   /* inter-character timer */\r
94     termio.c_cc[VMIN]     = 1;   /* block read until 1 chars received, when blocking I/O */\r
95 \r
96     cfsetispeed(&termio, B9600);\r
97     cfsetospeed(&termio, B9600);\r
98     tcsetattr(fd,TCSANOW,&termio);\r
99 \r
100     serial_flush(port);\r
101     return port;\r
102 }\r
103 \r
104 void serial_close(SERIALPORT *port)\r
105 {\r
106     if (port)\r
107     {\r
108         /* restore old port settings */\r
109         tcsetattr(port->fd,TCSANOW,&port->termio_save);\r
110         close(port->fd);\r
111         free(port);\r
112     }\r
113 }\r
114 \r
115 int serial_getchar(SERIALPORT *port)\r
116 {\r
117     unsigned char ch;\r
118     if (!port) return EOF;\r
119     if (read(port->fd,&ch,1)) return ch;\r
120     return EOF;\r
121 }\r
122 \r
123 int serial_putchar(SERIALPORT *port, unsigned char ch)\r
124 {\r
125     if (!port) return 0;\r
126     return write(port->fd,&ch,1);\r
127 }\r
128 \r
129 void serial_flush ( SERIALPORT *port )\r
130 {\r
131     tcflush ( port->fd, TCIOFLUSH );\r
132 }\r