#
# Funktion-Libs einbinden
#
. /usr/bin/easyvdr/functions/easyvdr_m2n_functions

IMONDRIVER="lirc_imon"

function EditConfig() {
   if [ ! -f /etc/LCDd.conf.org ]; then
      cp /etc/LCDd.conf /etc/LCDd.conf.org
   fi

   cp /etc/LCDd.conf.antecv2 /etc/LCDd.conf
   ##### udev Änderung wegen fehlendem /dev/lcd0 #####
   FILE="/etc/udev/rules.d/10-lcd.rules"
   BACKUP="/media/backup/10-lcd.rules.`date +%Y%m%d%H%M`"
   cp $FILE $BACKUP

   if [ $(grep -w -e '^BUS=="usb" KERNEL=="lcd?"' $FILE &>/dev/null; echo $?) = "1"  ]; then
      sed -i '1iBUS=="usb" KERNEL=="lcd?", NAME="%k", SYMLINK+="lcd0"' $FILE
   else
      sed -i '/^BUS=="usb" KERNEL=="lcd?"*/ c\BUS=="usb" KERNEL=="lcd?", NAME="%k", SYMLINK+="lcd0"' $FILE
   fi

   FILE="/etc/init.d/RCStartBeforVDR.d/RCStartPersonal"
   if [ $(grep -w -e "^modprobe $IMONDRIVER" $FILE &>/dev/null; echo $?) = "1"  ]; then
      echo "modprobe $IMONDRIVER"	>> $FILE
   fi

   FILE="/etc/init.d/RCShutdown.d/RCShutdownPersonal1"
   if [ $(grep -w -e "^killall LCDd" $FILE &>/dev/null; echo $?) = "1"  ]; then
      echo "killall LCDd"		>> $FILE
      echo "sleep 1"			>> $FILE
      echo "echo -n \" \" > /dev/lcd0"	>> $FILE
   fi

   SetSysconfig LCD	"lcdproc"
   SetSysconfig LIRC	"imon"
}

function StartImon() {
  modprobe $IMONDRIVER
  sleep 2
}
############################################# aus imon_vfd.c
#         { USB_DEVICE(0x0aa8, 0xffda) },         /* IR & VFD    */  #####                            ungetestet
#	  { USB_DEVICE(0x15c2, 0xffda) },         /* IR & VFD    */  #####                            ungetestet
#	  { USB_DEVICE(0x15c2, 0xffdc) },         /* IR & VFD    */  ##### Antec Fusion V2 silber VFD   getestet
#
function IsImonVFD ()
{
  chk_lsusb "15c2:ffdc" || \
  chk_lsusb "15c2:ffda" || \
  chk_lsusb "0aa8:ffda"

  return $?
}

function main() {
   stop_vdr

   IsImonVFD
   if [ $? -eq 0  ]; then
      echo "--->Richte ImonVFD ein"
      EditConfig
      StartImon
   else
      echo "--->Kein ImonVFD gefunden"
   fi

   start_vdr
}

main
