#!/bin/sh

lAudioTip=$1

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo $script_path

DOUBLELEDMODE=`cat $script_path/led.ini | ./busybox grep "DoubleLedMode:" | ./busybox grep -v grep | sed 's/DoubleLedMode://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
BLACKLEDMODE=`cat $script_path/led.ini | ./busybox grep "BlackLedMode:" | ./busybox grep -v grep | sed 's/BlackLedMode://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
if [ $? != 0 ]; then
	echo "cann't found led ini config file"
	exit -1
fi

DOUBLELIGHT_WHITELED_GROUP=`cat $script_path/led.ini | ./busybox grep "doubleLight_whiteLed_group:" | ./busybox grep -v grep | sed 's/doubleLight_whiteLed_group://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
DOUBLELIGHT_WHITELED_NUM=`cat $script_path/led.ini | ./busybox grep "doubleLight_whiteLed_num:" | ./busybox grep -v grep | sed 's/doubleLight_whiteLed_num://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
BLACKLIGHT_WHITELED_GROUP=`cat $script_path/led.ini | ./busybox grep "blackLight_whiteLed_group:" | ./busybox grep -v grep | sed 's/blackLight_whiteLed_group://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
BLACKLIGHT_WHITELED_NUM=`cat $script_path/led.ini | ./busybox grep "blackLight_whiteLed_num:" | ./busybox grep -v grep | sed 's/blackLight_whiteLed_num://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
BLACKLIGHT_SHIMMERLED_GROUP=`cat $script_path/led.ini | ./busybox grep "blackLight_shimmerLed_group:" | ./busybox grep -v grep | sed 's/blackLight_shimmerLed_group://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
BLACKLIGHT_SHIMMERLED_NUM=`cat $script_path/led.ini | ./busybox grep "blackLight_shimmerLed_num:" | ./busybox grep -v grep | sed 's/blackLight_shimmerLed_num://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

if [ "$lAudioTip" != "no" ];then
	./simple_adec_bind_ao -r 8000 -t g711a -i audio/ledTestStart.pcm
fi

if [ "$DOUBLELEDMODE" = "yes" ];then
	io -4 0x201A0040 0x000F0000
	io -4 0x20840008 0x00010001
	io -4 0x20840000 0x00010001
	sleep 2
	io -4 0x20840000 0x00010000
	sleep 2
	XmGpio sethigh "${DOUBLELIGHT_WHITELED_GROUP}" "${DOUBLELIGHT_WHITELED_NUM}"
	sleep 2
	XmGpio setlow "${DOUBLELIGHT_WHITELED_GROUP}" "${DOUBLELIGHT_WHITELED_NUM}"
fi

if [ "$BLACKLEDMODE" = "yes" ];then
	XmGpio sethigh "${BLACKLIGHT_WHITELED_GROUP}" "${BLACKLIGHT_WHITELED_NUM}"
	sleep 2
	XmGpio setlow "${BLACKLIGHT_WHITELED_GROUP}" "${BLACKLIGHT_WHITELED_NUM}"
	sleep 2
	XmGpio sethigh "${BLACKLIGHT_SHIMMERLED_GROUP}" "${BLACKLIGHT_SHIMMERLED_NUM}"
	sleep 2
	XmGpio setlow "${BLACKLIGHT_SHIMMERLED_GROUP}" "${BLACKLIGHT_SHIMMERLED_NUM}"
	
fi

if [ "$lAudioTip" != "no" ];then
	./simple_adec_bind_ao -r 8000 -t g711a -i audio/ledTestEnd.pcm
fi
