#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

. /etc/profile

COLOR=$(get_setting led.color)
BRI=$(get_setting led.brightness)

if [ -z "${COLOR}" ] || \
     [ "${COLOR}" = "off" ] || \
     [ -n "${DEVICE_LED_CHARGING}" ]
then
  FLASH_COLOR="red"
else
  FLASH_COLOR="${COLOR}"
fi

if [ "${DEVICE_LED_BRIGHTNESS}" = "true" ]
then
  ledcontrol brightness mid
fi

for i in $(seq 1 1 3)
do
  ledcontrol ${FLASH_COLOR}
  sleep .5
  ledcontrol poweroff
  sleep .5
done

if [ -n "${COLOR}" ]
then
  ledcontrol ${COLOR}
else
  ledcontrol default
fi

if [ "${DEVICE_LED_BRIGHTNESS}" = "true" ]
then
  ledcontrol brightness ${BRI}
fi
