Skip to content

Commit

Permalink
Update README for get windows uvc time stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jian-dong committed May 24, 2024
1 parent c0df1c5 commit ec46f6f
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ python3 setup.py bdist_wheel
pip3 install dist/*.whl
```

## Enabling Device Timestamps via UVC Protocol on Windows

To get device timestamps through the UVC protocol on a Windows system, you must modify the registry by completing a registration process. This is required due to default system limitations. Follow the steps below to configure your system:

### 1. Connect the Device
- Ensure your UVC-compatible device is connected to the computer and recognized by the system. Confirm that the device is online and functioning.

### 2. Open PowerShell with Administrator Privileges
- Open the Start menu, type `PowerShell`, right-click on the PowerShell app, and select 'Run as administrator'.

### 3. Navigate to the Scripts Directory
- Use the `cd` command to change the directory to the location of your scripts.
```powershell
cd scripts
```

### 4. Modify Execution Policy
- Modify the PowerShell execution policy to allow script execution. Run the following command and press `Y` when prompted to confirm the change:
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

### 5. Execute the Registration Script
- Run the registration script to modify the registry settings. Use the following command:
```powershell
.\obsensor_metadata_win10.ps1 -op install_all
```

This will complete the necessary registration and modification of settings to allow device timestamps via the UVC protocol on your Windows system.


## Documentation

For detailed documentation, please refer to [docs/README.md](docs/README_EN.md).
Expand Down
126 changes: 126 additions & 0 deletions scripts/obsensor_metadata_win10.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Usage:
#Launch Windows PowerShell, and navigate to the script directory
#PS> .\obsensor_metadata_win10.ps1 - Add metadata reg. keys for the connected Orbbec devices
#PS> .\obsensor_metadata_win10.ps1 -op install - See above
#PS> .\obsensor_metadata_win10.ps1 -op install_all - Add metadata reg. keys for all Orbbec devices that were previously connected
#PS> .\obsensor_metadata_win10.ps1 -op remove - Remove metadata reg. keys for the connected Orbbec devices
#PS> .\obsensor_metadata_win10.ps1 -op remove_all - Remove metadata reg. keys for all Orbbec devices that were previously connected


#Parse command-line argument
param (
[string]$op = "install"
)

# Elevate to admin - https://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# The original script is modified to pass through the command-line parameter
$arguments = "& '" + $myinvocation.mycommand.definition + "'" + " -op " + $op
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

# Base location for the registry keys we need to add
$DevConfigRegBase = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceClasses"
# The Registry subtrees for the Metadata keys shall be added
$guid1 = "{e5323777-f976-4f5b-9b55-b94699c46e44}";
$guid2 = "{65E8773D-8F56-11D0-A3B9-00A0C9223196}";

$SearchTrees = "$DevConfigRegBase\$guid1", "$DevConfigRegBase\$guid2"

# Multipin devices that need additional key MetadataBufferSizeInKB1 & MetadataBufferSizeInKB2 & etc...
$MultiPinDevices = "USB\VID_2BC5&PID_06D0&MI_00", # Gemini 2 R // 3 pin for depth uvc
"USB\VID_2BC5&PID_06D1&MI_00" # Gemini 2 RL // 3 pin for depth uvc

#Inhibit system warnings and erros, such as permissions or missing values
$ErrorActionPreference = "silentlycontinue"

$ConnectedDev = @()
#Retrieve all connected UVC devices
$DevInReg = Get-ChildItem hklm:\SYSTEM\CurrentControlSet\Services\usbvideo | ForEach-Object {Get-ItemProperty $_.pspath}

#Transform output into a standard container
for ($i=0; $i -lt $DevInReg[0].Count; $i++) { $ConnectedDev +=$DevInReg[0].$i}

#Filter Orbbec devices
#$ConnectedDev = $ConnectedDev -like "*VID_8086*"
$ConnectedDev = $ConnectedDev -like "*VID_2BC5*"

#Progress notification
$rs_count = $ConnectedDev.Count
echo "$rs_count connected Orbbec devices were found:" $ConnectedDev

#Search each subtree for values that correspond to the requested Orbbec devices
foreach ($subtree in $SearchTrees)
{
"`nProcessing Registry branch $subtree"
#Get records for all UVC devices records
$Items = Get-ChildItem $subtree | Foreach-Object {Get-ItemProperty $_.PsPath }

#Filter Orbbec devices
"There are " + $Items.Count +" total devices listed"
# $Items = $Items | Where { $_.DeviceInstance -like "*VID_8086*" }
$Items = $Items | Where { $_.DeviceInstance -like "*VID_2BC5*" }
"" + $Items.Count + " of them are Orbbec devices"

$remove_keys = 0
switch ($op)
{
"install" { $Items = $Items | Where { $ConnectedDev -contains $_.DeviceInstance }}
"remove" { $Items = $Items | Where { $ConnectedDev -contains $_.DeviceInstance }; $remove_keys = 1 }
"install_all" { }
"remove_all" { $remove_keys = 1 }
default { "Aborting: unrecognized argument "" + $op + "" provided.`nPossible values are:";
"`t`t -op [install/install_all/remove/remove_all].`nRefer to the installation manual for details"; Sleep 2; Exit }
}

foreach ($item in $Items)
{

$fullPath = $item.PSPath+'\#global\Device Parameters'

if ($remove_keys -ge 1)
{
"Remove keys for device: " + $item.DeviceInstance.ToString()
# Non-present value will be ignored as for script execution policy
Remove-ItemProperty -path $fullPath -name MetadataBufferSizeInKB0
Remove-ItemProperty -path $fullPath -name MetadataBufferSizeInKB1
Remove-ItemProperty -path $fullPath -name MetadataBufferSizeInKB2
}
else
{
$val = 0,0,0
$val[0] = Get-ItemPropertyValue -Path $fullPath -Name MetadataBufferSizeInKB0
$val[1] = Get-ItemPropertyValue -Path $fullPath -Name MetadataBufferSizeInKB1
$val[2] = Get-ItemPropertyValue -Path $fullPath -Name MetadataBufferSizeInKB2

if ($val[0] -eq 0)
{
"Device " + $item.DeviceInstance.ToString() + ": adding metadata key"
Set-ItemProperty -path $fullPath -name MetadataBufferSizeInKB0 -value 5
}
else
{
"Device " + $item.DeviceInstance.ToString() + ": skiping - metadata key already exists"
}

if (($MultiPinDevices -contains $item.DeviceInstance.Substring(0,27)) -and ($val[1] -eq 0))
{
# Multi-pin interface requires an additional key
"Device " + $item.DeviceInstance.ToString() +": adding extra key for multipin interface, pin 1"
Set-ItemProperty -path $fullPath -name MetadataBufferSizeInKB1 -value 5
}

if (($MultiPinDevices -contains $item.DeviceInstance.Substring(0,27)) -and ($val[2] -eq 0))
{
# Multi-pin interface requires an additional key
"Device " + $item.DeviceInstance.ToString() +": adding extra key for multipin interface, pin 2"
Set-ItemProperty -path $fullPath -name MetadataBufferSizeInKB2 -value 5
}
}
}
}

"`nTask Completed"
sleep 1

0 comments on commit ec46f6f

Please sign in to comment.