Skip to content

Commit c80dfd3

Browse files
committed
Added initial OpenKinect libraries
1 parent 7ff148f commit c80dfd3

40 files changed

+3104
-0
lines changed

OpenKinect.sln

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenKinectConsole", "OpenKinectConsole\OpenKinectConsole.csproj", "{2175C719-1808-4EC1-8F23-6FFE87591302}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenKinect", "OpenKinect\OpenKinect.csproj", "{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|Mixed Platforms = Debug|Mixed Platforms
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|Mixed Platforms = Release|Mixed Platforms
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
21+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|Mixed Platforms.Build.0 = Debug|x86
22+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|x86.ActiveCfg = Debug|x86
23+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Debug|x86.Build.0 = Debug|x86
24+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Release|Any CPU.ActiveCfg = Release|x86
25+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Release|Mixed Platforms.ActiveCfg = Release|x86
26+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Release|Mixed Platforms.Build.0 = Release|x86
27+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Release|x86.ActiveCfg = Release|x86
28+
{2175C719-1808-4EC1-8F23-6FFE87591302}.Release|x86.Build.0 = Release|x86
29+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
32+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
33+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|x86.ActiveCfg = Debug|x86
34+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Debug|x86.Build.0 = Debug|x86
35+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
38+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Release|Mixed Platforms.Build.0 = Release|Any CPU
39+
{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}.Release|x86.ActiveCfg = Release|Any CPU
40+
EndGlobalSection
41+
GlobalSection(SolutionProperties) = preSolution
42+
HideSolutionNode = FALSE
43+
EndGlobalSection
44+
EndGlobal

OpenKinect/KinectLEDStatus.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace OpenKinect
7+
{
8+
public enum KinectLEDStatus
9+
{
10+
Off = 0x0,
11+
Green = 0x1,
12+
Red = 0x2,
13+
Yellow = 0x3,
14+
BlinkingYellow = 0x4,
15+
BlinkingGreen = 0x5,
16+
AlternateRedYellow = 0x6,
17+
AlternateRedGreen = 0x7
18+
}
19+
}

OpenKinect/KinectMotor.cs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using LibUsbDotNet.Main;
6+
using LibUsbDotNet;
7+
8+
namespace OpenKinect
9+
{
10+
public class KinectMotor
11+
{
12+
#region Fields
13+
14+
private static UsbDevice MyUsbDevice;
15+
private static UsbDeviceFinder MyUsbFinder;
16+
17+
#endregion
18+
19+
#region Constructors
20+
public KinectMotor()
21+
{
22+
InitDevice();
23+
}
24+
#endregion
25+
26+
#region Public Methods
27+
28+
/// <summary>
29+
/// Always returns 0x22 (34) so far
30+
/// </summary>
31+
/// <returns></returns>
32+
public ushort GetInitStatus()
33+
{
34+
UsbSetupPacket setup = new UsbSetupPacket(0xC0, 0x10, 0x0, 0x0, 0x1);
35+
int len = 0;
36+
37+
byte[] buf = new byte[1];
38+
MyUsbDevice.ControlTransfer(ref setup, buf, (ushort)buf.Length, out len);
39+
40+
return buf[0];
41+
}
42+
43+
public void SetLED(KinectLEDStatus status)
44+
{
45+
UsbSetupPacket setup = new UsbSetupPacket(0x40, 0x06, (ushort)status, 0x0, 0x0);
46+
int len = 0;
47+
MyUsbDevice.ControlTransfer(ref setup, IntPtr.Zero, 0, out len);
48+
}
49+
50+
public void SetTilt(byte tiltValue)
51+
{
52+
if (!MyUsbDevice.IsOpen)
53+
{
54+
InitDevice();
55+
}
56+
ushort mappedValue = (byte)(0xffd0 + tiltValue / 5);
57+
58+
UsbSetupPacket setup = new UsbSetupPacket(0x40, 0x31, mappedValue, 0x0, 0x0);
59+
int len = 0;
60+
MyUsbDevice.ControlTransfer(ref setup, IntPtr.Zero, 0, out len);
61+
62+
}
63+
64+
#endregion
65+
66+
#region Private Methods
67+
private static void InitDevice()
68+
{
69+
MyUsbFinder = new UsbDeviceFinder(0x045E, 0x02B0);
70+
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
71+
72+
// If the device is open and ready
73+
if (MyUsbDevice == null) throw new Exception("Device Not Found.");
74+
75+
// If this is a "whole" usb device (libusb-win32, linux libusb)
76+
// it will have an IUsbDevice interface. If not (WinUSB) the
77+
// variable will be null indicating this is an interface of a
78+
// device.
79+
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
80+
if (!ReferenceEquals(wholeUsbDevice, null))
81+
{
82+
// This is a "whole" USB device. Before it can be used,
83+
// the desired configuration and interface must be selected.
84+
85+
// Select config #1
86+
wholeUsbDevice.SetConfiguration(1);
87+
88+
// Claim interface #0.
89+
wholeUsbDevice.ClaimInterface(0);
90+
}
91+
}
92+
#endregion
93+
94+
}
95+
}

OpenKinect/OpenKinect.csproj

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{0D49FD4F-D019-41A7-8FF7-E8E8E3691D55}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>OpenKinect</RootNamespace>
12+
<AssemblyName>OpenKinect</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
34+
<DebugSymbols>true</DebugSymbols>
35+
<OutputPath>bin\x86\Debug\</OutputPath>
36+
<DefineConstants>DEBUG;TRACE</DefineConstants>
37+
<DebugType>full</DebugType>
38+
<PlatformTarget>x86</PlatformTarget>
39+
<CodeAnalysisLogFile>bin\Debug\OpenKinect.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
40+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
41+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
42+
<ErrorReport>prompt</ErrorReport>
43+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
44+
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
45+
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
48+
<OutputPath>bin\x86\Release\</OutputPath>
49+
<DefineConstants>TRACE</DefineConstants>
50+
<Optimize>true</Optimize>
51+
<DebugType>pdbonly</DebugType>
52+
<PlatformTarget>x86</PlatformTarget>
53+
<CodeAnalysisLogFile>bin\Release\OpenKinect.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
54+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
55+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
56+
<ErrorReport>prompt</ErrorReport>
57+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
58+
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
59+
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
60+
</PropertyGroup>
61+
<ItemGroup>
62+
<Reference Include="LibUsbDotNet">
63+
<HintPath>..\external\LibUsbDotNet.dll</HintPath>
64+
</Reference>
65+
<Reference Include="System" />
66+
<Reference Include="System.Core" />
67+
<Reference Include="System.Xml.Linq" />
68+
<Reference Include="System.Data.DataSetExtensions" />
69+
<Reference Include="Microsoft.CSharp" />
70+
<Reference Include="System.Data" />
71+
<Reference Include="System.Xml" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="KinectLEDStatus.cs" />
75+
<Compile Include="KinectMotor.cs" />
76+
<Compile Include="Properties\AssemblyInfo.cs" />
77+
</ItemGroup>
78+
<ItemGroup>
79+
<Folder Include="Camera\" />
80+
</ItemGroup>
81+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
83+
Other similar extension points exist, see Microsoft.Common.targets.
84+
<Target Name="BeforeBuild">
85+
</Target>
86+
<Target Name="AfterBuild">
87+
</Target>
88+
-->
89+
</Project>

OpenKinect/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("OpenKinect")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("OpenKinect")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("8efb3256-039b-47d4-92a3-2aa61389a66f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using LibUsbDotNet.Main;
6+
using LibUsbDotNet;
7+
using OpenKinect;
8+
using System.Threading;
9+
10+
namespace OpenKinectConsole
11+
{
12+
class OpenKinectConsole
13+
{
14+
static void Main(string[] args)
15+
{
16+
ExerciseMotor();
17+
18+
19+
// Wait for user input..
20+
Console.WriteLine("done");
21+
Console.ReadKey();
22+
23+
}
24+
25+
private static void ExerciseMotor()
26+
{
27+
KinectMotor motor = new KinectMotor();
28+
29+
motor.SetTilt(50);
30+
motor.SetLED(KinectLEDStatus.Red);
31+
Thread.Sleep(TimeSpan.FromSeconds(2));
32+
33+
motor.SetTilt(255);
34+
motor.SetLED(KinectLEDStatus.BlinkingYellow);
35+
Thread.Sleep(TimeSpan.FromSeconds(2));
36+
37+
motor.SetTilt(128);
38+
motor.SetLED(KinectLEDStatus.AlternateRedGreen);
39+
Thread.Sleep(TimeSpan.FromSeconds(2));
40+
41+
motor.SetLED(KinectLEDStatus.Green);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)