forked from ophub/amlogic-s9xxx-armbian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
armbian-openvfd
executable file
·192 lines (172 loc) · 6.61 KB
/
armbian-openvfd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
#==========================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Rebuild Armbian
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: LED display control
# Copyright (C) 2022- https://github.com/unifreq/openwrt_packit
# Copyright (C) 2022- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Function : Command
# Default : armbian-openvfd
# One-key to open : armbian-openvfd <boxid>
# One-key to stop : armbian-openvfd 0
# Update config : armbian-openvfd -u
#
#============================= Functions list =============================
#
# do_start : Turn on the led screen display
# do_stop : Turn off the led screen display
# do_update_conf : Update openvfd config files
# do_select_box : Call config based on options
#
#==========================================================================
#
# Openvfd files storage path
openvfd_path="/usr/share/openvfd"
openvfd_service="${openvfd_path}/vfdservice"
# The openvfd files download repository
openvfd_repo="https://github.com/ophub/amlogic-s9xxx-armbian/tree/main/build-armbian/armbian-files/platform-files/amlogic/rootfs${openvfd_path}"
#
# Set font color
STEPS="[\033[95m STEPS \033[0m]"
INFO="[\033[94m INFO \033[0m]"
SUCCESS="[\033[92m SUCCESS \033[0m]"
OPTIONS="[\033[93m OPTIONS \033[0m]"
ERROR="[\033[91m ERROR \033[0m]"
#
#==========================================================================
# Show error message
error_msg() {
echo -e "${ERROR} ${1}"
exit 1
}
# Update openvfd config files
do_update_conf() {
echo -e "${STEPS} Start updating the openfvd config files..."
# Check dependencies
[[ -z "$(dpkg -l | awk '{print $2}' | grep -w "^subversion$")" ]] && sudo apt-get update && sudo apt-get install -y subversion
# Convert script repository address to svn format
if [[ "${openvfd_repo}" == http* && -n "$(echo ${openvfd_repo} | grep "tree/main")" ]]; then
openvfd_repo="${openvfd_repo//tree\/main/trunk}"
fi
# Update related files
echo -e "${STEPS} Start syncing files..."
[[ -d "${openvfd_path}" ]] || mkdir -p ${openvfd_path}
svn export ${openvfd_repo} ${openvfd_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${openvfd_repo} ] scripts failed."
chmod +x ${openvfd_path}/vfdservice
sync && sleep 3
echo -e "${SUCCESS} Openfvd config files update completed."
exit 0
}
# Turn on the led screen display
do_start() {
echo -e "${STEPS} Start the led screen display..."
# Check config files and services
conf_file="${openvfd_path}/conf/${1}"
if [[ -s "${conf_file}" && -x "${openvfd_service}" ]]; then
source "${conf_file}" 2>/dev/null
echo -e "${INFO} Using LED Profiles: ${conf_file}"
else
error_msg "The LED profile [ ${conf_file} ] does not exist!"
fi
modprobe openvfd vfd_gpio_clk=${vfd_gpio_clk} \
vfd_gpio_dat=${vfd_gpio_dat} \
vfd_gpio_stb=${vfd_gpio_stb:-0,0,0xFF} \
vfd_gpio0=${vfd_gpio0:-0,0,0xFF} \
vfd_gpio1=${vfd_gpio1:-0,0,0xFF} \
vfd_gpio2=${vfd_gpio2:-0,0,0xFF} \
vfd_gpio3=${vfd_gpio3:-0,0,0xFF} \
vfd_gpio_protocol=${vfd_gpio_protocol:-0,0} \
vfd_chars=${vfd_chars} vfd_dot_bits=${vfd_dot_bits} \
vfd_display_type=${vfd_display_type}
"${openvfd_service}" &
trap "killall ${openvfd_service}; rmmod openvfd; exit" 2 3 15
if [[ -n "${functions}" ]]; then
for func in ${functions}; do
echo -e "${INFO} turn led ${func} on ... "
echo "${func}" >/sys/class/leds/openvfd/led_on 2>/dev/null
done
fi
echo -e "${SUCCESS} Enable LED display!"
exit 0
}
# Turn off the led screen display
do_stop() {
echo -e "${STEPS} Start to turn off the led screen display..."
killall -9 vfdservice 2>/dev/null
rmmod openvfd -f 2>/dev/null
echo -e "${SUCCESS} Disable LED display!"
exit 0
}
# Call config based on options
do_select_box() {
case "${1}" in
11 | x96max) do_start x96max.conf ;;
12 | x96maxplus) do_start x96maxplus.conf ;;
13 | x96air) do_start x96air.conf ;;
14 | h96max-x3) do_start h96max-x3.conf ;;
15 | hk1-x3) do_start hk1-x3.conf ;;
16 | hk1box) do_start hk1box.conf ;;
17 | tx3) do_start tx3.conf ;;
18 | tx3-mini) do_start tx3-mini.conf ;;
19 | t95) do_start t95.conf ;;
20 | t95z-plus) do_start t95z-plus.conf ;;
21 | tx9-pro) do_start tx9-pro.conf ;;
22 | x92) do_start x92.conf ;;
23 | whale) do_start whale.conf ;;
24 | x88pro-x3) do_start x88pro-x3.conf ;;
99 | diy) do_start diy.conf ;;
0 | stop) do_stop ;;
1 | quit) echo "quit!" && exit 0 ;;
*) error_msg "Invalid input!" ;;
esac
}
# Execute according to the classification of input parameters
case "${1}" in
-u | u | -update | update)
do_update_conf
;;
[0-9]*)
do_select_box "${1}"
;;
*)
clear
cat <<EOF
┌────────[ Enable LED ]─────────┐
│ │
│ 11. x96max (s905x2) │
│ 12. x96maxplus (s905x3) │
│ 13. x96air (s905x3) │
│ 14. h96max-x3 (s905x3) │
│ 15. hk1-x3 (s905x3) │
│ 16. hk1box (s905x3) │
│ 17. tx3 (s905x3) │
│ 18. tx3-mini (s905w) │
│ 19. t95 (s905x) │
│ 20. t95z-plus (s912) │
│ 21. tx9-pro (s912) │
│ 22. x92 (s912) │
│ 23. whale (s905x3) │
| 24. x88pro-x3 (s905x3) |
│ 99. diy │
│ │
├──────[ Other Operations ]─────┤
│ │
│ -u. update │
│ 0. stop │
│ 1. quit │
│ │
└───────────────────────────────┘
EOF
echo -ne "${OPTIONS} Please Input ID: "
read boxid
do_select_box "${boxid}"
;;
esac