2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): none yet.
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file ghost/intern/GHOST_NDOFManager.cpp
28 #include <stdio.h> /* just for printf */
30 #include "GHOST_NDOFManager.h"
33 // the variable is outside the class because it must be accessed from plugin
34 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
36 #if !defined(_WIN32) && !defined(__APPLE__)
37 #include "GHOST_SystemX11.h"
42 GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
43 GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
44 GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
47 GHOST_NDOFManager::GHOST_NDOFManager()
51 // discover the API from the plugin
53 ndofLibraryShutdown = 0;
57 GHOST_NDOFManager::~GHOST_NDOFManager()
59 if (ndofLibraryShutdown)
60 ndofLibraryShutdown(m_DeviceHandle);
67 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
68 GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
69 GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
70 GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
74 ndofLibraryInit = setNdofLibraryInit;
75 ndofLibraryShutdown = setNdofLibraryShutdown;
76 ndofDeviceOpen = setNdofDeviceOpen;
78 if (ndofLibraryInit && ndofDeviceOpen)
80 Pid= ndofLibraryInit();
82 printf("%i client \n", Pid);
84 #if defined(WITH_HEADLESS)
86 #elif defined(_WIN32) || defined(__APPLE__)
87 m_DeviceHandle = ndofDeviceOpen((void *)¤tNdofValues);
88 #elif defined(WITH_GHOST_SDL)
92 sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
93 void *ndofInfo = sys->prepareNdofInfo(¤tNdofValues);
94 m_DeviceHandle = ndofDeviceOpen(ndofInfo);
96 return (Pid > 0) ? 0 : 1;
104 GHOST_NDOFManager::available() const
106 return m_DeviceHandle != 0;
110 GHOST_NDOFManager::event_present() const
112 if( currentNdofValues.changed >0) {
113 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n" ,
114 currentNdofValues.time, currentNdofValues.buttons,
115 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
116 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
123 void GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
125 datas.tx = currentNdofValues.tx;
126 datas.ty = currentNdofValues.ty;
127 datas.tz = currentNdofValues.tz;
128 datas.rx = currentNdofValues.rx;
129 datas.ry = currentNdofValues.ry;
130 datas.rz = currentNdofValues.rz;
131 datas.buttons = currentNdofValues.buttons;
132 datas.client = currentNdofValues.client;
133 datas.address = currentNdofValues.address;
134 datas.time = currentNdofValues.time;
135 datas.delta = currentNdofValues.delta;