protecting by #ifdef0 debug prints for ndof
[blender-staging.git] / intern / ghost / intern / GHOST_NDOFManager.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * Contributor(s): none yet.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 #include <stdio.h> /* just for printf */
24
25 #include "GHOST_NDOFManager.h"
26
27
28 // the variable is outside the class because it must be accessed from plugin
29 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
30
31 #if !defined(_WIN32) && !defined(__APPLE__)
32 #include "GHOST_SystemX11.h"
33 #endif
34
35 namespace
36 {
37     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
38     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
39     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
40 }
41
42 GHOST_NDOFManager::GHOST_NDOFManager()
43 {
44     m_DeviceHandle = 0;
45
46     // discover the API from the plugin
47     ndofLibraryInit = 0;
48     ndofLibraryShutdown = 0;
49     ndofDeviceOpen = 0;
50 }
51
52 GHOST_NDOFManager::~GHOST_NDOFManager()
53 {
54     if (ndofLibraryShutdown)
55         ndofLibraryShutdown(m_DeviceHandle);
56
57     m_DeviceHandle = 0;
58 }
59
60
61 int
62 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
63         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
64         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
65         GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
66 {
67         int Pid;
68         
69     ndofLibraryInit = setNdofLibraryInit;
70     ndofLibraryShutdown = setNdofLibraryShutdown;
71     ndofDeviceOpen = setNdofDeviceOpen;
72
73     if (ndofLibraryInit  && ndofDeviceOpen)
74     {
75         Pid= ndofLibraryInit();
76 #if 0
77         printf("%i client \n", Pid);
78 #endif
79                 #if defined(_WIN32) || defined(__APPLE__)
80                         m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
81                 #else
82                         GHOST_SystemX11 *sys;
83                         sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
84                         void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
85                         m_DeviceHandle = ndofDeviceOpen(ndofInfo);
86                 #endif
87                  return (Pid > 0) ? 0 : 1;
88                         
89         } else
90                 return 1;
91 }
92
93
94 bool 
95 GHOST_NDOFManager::available() const
96
97     return m_DeviceHandle != 0; 
98 }
99
100 bool 
101 GHOST_NDOFManager::event_present() const
102
103     if( currentNdofValues.changed >0) {
104                 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n"  ,                       
105                                 currentNdofValues.time,         currentNdofValues.buttons,
106                                 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
107                                 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
108         return true;
109         }else
110         return false;
111
112 }
113
114 void        GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
115 {
116         datas.tx = currentNdofValues.tx;
117         datas.ty = currentNdofValues.ty;
118         datas.tz = currentNdofValues.tz;
119         datas.rx = currentNdofValues.rx;
120         datas.ry = currentNdofValues.ry;
121         datas.rz = currentNdofValues.rz;
122         datas.buttons = currentNdofValues.buttons;
123         datas.client = currentNdofValues.client;
124         datas.address = currentNdofValues.address;
125         datas.time = currentNdofValues.time;
126         datas.delta = currentNdofValues.delta;
127 }