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