#!/bin/sh
case "$1" in
  'start')
	lfocus_stat=$(ps ax | grep -v grep | grep lfocus.py | awk 'NR==1 {print $1}')
  	while  [ $lfocus_stat > /dev/null ]
	do
		kill $lfocus_stat
		lfocus_stat=$(ps ax | grep -v grep | grep lfocus.py | awk 'NR==1 {print $1}')
	done
	python /opt/lfocus/lfocus.py
	;;
  'stop')
	lfocus_stat=$(ps ax | grep -v grep | grep lfocus.py | awk 'NR==1 {print $1}')
  	while  [ $lfocus_stat > /dev/null ]
	do
		kill $lfocus_stat
		lfocus_stat=$(ps ax | grep -v grep | grep lfocus.py | awk 'NR==1 {print $1}')
	done
	;;
  'start_stop_focus')
	lfocus_stat=$(ps ax | grep -v grep | grep stop_focus.py | awk 'NR==1 {print $1}')
  	while  [ $lfocus_stat > /dev/null ]
	do
		kill $lfocus_stat
		lfocus_stat=$(ps ax | grep -v grep | grep stop_focus.py | awk 'NR==1 {print $1}')
	done
	python /opt/lfocus/stop_focus.py
	;;
  'stop_stop_focus')
	lfocus_stat=$(ps ax | grep -v grep | grep stop_focus.py | awk 'NR==1 {print $1}')
  	while  [ $lfocus_stat > /dev/null ]
	do
		kill $lfocus_stat
		lfocus_stat=$(ps ax | grep -v grep | grep stop_focus.py | awk 'NR==1 {print $1}')
	done
	;;
  'start_capture')
	python /opt/lfocus/stop_focus.py start
	;;
  'start_proximity')
	echo -n 0 > /sys/devices/platform/gpio-switch/proximity/disable 
	;;
  'stop_proximity')
	echo -n 1 > /sys/devices/platform/gpio-switch/proximity/disable 
	;;
  *)
	echo "Usage: $SELF start|stop|start_stop_focus|stop_stop_focus|start_capture|start_proximity|stop_proximity"
	exit 1
	;;
esac
exit 0
