// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
namespace Intel.RealSense
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class AdvancedDevice : Device
{
internal AdvancedDevice(IntPtr dev)
: base(dev)
{
}
///
/// Create an from existing
///
/// a device that supports
/// a new
/// Thrown when does not support
public static AdvancedDevice FromDevice(Device dev)
{
object error;
if (NativeMethods.rs2_is_device_extendable_to(dev.Handle, Extension.AdvancedMode, out error) == 0)
{
throw new ArgumentException($"Device does not support {nameof(Extension.AdvancedMode)}");
}
return Device.Create(dev.Handle);
}
///
/// Gets or sets a value indicating whether Advanced-Mode is enabled
///
/// when Advanced-Mode is enabled
public bool AdvancedModeEnabled
{
get
{
int enabled = 0;
try
{
object error;
NativeMethods.rs2_is_enabled(Handle, out enabled, out error);
}
catch
{
// above might throw, ignored for this getter
}
return enabled == 1;
}
set
{
object error;
NativeMethods.rs2_toggle_advanced_mode(Handle, value ? 1 : 0, out error);
}
}
///
/// Gets or sets JSON and applies advanced-mode controls
///
/// Serialize JSON content
public string JsonConfiguration
{
get
{
object error;
IntPtr buffer = NativeMethods.rs2_serialize_json(Handle, out error);
int size = NativeMethods.rs2_get_raw_data_size(buffer, out error);
IntPtr data = NativeMethods.rs2_get_raw_data(buffer, out error);
var str = Marshal.PtrToStringAnsi(data, size);
NativeMethods.rs2_delete_raw_data(buffer);
return str;
}
set
{
object error;
NativeMethods.rs2_load_json(Handle, value, (uint)value.Length, out error);
}
}
}
}