Last active
December 20, 2023 07:29
-
-
Save poiriersimon/eaee208ce8ea79f30b4cc7d3a078c3bc to your computer and use it in GitHub Desktop.
Logitech Litra Glow Beam Powershell Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Litra Glow and Litra Beam Powershell Controller | |
#Download hidapitester here : https://github.com/todbot/hidapitester/releases | |
#Based on https://www.reddit.com/r/LogitechG/comments/sacz2x/comment/j7doia4/?utm_source=share&utm_medium=web2x&context=3 | |
#Change to point to the extract folder | |
$HIDAPItesterFolderPath = "C:\Users\username\Scripts\" | |
#HIDAPItester | |
$global:HIDAPItesterPath = $HIDAPItesterFolderPath + "hidapitester.exe" | |
Function Set-HIDAPItester { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $vidpid, | |
[Parameter(Mandatory = $true)] | |
[string] $OpenPath, | |
[Parameter(Mandatory = $true)] | |
[string] $output, | |
[Parameter(Mandatory = $true)] | |
[string] $usagePage, | |
[string] $HIDAPItesterPath = $global:HIDAPItesterPath | |
) | |
$null = &($HIDAPItesterPath) --vidpid $vidpid --usagePage $usagePage --open-path $OpenPath --send-output $output | |
} | |
Function Get-LitraLight { | |
[CmdletBinding()] | |
param ( | |
[switch] $Beam, | |
[switch] $Glow | |
) | |
if($Beam){ | |
$LitraRaw= &($HIDAPItesterPath) --vidpid 046d/c901 --usagePage FF43 --list-detail | |
} | |
elseif($Glow){ | |
$LitraRaw= &($HIDAPItesterPath) --vidpid 046d/c900 --usagePage FF43 --list-detail | |
}else{ | |
$LitraRaw= &($HIDAPItesterPath) --usagePage FF43 --list-detail | |
} | |
#$litraRaw | |
$i=0 | |
[Array]$LitraLights = @() | |
$LitraLight = New-Object PSObject | |
foreach($line in $litraRaw){ | |
$i++ | |
if($i -eq 1){ | |
$name = "vidpid" | |
$value = $line.split(":")[0].trim() | |
}else{ | |
$name = $line.split(":")[0].trim() | |
$value = $line.split(":")[-1].trim() | |
} | |
if(!$([string]::IsNullOrempty($name))){ | |
$LitraLight | Add-Member NoteProperty -Name $name -Value $value | |
} | |
if($i -gt 8){ | |
$i=0 | |
[Array]$LitraLights+=$LitraLight | |
$LitraLight = New-Object PSObject | |
} | |
} | |
return $LitraLights | |
} | |
function Set-LitraLight { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $vidpid, | |
[Parameter(Mandatory = $true)] | |
[string] $OpenPath, | |
[ValidateRange(1, 100)] | |
[int] $Brightness, | |
[ValidateRange(2700, 6500)] | |
[int] $temperature | |
) | |
if($Brightness -gt 0){ | |
[int]$brightnessvalue = [math]::floor(31 + ($Brightness/100*368)) | |
$brightnessvalue | |
$hex = $brightnessvalue | Format-Hex | |
$hex | |
$output= "0x11,0xFF,0x04,0x4F,0x"+ $hex.HexBytes.Split(" ")[1] +",0x"+ $hex.HexBytes.Split(" ")[0] | |
Set-HIDAPItester -vidpid $vidpid -usagePage ff43 -OpenPath $OpenPath -output $output | |
} | |
if($temperature -gt 0){ | |
$hex = $temperature | Format-Hex | |
$hex | |
$output = "0x11,0xFF,0x04,0x9D,0x"+ $hex.HexBytes.Split(" ")[1] +",0x" + $hex.HexBytes.Split(" ")[0] | |
Set-HIDAPItester -vidpid $vidpid -usagePage ff43 -OpenPath $OpenPath -output $output | |
} | |
} | |
Function Start-LitraLight { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $vidpid, | |
[Parameter(Mandatory = $true)] | |
[string] $OpenPath | |
) | |
$output = "0x11,0xFF,0x04,0x1D,0x01" | |
Set-HIDAPItester -vidpid $vidpid -usagePage ff43 -OpenPath $OpenPath -output $output | |
} | |
Function Stop-LitraLight { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $vidpid, | |
[Parameter(Mandatory = $true)] | |
[string] $OpenPath | |
) | |
$output = "0x11,0xFF,0x04,0x1D,0x00" | |
Set-HIDAPItester -vidpid $vidpid -usagePage ff43 -OpenPath $OpenPath -output $output | |
} | |
#Exemple: | |
Write-host "All Off" | |
$lights = Get-LitraLight | |
foreach($Light in $Lights){ | |
Stop-LitraLight -vidpid $light.vidpid -OpenPath $light.path | |
} | |
Write-host "All On" | |
$lights = Get-LitraLight | |
foreach($Light in $Lights){ | |
start-LitraLight -vidpid $light.vidpid -OpenPath $light.path | |
} | |
Write-host "Beam On" | |
$lights = Get-LitraLight -Beam | |
foreach($Light in $Lights){ | |
start-LitraLight -vidpid $light.vidpid -OpenPath $light.path | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No problem 😊. Thank you again for creating this in the first place!