-
Notifications
You must be signed in to change notification settings - Fork 70
/
zynthian.sh
executable file
·296 lines (247 loc) · 8.15 KB
/
zynthian.sh
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
#******************************************************************************
# ZYNTHIAN PROJECT: Zynthian Start Script
#
# Start all services needed by zynthian and the zynthian UI
#
# Copyright (C) 2015-2023 Fernando Moyano <[email protected]>
#
#******************************************************************************
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the LICENSE.txt file.
#
#******************************************************************************
#export ZYNTHIAN_LOG_LEVEL=10 # 10=DEBUG, 20=INFO, 30=WARNING, 40=ERROR, 50=CRITICAL
#export ZYNTHIAN_RAISE_EXCEPTIONS=0
#------------------------------------------------------------------------------
# Some Functions
#------------------------------------------------------------------------------
function load_config_env() {
source "$ZYNTHIAN_SYS_DIR/scripts/zynthian_envars_extended.sh"
if [ -z "$ZYNTHIAN_SCRIPT_MIDI_PROFILE" ]; then
source "$ZYNTHIAN_MY_DATA_DIR/midi-profiles/default.sh"
else
source "$ZYNTHIAN_SCRIPT_MIDI_PROFILE"
fi
if [ -f "$ZYNTHIAN_CONFIG_DIR/zynthian_custom_config.sh" ]; then
source "$ZYNTHIAN_CONFIG_DIR/zynthian_custom_config.sh"
fi
}
function raw_splash_zynthian() {
if [ -c $FRAMEBUFFER ]; then
cat $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_boot.raw > $FRAMEBUFFER
fi
}
function raw_splash_zynthian_error() {
if [ -c $FRAMEBUFFER ]; then
cat $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_error.raw > $FRAMEBUFFER
fi
}
function splash_zynthian() {
xloadimage -fullscreen -onroot $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_boot.jpg
}
function splash_zynthian_message() {
zynthian_message=$1
img_fpath=$2
[ "$img_fpath" ] || img_fpath="$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_boot.jpg"
# Generate a splash image with the message...
img_w=$(identify -format '%w' $img_fpath)
img_h=$(identify -format '%h' $img_fpath)
if [[ "${#zynthian_message}" > "40" ]]; then
font_size=$(expr $img_w / 36)
else
font_size=$(expr $img_w / 28)
fi
strlen=$(expr ${#zynthian_message} \* $font_size / 2)
pos_x=$(expr $img_w / 2 - $strlen / 2)
pos_y=$(expr $img_h \* 10 / 100)
[[ "$pos_x" > "0" ]] || pos_x=5
convert -strip -family \"$ZYNTHIAN_UI_FONT_FAMILY\" -pointsize $font_size -fill white -draw "text $pos_x,$pos_y \"$zynthian_message\"" $img_fpath $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg
# Display error image
xloadimage -fullscreen -onroot $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg
}
function splash_zynthian_error() {
# Generate an error splash image...
splash_zynthian_message "$1" "$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_error.jpg"
}
function splash_zynthian_error_exit_ip() {
# Grab exit code if set
zynthian_error=$1
[ "$zynthian_error" ] || zynthian_error="???"
case $zynthian_error in
1)
message="Software"
;;
139)
message="SegFault"
;;
200)
message="Zyncore"
;;
201)
message="Control I/O"
;;
202)
message="Audio/MIDI"
;;
203)
message="CV/Gate"
;;
*)
message="ErrCode $zynthian_error"
;;
esac
# Get the IP
#zynthian_ip=`ip route get 1 | awk '{print $NF;exit}'`
zynthian_ip=$(hostname -I | cut -d " " -f1)
# Format the message
zynthian_message="IP:$zynthian_ip $message"
# Generate an error splash image with the IP & exit code...
splash_zynthian_message "$zynthian_message" "$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_error.jpg"
}
function splash_zynthian_last_message() {
if [ -f "$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg" ]; then
xloadimage -fullscreen -onroot $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg
else
xloadimage -fullscreen -onroot $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_boot.jpg
fi
}
function clean_zynthian_last_message() {
if [ -f "$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg" ]; then
rm -f $ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_message.jpg
fi
}
function start_wifi_ap() {
readarray -t connected_devices <<< $(nmcli --terse c show | cut -d : -f 4 | tr -s '\n' | tr -s 'lo\n')
if [[ "${#connected_devices[*]}" < "2" ]]; then
nmcli radio wifi on
nmcli con up "zynthian-ap"
fi
}
powersave_control.sh off
load_config_env
#------------------------------------------------------------------------------
# Test splash screen generator
#------------------------------------------------------------------------------
#splash_zynthian_message "Testing Splash Screen Generator..."
#sleep 10
#exit
if [[ "$(systemctl is-enabled first_boot)" == "enabled" ]]; then
is_first_boot=1
else
is_first_boot=0
fi
#------------------------------------------------------------------------------
# If needed, generate splash screen images
#------------------------------------------------------------------------------
if [[ ! -f "$ZYNTHIAN_CONFIG_DIR/img/fb_zynthian_error.jpg" ]]; then
if [[ "$is_first_boot" == "1" ]]; then
$ZYNTHIAN_SYS_DIR/sbin/generate_fb_splash.sh >> /root/first_boot.log
else
$ZYNTHIAN_SYS_DIR/sbin/generate_fb_splash.sh
fi
fi
#------------------------------------------------------------------------------
# Run Hardware Test
#------------------------------------------------------------------------------
if [[ -n "$ZYNTHIAN_HW_TEST" ]]; then
echo "Running HW test: $ZYNTHIAN_HW_TEST"
result=$($ZYNTHIAN_SYS_DIR/sbin/zynthian_hw_test.py $ZYNTHIAN_HW_TEST | tail -1)
res=${result%:*}
message=${result#*:}
if [[ "$res" == "OK" ]]; then
splash_zynthian_message "$result"
else
splash_zynthian_error "$message"
fi
run_control_test="0"
if [[ "$ZYNTHIAN_UI_CONTROL_TEST_ENABLED" == "1" ]]; then
control_board_name="V5_CONTROL"
echo "Testing control board '$control_board_name'..."
result=$($ZYNTHIAN_SYS_DIR/sbin/zynthian_hw_test.py $control_board_name | tail -1)
res=${result%:*}
#echo "RESULT => $result => $res"
if [[ "$res" == "OK" ]]; then
run_control_test="1"
fi
fi
echo "Running HW control test => $run_control_test"
if [[ "$run_control_test" == "0" ]]; then
sleep 3600
exit
fi
fi
#------------------------------------------------------------------------------
# Build zyncore if needed
#------------------------------------------------------------------------------
if [[ ! -f "$ZYNTHIAN_DIR/zyncoder/build/libzyncore.so" ]]; then
splash_zynthian_message "Building zyncore. Please wait..."
$ZYNTHIAN_DIR/zyncoder/build.sh
fi
#------------------------------------------------------------------------------
# Detect first boot
#------------------------------------------------------------------------------
if [[ "$is_first_boot" == "1" ]]; then
echo "Running first boot..."
splash_zynthian_message "Configuring your zynthian. Time to relax before the waves..."
sleep 1800
splash_zynthian_error "It takes too long! Bad sdcard/image, poor power supply..."
sleep 3600000
exit
fi
#------------------------------------------------------------------------------
# Run Zynthian-UI
#------------------------------------------------------------------------------
splash_zynthian
while true; do
clean_zynthian_last_message
# Start Zynthian GUI & Synth Engine
cd $ZYNTHIAN_UI_DIR
./zynthian_main.py
status=$?
echo -e "\n*******************\nEXIT STATUS => $status\n*******************\n"
# Proccess output status
case $status in
0)
#splash_zynthian_message "Powering Off..."
splash_zynthian_last_message
poweroff
#backlight_control.sh off
break
;;
100)
#splash_zynthian_message "Rebooting..."
splash_zynthian_last_message
reboot
break
;;
101)
#splash_zynthian_message "Exiting..."
splash_zynthian_last_message
break
;;
102)
#splash_zynthian_message "Restarting UI..."
splash_zynthian_last_message
load_config_env
sleep 10
;;
*)
splash_zynthian_error_exit_ip $status
load_config_env
start_wifi_ap
sleep 10
;;
esac
done
#------------------------------------------------------------------------------