#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
. /etc/profile
tocon "Configuring display..."
### Variables may need to be device specific here.
BRIGHTNESS=$(get_setting system.brightness)
if [[ ! "${BRIGHTNESS}" =~ [0-9] ]]
then
if [ "${DEVICE_BRIGHTNESS}" = "hardware" ]
then
BRIGHTNESS=$(cat /sys/class/backlight/$(brightness device)/brightness 2>/dev/null)
else
BRIGHTNESS=${DEVICE_BRIGHTNESS}
fi
fi
# Ensure user doesn't get "locked out" with super low brightness
if [[ "${BRIGHTNESS}" -lt "3" ]]
then
BRIGHTNESS=3
fi
BRIGHTNESS_DEVICE="$(brightness device)"
if [ -e "/sys/class/backlight/${BRIGHTNESS_DEVICE}/brightness" ]
then
printf "%.0f" $(echo "${BRIGHTNESS}") > /sys/class/backlight/${BRIGHTNESS_DEVICE}/brightness
fi
### Set the aspect ratio in ES.
ASPECT=$(get_aspect_ratio)
ES_CONFIG="/storage/.config/emulationstation/es_settings.cfg"
ES_ASPECT="${ASPECT/:/-}"
if [ "$(grep subset.aspect-ratio ${ES_CONFIG})" ]
then
sed -i 's||g' ${ES_CONFIG}
else
sed -i '/<\/config>/i \\t' ${ES_CONFIG}
fi