2 * freeglut_input_devices_mswin.c
\r
4 * The Windows-specific mouse cursor related stuff.
\r
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
\r
7 * Written by John F. Fay, <fayjf@sourceforge.net>
\r
8 * Creation date: Sat Jan 21, 2012
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #include <GL/freeglut.h>
\r
29 #include "../Common/freeglut_internal.h"
\r
31 #include <sys/types.h>
\r
32 #include <winbase.h>
\r
36 COMMTIMEOUTS timeouts_save;
\r
40 /* Serial Port Prototypes */
\r
41 SERIALPORT *serial_open ( const char *device );
\r
42 void serial_close ( SERIALPORT *port );
\r
43 int serial_getchar ( SERIALPORT *port );
\r
44 int serial_putchar ( SERIALPORT *port, unsigned char ch );
\r
45 void serial_flush ( SERIALPORT *port );
\r
48 void fgPlatformRegisterDialDevice ( const char *dial_device )
\r
51 static char devname[256];
\r
52 DWORD size=sizeof(devname);
\r
53 DWORD type = REG_SZ;
\r
55 if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) {
\r
56 if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){
\r
57 dial_device=devname;
\r
65 /* Serial Port Functions */
\r
66 SERIALPORT *serial_open(const char *device){
\r
68 DCB dcb={sizeof(DCB)};
\r
69 COMMTIMEOUTS timeouts;
\r
72 fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,
\r
73 OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
\r
74 if (!fh) return NULL;
\r
76 port = malloc(sizeof(SERIALPORT));
\r
77 ZeroMemory(port, sizeof(SERIALPORT));
\r
80 /* save current port settings */
\r
81 GetCommState(fh,&port->dcb_save);
\r
82 GetCommTimeouts(fh,&port->timeouts_save);
\r
84 dcb.DCBlength=sizeof(DCB);
\r
85 BuildCommDCB("96,n,8,1",&dcb);
\r
86 SetCommState(fh,&dcb);
\r
88 ZeroMemory(&timeouts,sizeof(timeouts));
\r
89 timeouts.ReadTotalTimeoutConstant=1;
\r
90 timeouts.WriteTotalTimeoutConstant=1;
\r
91 SetCommTimeouts(fh,&timeouts);
\r
98 void serial_close(SERIALPORT *port){
\r
100 /* restore old port settings */
\r
101 SetCommState(port->fh,&port->dcb_save);
\r
102 SetCommTimeouts(port->fh,&port->timeouts_save);
\r
103 CloseHandle(port->fh);
\r
108 int serial_getchar(SERIALPORT *port){
\r
111 if (!port) return EOF;
\r
112 if (!ReadFile(port->fh,&ch,1,&n,NULL)) return EOF;
\r
113 if (n==1) return ch;
\r
117 int serial_putchar(SERIALPORT *port, unsigned char ch){
\r
119 if (!port) return 0;
\r
120 return WriteFile(port->fh,&ch,1,&n,NULL);
\r
123 void serial_flush ( SERIALPORT *port )
\r
125 FlushFileBuffers(port->fh);
\r