+/*\r
+ * freeglut_input_devices_mswin.c\r
+ *\r
+ * The Windows-specific mouse cursor related stuff.\r
+ *\r
+ * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.\r
+ * Written by John F. Fay, <fayjf@sourceforge.net>\r
+ * Creation date: Sat Jan 21, 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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#include <GL/freeglut.h>\r
+#include "../Common/freeglut_internal.h"\r
+\r
+#include <sys/types.h>\r
+#include <winbase.h>\r
+\r
+typedef struct {\r
+ HANDLE fh;\r
+ COMMTIMEOUTS timeouts_save;\r
+ DCB dcb_save;\r
+} SERIALPORT;\r
+\r
+/* Serial Port Prototypes */\r
+SERIALPORT *serial_open ( const char *device );\r
+void serial_close ( SERIALPORT *port );\r
+int serial_getchar ( SERIALPORT *port );\r
+int serial_putchar ( SERIALPORT *port, unsigned char ch );\r
+void serial_flush ( SERIALPORT *port );\r
+\r
+\r
+void fgPlatformRegisterDialDevice ( const char *dial_device )\r
+{\r
+ if (!dial_device){\r
+ static char devname[256];\r
+ DWORD size=sizeof(devname);\r
+ DWORD type = REG_SZ;\r
+ HKEY key;\r
+ if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) {\r
+ if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){\r
+ dial_device=devname;\r
+ }\r
+ RegCloseKey(key);\r
+ }\r
+ }\r
+}\r
+\r
+\r
+/* Serial Port Functions */\r
+SERIALPORT *serial_open(const char *device){\r
+ HANDLE fh;\r
+ DCB dcb={sizeof(DCB)};\r
+ COMMTIMEOUTS timeouts;\r
+ SERIALPORT *port;\r
+\r
+ fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,\r
+ OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);\r
+ if (!fh) return NULL;\r
+\r
+ port = malloc(sizeof(SERIALPORT));\r
+ ZeroMemory(port, sizeof(SERIALPORT));\r
+ port->fh = fh;\r
+\r
+ /* save current port settings */\r
+ GetCommState(fh,&port->dcb_save);\r
+ GetCommTimeouts(fh,&port->timeouts_save);\r
+\r
+ dcb.DCBlength=sizeof(DCB);\r
+ BuildCommDCB("96,n,8,1",&dcb);\r
+ SetCommState(fh,&dcb);\r
+\r
+ ZeroMemory(&timeouts,sizeof(timeouts));\r
+ timeouts.ReadTotalTimeoutConstant=1;\r
+ timeouts.WriteTotalTimeoutConstant=1;\r
+ SetCommTimeouts(fh,&timeouts);\r
+\r
+ serial_flush(port);\r
+\r
+ return port;\r
+}\r
+\r
+void serial_close(SERIALPORT *port){\r
+ if (port){\r
+ /* restore old port settings */\r
+ SetCommState(port->fh,&port->dcb_save);\r
+ SetCommTimeouts(port->fh,&port->timeouts_save);\r
+ CloseHandle(port->fh);\r
+ free(port);\r
+ }\r
+}\r
+\r
+int serial_getchar(SERIALPORT *port){\r
+ DWORD n;\r
+ unsigned char ch;\r
+ if (!port) return EOF;\r
+ if (!ReadFile(port->fh,&ch,1,&n,NULL)) return EOF;\r
+ if (n==1) return ch;\r
+ return EOF;\r
+}\r
+\r
+int serial_putchar(SERIALPORT *port, unsigned char ch){\r
+ DWORD n;\r
+ if (!port) return 0;\r
+ return WriteFile(port->fh,&ch,1,&n,NULL);\r
+}\r
+\r
+void serial_flush ( SERIALPORT *port )\r
+{\r
+ FlushFileBuffers(port->fh);\r
+}\r
+\r