Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #42

Closed
wants to merge 15 commits into from
Closed

Dev #42

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions examples/cpp-multicam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#include <algorithm>

std::vector<texture_buffer> buffers;
std::vector<rs::device *> devices;

int main(int argc, char * argv[]) try
{
rs::log_to_console(rs::log_severity::warn);
rs::log_to_console(rs::log_severity::debug);
//rs::log_to_file(rs::log_severity::debug, "librealsense.log");

rs::context ctx;
if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");

// Enumerate all devices
std::vector<rs::device *> devices;
for(int i=0; i<ctx.get_device_count(); ++i)
{
devices.push_back(ctx.get_device(i));
Expand All @@ -41,14 +41,49 @@ int main(int argc, char * argv[]) try
glfwInit();
std::ostringstream ss; ss << "CPP Multi-Camera Example";
GLFWwindow * win = glfwCreateWindow(1280, 960, ss.str().c_str(), 0, 0);
glfwMakeContextCurrent(win);
glfwSetWindowUserPointer(win, &ctx);
glfwSetKeyCallback(win, [](GLFWwindow * win, int key, int scancode, int action, int mods)
{
auto ctx = (rs::context *)glfwGetWindowUserPointer(win);
if(action != GLFW_RELEASE)
{
if(key >= GLFW_KEY_0 && key <= GLFW_KEY_9)
{
int index = key - GLFW_KEY_0;
if(index < ctx->get_device_count())
{
auto * dev = ctx->get_device(index);
std::cout << "Resetting device " << index << " (" << dev->get_name() << ")" << std::endl;
dev->reset();

int windowWidth, windowHeight;
glfwGetWindowSize(win, &windowWidth, &windowHeight);
std::cout << "Device reset. Restarting streaming..." << std::endl;
dev->enable_stream(rs::stream::depth, rs::preset::best_quality);
dev->enable_stream(rs::stream::color, rs::preset::best_quality);
dev->start();
}
}

// Does not account for correct aspect ratios
auto perTextureWidth = windowWidth / devices.size();
auto perTextureHeight = 480;
if(key == GLFW_KEY_R)
{
int old_count = ctx->get_device_count();
ctx->enumerate_devices();
int new_count = ctx->get_device_count();
for(int i=old_count; i<new_count; ++i)
{
auto dev = ctx->get_device(i);

devices.push_back(dev);
std::cout << "Starting " << dev->get_name() << "... ";
dev->enable_stream(rs::stream::depth, rs::preset::best_quality);
dev->enable_stream(rs::stream::color, rs::preset::best_quality);
dev->start();
std::cout << "done." << std::endl;
}
buffers.resize(new_count * 2);
}
}
});
glfwMakeContextCurrent(win);

while (!glfwWindowShouldClose(win))
{
Expand All @@ -65,6 +100,11 @@ int main(int argc, char * argv[]) try
glPushMatrix();
glOrtho(0, w, h, 0, -1, +1);
glPixelZoom(1, -1);

// Does not account for correct aspect ratios
auto perTextureWidth = w / devices.size();
auto perTextureHeight = h / 2;

int i=0, x=0;
for(auto dev : devices)
{
Expand Down
14 changes: 13 additions & 1 deletion include/librealsense/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern "C" {
#endif

#define RS_API_VERSION 4
#define RS_API_VERSION 5

typedef enum rs_stream
{
Expand Down Expand Up @@ -150,6 +150,12 @@ typedef struct rs_error rs_error;
rs_context * rs_create_context(int api_version, rs_error ** error);
void rs_delete_context(rs_context * context, rs_error ** error);

/**
* refresh the list of available devices associated with this context
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
void rs_enumerate_devices(rs_context * context, rs_error ** error);

/**
* determine number of connected devices
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
Expand Down Expand Up @@ -395,6 +401,12 @@ int rs_get_frame_timestamp(const rs_device * device, rs_stream stream, rs_error
* \return the pointer to the start of the frame data
*/
const void * rs_get_frame_data(const rs_device * device, rs_stream stream, rs_error ** error);

/**
* force the device hardware to reset, and block until a connection to the device can be reestablished
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
void rs_reset_device(rs_device * device, rs_error ** error);

const char * rs_get_failed_function (const rs_error * error);
const char * rs_get_failed_args (const rs_error * error);
Expand Down
20 changes: 19 additions & 1 deletion include/librealsense/rs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace rs
context()
{
rs_error * e = nullptr;
handle = rs_create_context(4, &e);
handle = rs_create_context(RS_API_VERSION, &e);
error::handle(e);
}

Expand All @@ -179,6 +179,15 @@ namespace rs
rs_delete_context(handle, nullptr);
}

/// refresh the list of available devices associated with this context
///
void enumerate_devices()
{
rs_error * e = nullptr;
rs_enumerate_devices(handle, &e);
error::handle(e);
}

/// determine number of connected devices
/// \return the count of devices
int get_device_count() const
Expand Down Expand Up @@ -519,6 +528,15 @@ namespace rs
error::handle(e);
return r;
}

/// force the device hardware to reset, and block until a connection to the device can be reestablished
/// \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
void reset()
{
rs_error * e = nullptr;
rs_reset_device((rs_device *)this, &e);
error::handle(e);
}
};

inline std::ostream & operator << (std::ostream & o, stream stream) { return o << rs_stream_to_string((rs_stream)stream); }
Expand Down
187 changes: 187 additions & 0 deletions librealsense.vc12/realsense-s/realsense-s.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\context.cpp" />
<ClCompile Include="..\..\src\device.cpp" />
<ClCompile Include="..\..\src\f200-private.cpp" />
<ClCompile Include="..\..\src\f200.cpp" />
<ClCompile Include="..\..\src\image.cpp" />
<ClCompile Include="..\..\src\log.cpp" />
<ClCompile Include="..\..\src\r200-private.cpp" />
<ClCompile Include="..\..\src\r200.cpp" />
<ClCompile Include="..\..\src\rs.cpp" />
<ClCompile Include="..\..\src\stream.cpp" />
<ClCompile Include="..\..\src\sync.cpp" />
<ClCompile Include="..\..\src\types.cpp" />
<ClCompile Include="..\..\src\uvc-libuvc.cpp" />
<ClCompile Include="..\..\src\uvc-v4l2.cpp" />
<ClCompile Include="..\..\src\uvc-wmf.cpp" />
<ClCompile Include="..\..\src\uvc.cpp" />
<ClCompile Include="..\..\src\verify.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\librealsense\rs.h" />
<ClInclude Include="..\..\include\librealsense\rs.hpp" />
<ClInclude Include="..\..\include\librealsense\rsutil.h" />
<ClInclude Include="..\..\src\context.h" />
<ClInclude Include="..\..\src\device.h" />
<ClInclude Include="..\..\src\f200-private.h" />
<ClInclude Include="..\..\src\f200.h" />
<ClInclude Include="..\..\src\image.h" />
<ClInclude Include="..\..\src\r200-private.h" />
<ClInclude Include="..\..\src\r200.h" />
<ClInclude Include="..\..\src\stream.h" />
<ClInclude Include="..\..\src\sync.h" />
<ClInclude Include="..\..\src\types.h" />
<ClInclude Include="..\..\src\uvc.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FD3A32E5-FD0B-4802-AED9-4260DF436FE0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>realsenses</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>obj\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>obj\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>obj\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>obj\$(Configuration)-$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)-$(Platform)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>RS_USE_WMF_BACKEND;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>RS_USE_WMF_BACKEND;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>RS_USE_WMF_BACKEND;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>RS_USE_WMF_BACKEND;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading