Skip to content

Instantly share code, notes, and snippets.

@9dc
Last active March 20, 2024 09:32
Show Gist options
  • Save 9dc/010b7625980e71077211456b4e96ff84 to your computer and use it in GitHub Desktop.
Save 9dc/010b7625980e71077211456b4e96ff84 to your computer and use it in GitHub Desktop.
Auto On/Off of Logitech Litra Glow when Webcam in use (for Teams) // doesnt need any logitech shit software other than hidapitester.exe
function setLightState {
param (
[Parameter(Mandatory = $true)]
[ValidateSet('On', 'Off')]
[String]$state,
[ValidateRange(1, 100)]
[Int]$brightness=50,
[ValidateRange(2700, 6500)]
[Int]$temperature=6500
)
function run {
param ($bytes)
&"$PSScriptRoot\hidapitester.exe" --quiet --vidpid 046D/C900 --usagePage FF43 --open --length 20 --send-output $bytes
}
Write-Host "State: $state, Brightness: $brightness, Temperature: $temperature"
switch ($state) {
'On' { run('0x11,0xff,0x04,0x1c,0x01') }
'Off' { run('0x11,0xff,0x04,0x1c,0x00') }
}
if ($state -eq 'On') {
# Remap brightness from 1-100 to 20-250
$adjustedBrightness = [Math]::Floor(($brightness - 1) / (100 - 1) * (250 - 20) + 20)
run("0x11,0xff,0x04,0x4c,0x00,$adjustedBrightness")
$temperatureAsBytes = [BitConverter]::GetBytes($temperature)
run("0x11,0xff,0x04,0x9c,$($temperatureAsBytes[1]),$($temperatureAsBytes[0])")
}
}
$prevLastUsedTimeStop = $null
while ($true) {
# EDIT IF YOU NEED IT FOR OTHER PROGRAMS
$regKey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged\C:#Users#Robin#AppData#Local#Microsoft#Teams#current#Teams.exe"
$lastUsedTimeStop = (Get-ItemProperty -Path $regKey -Name "LastUsedTimeStop").LastUsedTimeStop
if ($lastUsedTimeStop -ne $prevLastUsedTimeStop) {
# The value has changed, update the previous value and take action
$prevLastUsedTimeStop = $lastUsedTimeStop
if ($lastUsedTimeStop -eq 0) {
# LastUsedTimeStop is 0, turn on the light
setLightState -State 'On' -Brightness 100 -Temperature 6500
} else {
# LastUsedTimeStop is not 0, turn off the light
setLightState -State 'Off'
}
}
# Wait for 2 seconds before checking again
Start-Sleep -Seconds 2
}
@9dc
Copy link
Author

9dc commented Mar 23, 2023

needed:

https://github.com/todbot/hidapitester (.exe in same folder)

and set
"Set-ExecutionPolicy RemoteSigned" in powershell admin console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment