Created
January 6, 2025 19:45
-
-
Save itskenny0/39a4b358aa2ecf0c5ef0e66c6ce22491 to your computer and use it in GitHub Desktop.
Adjust brightness on HyperPixel 4
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
#!/usr/bin/env bash | |
PIN=19 | |
FREQ=100 | |
STEP=100000 | |
MAX=1000000 | |
MIN=0 | |
get_current_duty() { | |
pigs gdc "$PIN" | |
} | |
set_duty() { | |
local newDuty=$1 | |
# Clamp values | |
if [ "$newDuty" -lt "$MIN" ]; then | |
newDuty=$MIN | |
fi | |
if [ "$newDuty" -gt "$MAX" ]; then | |
newDuty=$MAX | |
fi | |
pigs hp "$PIN" "$FREQ" "$newDuty" | |
} | |
case "$1" in | |
up) | |
current=$(get_current_duty) | |
new=$(( current + STEP )) | |
set_duty "$new" | |
;; | |
down) | |
current=$(get_current_duty) | |
new=$(( current - STEP )) | |
set_duty "$new" | |
;; | |
off) | |
set_duty 0 | |
;; | |
*) | |
if [[ "$1" =~ ^[0-9]+$ ]]; then | |
if [ "$1" -lt 0 ] || [ "$1" -gt 100 ]; then | |
echo "Percentage must be between 0 and 100." | |
exit 1 | |
fi | |
new=$(( ( $1 * MAX ) / 100 )) | |
set_duty "$new" | |
else | |
echo "Usage: $0 {up|down|off|<0-100>}" | |
exit 1 | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment