#!/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"`
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"`
DOUBLELIGHT_IRLED_GROUP=`cat $script_path/led.ini | ./busybox grep "doubleLight_IRLed_group:" | ./busybox grep -v grep | sed 's/doubleLight_IRLed_group://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
DOUBLELIGHT_IRLED_NUM=`cat $script_path/led.ini | ./busybox grep "doubleLight_IRLed_num:" | ./busybox grep -v grep | sed 's/doubleLight_IRLed_num://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`


if [ "$lAudioTip" != "no" ];then
	./playOrRecord -p audio/ledTestStart.pcm -s 8000 -f 1
fi

if [ "$DOUBLELEDMODE" = "yes" ];then
	XmGpio sethigh "${DOUBLELIGHT_WHITELED_GROUP}" "${DOUBLELIGHT_WHITELED_NUM}"
	sleep 2
	XmGpio setlow "${DOUBLELIGHT_WHITELED_GROUP}" "${DOUBLELIGHT_WHITELED_NUM}"
	sleep 2
	XmGpio sethigh "${DOUBLELIGHT_IRLED_GROUP}" "${DOUBLELIGHT_IRLED_NUM}"
	sleep 2
	XmGpio setlow "${DOUBLELIGHT_IRLED_GROUP}" "${DOUBLELIGHT_IRLED_NUM}"
fi

if [ "$lAudioTip" != "no" ];then
	./playOrRecord -p audio/ledTestEnd.pcm -s 8000 -f 1
fi
