2023-03-31 12:26:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Copyright (C) 2023-present Fewtarius
|
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
# ARGS:
|
|
|
|
#
|
2023-04-01 00:20:39 +00:00
|
|
|
# 1 - property to adjust (gamma (brightness)/contrast/saturation/hue)
|
2023-03-31 12:26:01 +00:00
|
|
|
# 2 - up/down or a defined value
|
|
|
|
|
|
|
|
PROPERTY=${1}
|
|
|
|
NEWVAL=${2}
|
|
|
|
|
|
|
|
# Command usage:
|
|
|
|
# drm_tool set /dev/dri/card0 133 saturation value
|
|
|
|
|
|
|
|
# Define the basics
|
|
|
|
MIN=1
|
|
|
|
MAX=100
|
|
|
|
STEP=1
|
|
|
|
|
|
|
|
if [ ! -e /dev/dri/card0 ]
|
|
|
|
then
|
|
|
|
echo "ERROR: No display found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
log() {
|
2023-04-01 00:20:39 +00:00
|
|
|
$DEBUG && echo "Info: ${*}" >>/var/log/display.log
|
2023-03-31 12:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
2023-04-01 00:20:39 +00:00
|
|
|
MYVAL=$(get_setting display.${1})
|
2023-03-31 12:26:01 +00:00
|
|
|
if [ -n "${MYVAL}" ]
|
|
|
|
then
|
|
|
|
if [ "${MYVAL}" > "${MAX}" ]
|
|
|
|
then
|
|
|
|
MYVAL=${MAX}
|
|
|
|
elif [ "${MYVAL}" < "${MIN}" ]
|
|
|
|
then
|
|
|
|
MYVAL=${MIN}
|
|
|
|
fi
|
|
|
|
echo ${MYVAL}
|
|
|
|
else
|
2023-04-26 00:16:29 +00:00
|
|
|
echo $(drm_tool list 2>/dev/null | sed -n '/Connector: '${CONNECTOR}'/,$p' | awk '/'${1}'/ {print $5}')
|
2023-03-31 12:26:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
setValue() {
|
2023-04-01 00:20:39 +00:00
|
|
|
log "Set (${1}: ${2})"
|
2023-04-26 00:16:29 +00:00
|
|
|
drm_tool set /dev/dri/card0 ${CONNECTOR} ${1} ${2} 2>/dev/null
|
2023-03-31 12:26:01 +00:00
|
|
|
if [ $? = 0 ]
|
|
|
|
then
|
2023-04-01 00:20:39 +00:00
|
|
|
set_setting display.${1} ${2}
|
2023-03-31 12:26:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stepUp() {
|
2023-03-31 12:28:38 +00:00
|
|
|
LASTVAL=$(getValue ${PROPERTY})
|
2023-03-31 12:26:01 +00:00
|
|
|
NEWVAL=$(expr ${LASTVAL} + 1)
|
2023-04-01 00:20:39 +00:00
|
|
|
log "Step up (${PROPERTY}: ${NEWVAL})"
|
2023-03-31 12:26:01 +00:00
|
|
|
setValue ${PROPERTY} ${NEWVAL}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepDown() {
|
2023-03-31 12:28:38 +00:00
|
|
|
LASTVAL=$(getValue ${PROPERTY})
|
2023-03-31 12:26:01 +00:00
|
|
|
NEWVAL=$(expr ${LASTVAL} - 1)
|
2023-04-01 00:20:39 +00:00
|
|
|
log "Step down (${PROPERTY}: ${NEWVAL})"
|
2023-03-31 12:26:01 +00:00
|
|
|
setValue ${PROPERTY} ${NEWVAL}
|
|
|
|
}
|
|
|
|
|
|
|
|
restoreSettings() {
|
2023-04-01 00:20:39 +00:00
|
|
|
for PROPERTY in brightness contrast saturation hue
|
2023-03-31 12:26:01 +00:00
|
|
|
do
|
2023-03-31 12:28:38 +00:00
|
|
|
RESTVAL=$(getValue ${PROPERTY})
|
|
|
|
setValue ${PROPERTY} ${RESTVAL}
|
2023-03-31 12:26:01 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-04-26 00:16:29 +00:00
|
|
|
CONNECTOR=$(drm_tool list | grep -B1 "mode.*:" | awk '/Connector/ {print $2}')
|
|
|
|
|
2023-03-31 12:26:01 +00:00
|
|
|
case ${NEWVAL} in
|
|
|
|
"up")
|
|
|
|
stepUp
|
|
|
|
;;
|
|
|
|
"down")
|
|
|
|
stepDown
|
|
|
|
;;
|
|
|
|
"restore")
|
|
|
|
restoreSettings
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [[ "${NEWVAL}" =~ ^[0-9] ]] && \
|
|
|
|
[ "${NEWVAL}" -le "${MAX}" ] && \
|
|
|
|
[ "${NEWVAL}" -ge "${MIN}" ]
|
|
|
|
then
|
|
|
|
setValue ${PROPERTY} ${NEWVAL}
|
|
|
|
else
|
|
|
|
echo "Error: Invalid value."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|