3dxware_test

changeset 0:0219182eb47b tip

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 09 Jul 2013 04:46:51 +0300
parents
children
files .hgignore 3dxware_test.sln 3dxware_test.vcproj main.cc
diffstat 4 files changed, 424 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Tue Jul 09 04:46:51 2013 +0300
     1.3 @@ -0,0 +1,8 @@
     1.4 +\.o$
     1.5 +\.d$
     1.6 +\.swp$
     1.7 +\.ncb$
     1.8 +\.suo$
     1.9 +\.vcproj\..*\.user$
    1.10 +^Debug/
    1.11 +^Release/
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/3dxware_test.sln	Tue Jul 09 04:46:51 2013 +0300
     2.3 @@ -0,0 +1,20 @@
     2.4 +
     2.5 +Microsoft Visual Studio Solution File, Format Version 10.00
     2.6 +# Visual Studio 2008
     2.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3dxware_test", "3dxware_test.vcproj", "{60E6ACB4-4069-41CD-8195-062C66AC4C88}"
     2.8 +EndProject
     2.9 +Global
    2.10 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.11 +		Debug|Win32 = Debug|Win32
    2.12 +		Release|Win32 = Release|Win32
    2.13 +	EndGlobalSection
    2.14 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2.15 +		{60E6ACB4-4069-41CD-8195-062C66AC4C88}.Debug|Win32.ActiveCfg = Debug|Win32
    2.16 +		{60E6ACB4-4069-41CD-8195-062C66AC4C88}.Debug|Win32.Build.0 = Debug|Win32
    2.17 +		{60E6ACB4-4069-41CD-8195-062C66AC4C88}.Release|Win32.ActiveCfg = Release|Win32
    2.18 +		{60E6ACB4-4069-41CD-8195-062C66AC4C88}.Release|Win32.Build.0 = Release|Win32
    2.19 +	EndGlobalSection
    2.20 +	GlobalSection(SolutionProperties) = preSolution
    2.21 +		HideSolutionNode = FALSE
    2.22 +	EndGlobalSection
    2.23 +EndGlobal
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/3dxware_test.vcproj	Tue Jul 09 04:46:51 2013 +0300
     3.3 @@ -0,0 +1,247 @@
     3.4 +<?xml version="1.0" encoding="Windows-1252"?>
     3.5 +<VisualStudioProject
     3.6 +	ProjectType="Visual C++"
     3.7 +	Version="9.00"
     3.8 +	Name="3dxware_test"
     3.9 +	ProjectGUID="{60E6ACB4-4069-41CD-8195-062C66AC4C88}"
    3.10 +	RootNamespace="My3dxware_test"
    3.11 +	Keyword="Win32Proj"
    3.12 +	TargetFrameworkVersion="196613"
    3.13 +	>
    3.14 +	<Platforms>
    3.15 +		<Platform
    3.16 +			Name="Win32"
    3.17 +		/>
    3.18 +	</Platforms>
    3.19 +	<ToolFiles>
    3.20 +	</ToolFiles>
    3.21 +	<Configurations>
    3.22 +		<Configuration
    3.23 +			Name="Debug|Win32"
    3.24 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
    3.25 +			IntermediateDirectory="$(ConfigurationName)"
    3.26 +			ConfigurationType="1"
    3.27 +			CharacterSet="2"
    3.28 +			>
    3.29 +			<Tool
    3.30 +				Name="VCPreBuildEventTool"
    3.31 +			/>
    3.32 +			<Tool
    3.33 +				Name="VCCustomBuildTool"
    3.34 +			/>
    3.35 +			<Tool
    3.36 +				Name="VCXMLDataGeneratorTool"
    3.37 +			/>
    3.38 +			<Tool
    3.39 +				Name="VCWebServiceProxyGeneratorTool"
    3.40 +			/>
    3.41 +			<Tool
    3.42 +				Name="VCMIDLTool"
    3.43 +			/>
    3.44 +			<Tool
    3.45 +				Name="VCCLCompilerTool"
    3.46 +				Optimization="0"
    3.47 +				AdditionalIncludeDirectories="&quot;C:\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc&quot;"
    3.48 +				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
    3.49 +				MinimalRebuild="true"
    3.50 +				BasicRuntimeChecks="3"
    3.51 +				RuntimeLibrary="3"
    3.52 +				UsePrecompiledHeader="0"
    3.53 +				WarningLevel="3"
    3.54 +				DebugInformationFormat="4"
    3.55 +			/>
    3.56 +			<Tool
    3.57 +				Name="VCManagedResourceCompilerTool"
    3.58 +			/>
    3.59 +			<Tool
    3.60 +				Name="VCResourceCompilerTool"
    3.61 +			/>
    3.62 +			<Tool
    3.63 +				Name="VCPreLinkEventTool"
    3.64 +			/>
    3.65 +			<Tool
    3.66 +				Name="VCLinkerTool"
    3.67 +				AdditionalDependencies="siappD.lib"
    3.68 +				LinkIncremental="2"
    3.69 +				AdditionalLibraryDirectories="&quot;C:\Program Files (x86)\3Dconnexion\3DxWare SDK\Lib\x86&quot;"
    3.70 +				GenerateDebugInformation="true"
    3.71 +				SubSystem="1"
    3.72 +				TargetMachine="1"
    3.73 +			/>
    3.74 +			<Tool
    3.75 +				Name="VCALinkTool"
    3.76 +			/>
    3.77 +			<Tool
    3.78 +				Name="VCManifestTool"
    3.79 +			/>
    3.80 +			<Tool
    3.81 +				Name="VCXDCMakeTool"
    3.82 +			/>
    3.83 +			<Tool
    3.84 +				Name="VCBscMakeTool"
    3.85 +			/>
    3.86 +			<Tool
    3.87 +				Name="VCFxCopTool"
    3.88 +			/>
    3.89 +			<Tool
    3.90 +				Name="VCAppVerifierTool"
    3.91 +			/>
    3.92 +			<Tool
    3.93 +				Name="VCPostBuildEventTool"
    3.94 +			/>
    3.95 +		</Configuration>
    3.96 +		<Configuration
    3.97 +			Name="Release|Win32"
    3.98 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
    3.99 +			IntermediateDirectory="$(ConfigurationName)"
   3.100 +			ConfigurationType="1"
   3.101 +			CharacterSet="2"
   3.102 +			WholeProgramOptimization="1"
   3.103 +			>
   3.104 +			<Tool
   3.105 +				Name="VCPreBuildEventTool"
   3.106 +			/>
   3.107 +			<Tool
   3.108 +				Name="VCCustomBuildTool"
   3.109 +			/>
   3.110 +			<Tool
   3.111 +				Name="VCXMLDataGeneratorTool"
   3.112 +			/>
   3.113 +			<Tool
   3.114 +				Name="VCWebServiceProxyGeneratorTool"
   3.115 +			/>
   3.116 +			<Tool
   3.117 +				Name="VCMIDLTool"
   3.118 +			/>
   3.119 +			<Tool
   3.120 +				Name="VCCLCompilerTool"
   3.121 +				Optimization="2"
   3.122 +				EnableIntrinsicFunctions="true"
   3.123 +				AdditionalIncludeDirectories="&quot;C:\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc&quot;"
   3.124 +				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
   3.125 +				RuntimeLibrary="2"
   3.126 +				EnableFunctionLevelLinking="true"
   3.127 +				UsePrecompiledHeader="0"
   3.128 +				WarningLevel="3"
   3.129 +				DebugInformationFormat="3"
   3.130 +			/>
   3.131 +			<Tool
   3.132 +				Name="VCManagedResourceCompilerTool"
   3.133 +			/>
   3.134 +			<Tool
   3.135 +				Name="VCResourceCompilerTool"
   3.136 +			/>
   3.137 +			<Tool
   3.138 +				Name="VCPreLinkEventTool"
   3.139 +			/>
   3.140 +			<Tool
   3.141 +				Name="VCLinkerTool"
   3.142 +				AdditionalDependencies="siapp.lib"
   3.143 +				LinkIncremental="1"
   3.144 +				AdditionalLibraryDirectories="&quot;C:\Program Files (x86)\3Dconnexion\3DxWare SDK\Lib\x86&quot;"
   3.145 +				GenerateDebugInformation="true"
   3.146 +				SubSystem="1"
   3.147 +				OptimizeReferences="2"
   3.148 +				EnableCOMDATFolding="2"
   3.149 +				TargetMachine="1"
   3.150 +			/>
   3.151 +			<Tool
   3.152 +				Name="VCALinkTool"
   3.153 +			/>
   3.154 +			<Tool
   3.155 +				Name="VCManifestTool"
   3.156 +			/>
   3.157 +			<Tool
   3.158 +				Name="VCXDCMakeTool"
   3.159 +			/>
   3.160 +			<Tool
   3.161 +				Name="VCBscMakeTool"
   3.162 +			/>
   3.163 +			<Tool
   3.164 +				Name="VCFxCopTool"
   3.165 +			/>
   3.166 +			<Tool
   3.167 +				Name="VCAppVerifierTool"
   3.168 +			/>
   3.169 +			<Tool
   3.170 +				Name="VCPostBuildEventTool"
   3.171 +			/>
   3.172 +		</Configuration>
   3.173 +	</Configurations>
   3.174 +	<References>
   3.175 +	</References>
   3.176 +	<Files>
   3.177 +		<Filter
   3.178 +			Name="Source Files"
   3.179 +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
   3.180 +			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
   3.181 +			>
   3.182 +			<File
   3.183 +				RelativePath=".\main.cc"
   3.184 +				>
   3.185 +			</File>
   3.186 +		</Filter>
   3.187 +		<Filter
   3.188 +			Name="Header Files"
   3.189 +			Filter="h;hpp;hxx;hm;inl;inc;xsd"
   3.190 +			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
   3.191 +			>
   3.192 +			<File
   3.193 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\3DxWareVersionNumbers.h"
   3.194 +				>
   3.195 +			</File>
   3.196 +			<File
   3.197 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\si.h"
   3.198 +				>
   3.199 +			</File>
   3.200 +			<File
   3.201 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\siapp.h"
   3.202 +				>
   3.203 +			</File>
   3.204 +			<File
   3.205 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\SiCfg.h"
   3.206 +				>
   3.207 +			</File>
   3.208 +			<File
   3.209 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\siDefines.h"
   3.210 +				>
   3.211 +			</File>
   3.212 +			<File
   3.213 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\siSync.h"
   3.214 +				>
   3.215 +			</File>
   3.216 +			<File
   3.217 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\siSyncDefines.h"
   3.218 +				>
   3.219 +			</File>
   3.220 +			<File
   3.221 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\siSyncPriv.h"
   3.222 +				>
   3.223 +			</File>
   3.224 +			<File
   3.225 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\spwdata.h"
   3.226 +				>
   3.227 +			</File>
   3.228 +			<File
   3.229 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\spwerror.h"
   3.230 +				>
   3.231 +			</File>
   3.232 +			<File
   3.233 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\spwmacro.h"
   3.234 +				>
   3.235 +			</File>
   3.236 +			<File
   3.237 +				RelativePath="..\..\..\..\Program Files (x86)\3Dconnexion\3DxWare SDK\Inc\spwmath.h"
   3.238 +				>
   3.239 +			</File>
   3.240 +		</Filter>
   3.241 +		<Filter
   3.242 +			Name="Resource Files"
   3.243 +			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
   3.244 +			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
   3.245 +			>
   3.246 +		</Filter>
   3.247 +	</Files>
   3.248 +	<Globals>
   3.249 +	</Globals>
   3.250 +</VisualStudioProject>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/main.cc	Tue Jul 09 04:46:51 2013 +0300
     4.3 @@ -0,0 +1,149 @@
     4.4 +#include <stdio.h>
     4.5 +#include <stdlib.h>
     4.6 +#include <windows.h>
     4.7 +#include "si.h"
     4.8 +#include "siapp.h"
     4.9 +
    4.10 +HWND create_window();
    4.11 +void destroy_window(HWND win);
    4.12 +bool connect_spnav(HWND win);
    4.13 +void close_spnav();
    4.14 +LRESULT CALLBACK winmsg_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
    4.15 +
    4.16 +SiHdl si_dev;
    4.17 +
    4.18 +int main()
    4.19 +{
    4.20 +	HWND win = create_window();
    4.21 +	if(!win) {
    4.22 +		return 1;
    4.23 +	}
    4.24 +	if(!connect_spnav(win)) {
    4.25 +		return 1;
    4.26 +	}
    4.27 +
    4.28 +	MSG msg;
    4.29 +	while(GetMessage(&msg, win, 0, 0)) {
    4.30 +		TranslateMessage(&msg);
    4.31 +		DispatchMessage(&msg);
    4.32 +	}
    4.33 +	destroy_window(win);
    4.34 +	return 0;
    4.35 +}
    4.36 +
    4.37 +HWND create_window()
    4.38 +{
    4.39 +	HINSTANCE hinst = GetModuleHandle(0);
    4.40 +
    4.41 +	WNDCLASS wc;
    4.42 +	memset(&wc, 0, sizeof wc);
    4.43 +	wc.lpfnWndProc = winmsg_handler;
    4.44 +	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    4.45 +	wc.hCursor = LoadCursor(0, IDC_ARROW);
    4.46 +	wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    4.47 +	wc.lpszClassName = "foobar_window";
    4.48 +	wc.style = CS_HREDRAW | CS_VREDRAW;
    4.49 +	RegisterClass(&wc);
    4.50 +
    4.51 +	HWND win = CreateWindow("foobar_window", "test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
    4.52 +		100, 100, 0, 0, hinst, 0);
    4.53 +	if(!win) {
    4.54 +		return 0;
    4.55 +	}
    4.56 +	ShowWindow(win, 1);
    4.57 +	UpdateWindow(win);
    4.58 +
    4.59 +	return win;
    4.60 +}
    4.61 +
    4.62 +void destroy_window(HWND win)
    4.63 +{
    4.64 +	DestroyWindow(win);
    4.65 +	UnregisterClass("foobar_window", GetModuleHandle(0));
    4.66 +}
    4.67 +
    4.68 +bool connect_spnav(HWND win)
    4.69 +{
    4.70 +	SiOpenData sidata;
    4.71 +
    4.72 +	if(SiInitialize() != 0) {
    4.73 +		fprintf(stderr, "SiInitialize failed\n");
    4.74 +		return false;
    4.75 +	}
    4.76 +	SiOpenWinInit(&sidata, win);
    4.77 +
    4.78 +	if(!(si_dev = SiOpen("spnavtest", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sidata))) {
    4.79 +		fprintf(stderr, "SiOpen failed\n");
    4.80 +		return false;
    4.81 +	}
    4.82 +	return true;
    4.83 +}
    4.84 +
    4.85 +void close_spnav()
    4.86 +{
    4.87 +	if(si_dev) {
    4.88 +		SiClose(si_dev);
    4.89 +	}
    4.90 +	SiTerminate();
    4.91 +}
    4.92 +
    4.93 +void handle_si_event(SiSpwEvent *ev)
    4.94 +{
    4.95 +	int bn;
    4.96 +
    4.97 +	switch(ev->type) {
    4.98 +	case SI_BUTTON_EVENT:
    4.99 +		if((bn = SiButtonPressed(ev)) != SI_NO_BUTTON) {
   4.100 +			printf("button %d pressed\n", bn);
   4.101 +		}
   4.102 +		if((bn = SiButtonReleased(ev)) != SI_NO_BUTTON) {
   4.103 +			printf("button %d released\n", bn);
   4.104 +		}
   4.105 +		break;
   4.106 +
   4.107 +	case SI_MOTION_EVENT:
   4.108 +		printf("motion: ");
   4.109 +		for(int i=0; i<6; i++) {
   4.110 +			printf("%ld ", ev->u.spwData.mData[i]);
   4.111 +			if(i == 2) {
   4.112 +				printf("- ");
   4.113 +			}
   4.114 +		}
   4.115 +		fputc('\n', stdout);
   4.116 +		break;
   4.117 +
   4.118 +	default:
   4.119 +		break;
   4.120 +	}
   4.121 +}
   4.122 +
   4.123 +LRESULT CALLBACK winmsg_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
   4.124 +{
   4.125 +	SiSpwEvent siev;
   4.126 +	SiGetEventData siev_data;
   4.127 +
   4.128 +	SiGetEventWinInit(&siev_data, msg, wparam, lparam);
   4.129 +	SpwRetVal val = SiGetEvent(si_dev, 0, &siev_data, &siev);
   4.130 +	if(val == SI_SKIP_EVENT) {
   4.131 +		return 0;
   4.132 +	} else if(val == SI_IS_EVENT) {
   4.133 +		handle_si_event(&siev);
   4.134 +		return 0;
   4.135 +	}
   4.136 +
   4.137 +	switch(msg) {
   4.138 +	case WM_CLOSE:
   4.139 +		printf("WM_CLOSE\n");
   4.140 +		DestroyWindow(win);
   4.141 +		break;
   4.142 +
   4.143 +	case WM_DESTROY:
   4.144 +		printf("WM_DESTROY\n");
   4.145 +		PostQuitMessage(0);
   4.146 +		break;
   4.147 +
   4.148 +	default:
   4.149 +		return DefWindowProc(win, msg, wparam, lparam);
   4.150 +	}
   4.151 +	return 0;
   4.152 +}
   4.153 \ No newline at end of file