Last active
November 21, 2023 18:26
Star
You must be signed in to star a gist
This file contains 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
# Sources: | |
# - https://ultracrepidarian.phfactor.net/category/computer-science/ | |
# - https://www.reddit.com/r/LogitechG/comments/sacz2x/comment/hyfx2xo/?utm_source=share&utm_medium=web2x&context=3 | |
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-windows-x86_64\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])") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment