Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GHOST_NDOFManager.cpp « intern « ghost « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2426146184a7f767da31f1e7d4cb0c8c2479ed93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#include <stdio.h> /* just for printf */

#include "GHOST_NDOFManager.h"


// the variable is outside the class because it must be accessed from plugin
static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};

#if !defined(_WIN32) && !defined(__APPLE__)
#include "GHOST_SystemX11.h"
#endif

namespace
{
    GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
    GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
    GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
}

GHOST_NDOFManager::GHOST_NDOFManager()
{
    m_DeviceHandle = 0;

    // discover the API from the plugin
    ndofLibraryInit = 0;
    ndofLibraryShutdown = 0;
    ndofDeviceOpen = 0;
}

GHOST_NDOFManager::~GHOST_NDOFManager()
{
    if (ndofLibraryShutdown)
        ndofLibraryShutdown(m_DeviceHandle);

    m_DeviceHandle = 0;
}


int
GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
        GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
        GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
{
	int Pid;
	
    ndofLibraryInit = setNdofLibraryInit;
    ndofLibraryShutdown = setNdofLibraryShutdown;
    ndofDeviceOpen = setNdofDeviceOpen;

    if (ndofLibraryInit  && ndofDeviceOpen)
    {
    	Pid= ndofLibraryInit();
#if 0
       	printf("%i client \n", Pid);
#endif
		#if defined(_WIN32) || defined(__APPLE__)
			m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
		#else
			GHOST_SystemX11 *sys;
			sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
			void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
			m_DeviceHandle = ndofDeviceOpen(ndofInfo);
		#endif
		 return (Pid > 0) ? 0 : 1;
			
	} else
		return 1;
}


bool 
GHOST_NDOFManager::available() const
{ 
    return m_DeviceHandle != 0; 
}

bool 
GHOST_NDOFManager::event_present() const
{ 
    if( currentNdofValues.changed >0) {
		printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n"	, 			
				currentNdofValues.time,		currentNdofValues.buttons,
				currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
				currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
    	return true;
	}else
	return false;

}

void        GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
{
	datas.tx = currentNdofValues.tx;
	datas.ty = currentNdofValues.ty;
	datas.tz = currentNdofValues.tz;
	datas.rx = currentNdofValues.rx;
	datas.ry = currentNdofValues.ry;
	datas.rz = currentNdofValues.rz;
	datas.buttons = currentNdofValues.buttons;
	datas.client = currentNdofValues.client;
	datas.address = currentNdofValues.address;
	datas.time = currentNdofValues.time;
	datas.delta = currentNdofValues.delta;
}