#!/bin/sh
test_sd () {
	local i=NG y=0
	glcdd asc:0:$y:2:0:3:SD fls:
	test-sd 30 && i=OK
	glcdd asc:36:$y:2:0:3:$i fls:
}
test_ether () {
	local i=NG y=10
	glcdd asc:0:$y:2:0:3:Ether fls:
	test-ether 30 && i=OK
	glcdd asc:36:$y:2:0:3:$i fls:
}
test_wifi () {
	local i=NG y=20
	glcdd asc:0:$y:2:0:3:Wi-Fi fls:
	test-ether 30 ra0 ub300-test ub300-test && i=OK
	glcdd asc:36:$y:2:0:3:$i fls:
}
test_hdmi () {
	local e=1 y=30
	glcdd asc:0:$y:2:0:3:HDMI fls:
	if simple-switch /usr/local/share/font32.bin 2> /dev/null; then
		i=OK; e=0
	fi
	glcdd asc:36:$y:2:0:3:$i fls:
	return $e
}

glcdd fst:1 fil:169:0:23:11:1 asc:170:1:2:0:2:TEST fls:
ub300key -wheel | ( while read k i; do [ $k -eq 32 ] && break; done)
if ! test-lcd 0 || ! test-lcd 1 || ! test-lcd 2 || ! test-wheel; then
	glcdd cls: asc:0:50:2:0:3:'Test failed!' fls:
	exit 1
fi
e=1
while [ $e != 0 ]; do
	glcdd cls: fil:169:0:23:11:1 asc:170:1:2:0:2:TEST fls:
	test_sd &
	test_ether &
	test_wifi &
	if test_hdmi; then
		e=0
		glcdd asc:0:50:2:0:3:Congratulations! fls:
	fi
	killall test-sd
	killall test-ether udhcpc
	wait
done
exit $e
