mirror of
https://github.com/nikdoof/builder.git
synced 2025-12-25 15:59:22 +00:00
add Xiaomi MJSXJ02HL
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Automatic LED control for Xiaomi MJSXJ02HL
|
||||
|
||||
streamerProcess="majestic"
|
||||
serviceProcess="sysupgrade"
|
||||
pollingInterval=1
|
||||
|
||||
show_help() {
|
||||
echo "Usage: $0 [-p process] [-s process] [-i value] [-h]
|
||||
-p process Name of the monitored streamer process (default = ${streamerProcess}).
|
||||
-s process Name of the monitored service process (default = ${serviceProcess}).
|
||||
-i value Polling interval in seconds (default = ${pollingInterval}).
|
||||
-h Show this help."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# override config values with command line arguments
|
||||
while getopts H:L:i:h flag; do
|
||||
case ${flag} in
|
||||
p) streamerProcess=${OPTARG} ;;
|
||||
s) serviceProcess=${OPTARG} ;;
|
||||
i) pollingInterval=${OPTARG} ;;
|
||||
h | *) show_help ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "...................."
|
||||
echo "Name of the monitored streamer process: ${streamerProcess}"
|
||||
echo "Name of the monitored service process: ${serviceProcess}"
|
||||
echo "Polling interval: ${pollingInterval} sec"
|
||||
echo "...................."
|
||||
|
||||
led_state=0
|
||||
/usr/sbin/led_control.sh -o 0 -b 0
|
||||
echo "...................."
|
||||
|
||||
while true; do
|
||||
if killall -q -0 $serviceProcess; then
|
||||
if [ $led_state -ne 3 ]; then
|
||||
echo "Process $serviceProcess is running, turn on the white LED"
|
||||
/usr/sbin/led_control.sh -o 1 -b 1
|
||||
led_state=3
|
||||
echo "...................."
|
||||
fi
|
||||
else
|
||||
if [ $led_state -ne 1 ] && ! killall -q -0 $streamerProcess; then
|
||||
echo "Process $streamerProcess is not running, turn on the orange LED"
|
||||
/usr/sbin/led_control.sh -o 1 -b 0
|
||||
led_state=1
|
||||
echo "...................."
|
||||
elif [ $led_state -ne 2 ] && killall -q -0 $streamerProcess; then
|
||||
echo "Process $streamerProcess is running, turn on the blue LED"
|
||||
/usr/sbin/led_control.sh -o 0 -b 1
|
||||
led_state=2
|
||||
echo "...................."
|
||||
fi
|
||||
fi
|
||||
sleep $pollingInterval
|
||||
done
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Majestic settinfs for Xiaomi MJSXJ02HL
|
||||
#
|
||||
# nightMode:
|
||||
# enabled: true
|
||||
# irCutPin1: 70
|
||||
# irCutPin2: 68
|
||||
# backlightPin: 54
|
||||
|
||||
again_high_target=14000
|
||||
again_low_target=2000
|
||||
pollingInterval=5
|
||||
|
||||
show_help() {
|
||||
echo "Usage: $0 [-H value] [-L value] [-i value] [-h]
|
||||
-H value Again high target (default = ${again_high_target}).
|
||||
-L value Again low target (default = ${again_low_target}).
|
||||
-i value Polling interval (default = ${pollingInterval}).
|
||||
-h Show this help."
|
||||
exit 0
|
||||
}
|
||||
|
||||
while getopts H:L:i:h flag; do
|
||||
case ${flag} in
|
||||
H) again_high_target=${OPTARG} ;;
|
||||
L) again_low_target=${OPTARG} ;;
|
||||
i) pollingInterval=${OPTARG} ;;
|
||||
h | *) show_help ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "...................."
|
||||
echo "Watching at isp_again > ${again_high_target} to enable night mode"
|
||||
echo "Watching at isp_again < ${again_low_target} to disable night mode"
|
||||
echo "Polling interval: ${pollingInterval} sec"
|
||||
echo "...................."
|
||||
|
||||
login=$(cat /etc/httpd.conf | grep cgi-bin | cut -d':' -f2)
|
||||
pass=$(cat /etc/httpd.conf | grep cgi-bin | cut -d':' -f3)
|
||||
|
||||
while true; do
|
||||
metrics=$(curl -s http://localhost/metrics)
|
||||
isp_again=$(echo "${metrics}" | awk '/^isp_again/ {print $2}' | grep . || echo 0)
|
||||
night_enabled=$(echo "${metrics}" | awk '/^night_enabled/ {print $2}' | grep . || echo 0)
|
||||
|
||||
if [ $night_enabled -ne 1 ] && [ $isp_again -gt $again_high_target ]; then
|
||||
curl -s -u $login:$pass http://localhost/night/on
|
||||
echo "Condition isp_again > ${again_high_target} was met (current value is ${isp_again}), turn on the night mode"
|
||||
elif [ $night_enabled -ne 0 ] && [ $isp_again -lt $again_low_target ]; then
|
||||
curl -s -u $login:$pass http://localhost/night/off
|
||||
echo "Condition isp_again < ${again_low_target} was met (current value is ${isp_again}), turn off the night mode"
|
||||
fi
|
||||
|
||||
sleep $pollingInterval
|
||||
done
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# LED control for Xiaomi MJSXJ02HL
|
||||
|
||||
show_help() {
|
||||
echo "Usage: $0 [-o <0|1>] [-b <0|1>]
|
||||
-o <0|1> Switch state for orange LED.
|
||||
-b <0|1> Switch state for blue LED."
|
||||
exit 0
|
||||
}
|
||||
|
||||
led_control() {
|
||||
echo "Switching LED with GPIO${1} to state ${2}"
|
||||
if [ ! -d /sys/class/gpio/gpio${1}/ ]; then
|
||||
echo ${1} > /sys/class/gpio/export
|
||||
echo out > /sys/class/gpio/gpio${1}/direction
|
||||
fi
|
||||
echo ${2} > /sys/class/gpio/gpio${1}/value
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then show_help; fi
|
||||
while getopts o:b: flag; do
|
||||
case ${flag} in
|
||||
o)
|
||||
[ ${OPTARG} -eq 0 -o ${OPTARG} -eq 1 ] || show_help
|
||||
led_control 52 ${OPTARG}
|
||||
;;
|
||||
b)
|
||||
[ ${OPTARG} -eq 0 -o ${OPTARG} -eq 1 ] || show_help
|
||||
led_control 53 ${OPTARG}
|
||||
;;
|
||||
*) show_help ;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue
Block a user