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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Contributor(s): none yet.
20 * ***** END GPL LICENSE BLOCK *****
24 #include "GHOST_NDOFManager.h"
27 // the variable is outside the class because it must be accessed from plugin
28 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
32 GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
33 GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
34 GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
37 GHOST_NDOFManager::GHOST_NDOFManager()
41 // discover the API from the plugin
43 ndofLibraryShutdown = 0;
47 GHOST_NDOFManager::~GHOST_NDOFManager()
49 if (ndofLibraryShutdown)
50 ndofLibraryShutdown(m_DeviceHandle);
57 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
58 GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
59 GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
60 GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
62 ndofLibraryInit = setNdofLibraryInit;
63 ndofLibraryShutdown = setNdofLibraryShutdown;
64 ndofDeviceOpen = setNdofDeviceOpen;
66 if (ndofLibraryInit && ndofDeviceOpen)
68 printf("%i client \n", ndofLibraryInit());
70 m_DeviceHandle = ndofDeviceOpen((void *)¤tNdofValues);
72 #if defined(_WIN32) || defined(__APPLE__)
73 m_DeviceHandle = ndofDeviceOpen((void *)¤tNdofValues);
76 sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
77 void *ndofInfo = sys->prepareNdofInfo(¤tNdofValues);
78 m_DeviceHandle = ndofDeviceOpen(ndofInfo);
84 /** original patch only */
87 GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam)
89 static GHOST_TEventNDOFData sbdata;
91 if (ndofEventHandler && m_DeviceHandle != 0)
93 handled = ndofEventHandler(&sbdata.tx, m_DeviceHandle, message, wParam, lParam);
95 printf("handled %i\n", handled);
96 return handled ? &sbdata : 0;
101 GHOST_NDOFManager::available() const
103 return m_DeviceHandle != 0;
107 GHOST_NDOFManager::event_present() const
109 if( currentNdofValues.changed >0) {
110 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n" ,
111 currentNdofValues.time, currentNdofValues.buttons,
112 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
113 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
120 void GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
122 datas.tx = currentNdofValues.tx;
123 datas.ty = currentNdofValues.ty;
124 datas.tz = currentNdofValues.tz;
125 datas.rx = currentNdofValues.rx;
126 datas.ry = currentNdofValues.ry;
127 datas.rz = currentNdofValues.rz;
128 datas.buttons = currentNdofValues.buttons;
129 datas.client = currentNdofValues.client;
130 datas.address = currentNdofValues.address;
131 datas.time = currentNdofValues.time;
132 datas.delta = currentNdofValues.delta;