Skip to content

Commit c515b08

Browse files
chuzihangzhonghong322
authored andcommitted
Add method to update depth presets
1 parent 7ea8f3b commit c515b08

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Device.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Text;
34

45
namespace Orbbec
56
{
@@ -490,6 +491,29 @@ public void DeviceUpgradeFromData(byte[] fileData, DeviceUpgradeCallback callbac
490491
NativeException.HandleError(error);
491492
}
492493

494+
private const int OB_PATH_MAX = 1024;
495+
public void UpdateOptionalDepthPresets(string[] filePaths, int pathCount, DeviceUpgradeCallback callback)
496+
{
497+
_deviceUpgradeCallback = callback;
498+
IntPtr error = IntPtr.Zero;
499+
IntPtr filesPtr = Marshal.AllocHGlobal(filePaths.Length * OB_PATH_MAX);
500+
for (int i = 0; i < filePaths.Length; i++)
501+
{
502+
byte[] buffer = new byte[OB_PATH_MAX];
503+
byte[] pathBytes = Encoding.UTF8.GetBytes(filePaths[i]);
504+
int copyLength = Math.Min(pathBytes.Length, OB_PATH_MAX - 1);
505+
506+
Array.Copy(pathBytes, 0, buffer, 0, copyLength);
507+
buffer[copyLength] = 0;
508+
509+
IntPtr filePtr = IntPtr.Add(filesPtr, i * OB_PATH_MAX);
510+
Marshal.Copy(buffer, 0, filePtr, OB_PATH_MAX);
511+
}
512+
obNative.ob_device_update_optional_depth_presets(_handle.Ptr, filesPtr, (uint)pathCount, _nativeDeviceUpgradeCallback, IntPtr.Zero, ref error);
513+
Marshal.FreeHGlobal(filesPtr);
514+
NativeException.HandleError(error);
515+
}
516+
493517
/**
494518
* \if English
495519
* @brief Get the current state

src/obNative.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ internal class obNative
216216
[DllImport(obsdk, EntryPoint = "ob_device_update_firmware_from_data")]
217217
public static extern void ob_device_update_firmware_from_data(IntPtr device, IntPtr fileData, UInt32 fileSize, [MarshalAs(UnmanagedType.FunctionPtr)] NativeDeviceUpgradeCallback callback, bool asycn, IntPtr userData, ref IntPtr error);
218218

219+
//void ob_device_update_optional_depth_presets(ob_device *device, const char file_path_list[][OB_PATH_MAX], uint8_t path_count, ob_device_fw_update_callback callback, void* user_data, ob_error **error);
220+
[DllImport(obsdk, EntryPoint = "ob_device_update_optional_depth_presets")]
221+
public static extern void ob_device_update_optional_depth_presets(IntPtr device, IntPtr filePathList, uint pathCount, [MarshalAs(UnmanagedType.FunctionPtr)] NativeDeviceUpgradeCallback callback, IntPtr userData, ref IntPtr error);
222+
219223
//ob_device_state ob_device_get_device_state( ob_device* device, ob_error** error );
220224
[DllImport(obsdk, EntryPoint = "ob_device_get_device_state")]
221225
public static extern UInt64 ob_device_get_device_state(IntPtr device, ref IntPtr error);

0 commit comments

Comments
 (0)