#!/bin/bash
#

printf "Trying to identify connected hardware using lsusb\n"
result=$(lsusb | grep -e "RR-CirKits LocoBuffer-USB")
if [ $? -eq 0 ]; then
  printf "Found LocoBuffer-USB\n"
  /home/pi/JMRI/PanelPro -p LocoBufferUSB.3e6f829c
  exit 0
fi
result=$(lsusb | grep -e "04d8:ff7e Microchip Technology, Inc.")
if [ $? -eq 0 ]; then
  printf "Found PR3 hardware\n"
  /home/pi/JMRI/PanelPro -p PR3.3f419377
  exit 0
fi
result=$(lsusb | grep -e "04d8:f91c Microchip Technology, Inc.")
if [ $? -eq 0 ]; then
  printf "Found SPROG IIv3 hardware\n"
  /home/pi/JMRI/PanelPro -p Sprog.3f366075
  exit 0
fi
result=$(lsusb | grep -e "04d8:fbb3 Microchip Technology, Inc.")
if [ $? -eq 0 ]; then
  printf "Found SPROG 3 hardware\n"
  /home/pi/JMRI/PanelPro -p Sprog.3f366075
  exit 0
fi
result=$(lsusb | grep -e "04d8:0721 Microchip Technology, Inc.")
if [ $? -eq 0 ]; then
  printf "Found LENZ USB hardware\n"
  /home/pi/JMRI/PanelPro -p LENZ_USB.3efdbd7f
  exit 0
fi
result=$(lsusb | grep -e "04d8:f80c Microchip Technology, Inc.")
if [ $? -eq 0 ]; then
  printf "Found MERG USB hardware\n"
  /home/pi/JMRI/PanelPro -p MERG_USB.3f66e424
  exit 0
fi
result=$(lsusb | grep -e "10c4:ea60")
if [ $? -eq 0 ]; then
  printf "Found NCE USB hardware\n"
  /home/pi/JMRI/PanelPro -p NCE_USB.3f722756
  exit 0
fi
result=$(lsusb | grep -e "2341:0042 Arduino")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "2341:0043 Arduino")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "1a86:7523 QinHeng Electronics")
if [ $? -eq 0 ]; then
  printf "Found DCC++ (ttyUSB0) hardware\n"
  /home/pi/JMRI/PanelPro -p DCC_ttyUSB0.3f18d91c
  exit 0
fi
result=$(lsusb | grep -e "2a03:0043")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "1b4f:8d21")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware (FireBox)\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "2886:800b")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware (SAMD21 Seeed Uno)\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "2341:804d")
if [ $? -eq 0 ]; then
  printf "Found DCC++ hardware (Arduino SA)\n"
  /home/pi/JMRI/PanelPro -p DCC.3f4cd52a
  exit 0
fi
result=$(lsusb | grep -e "0403:6001")
if [ $? -eq 0 ]; then
  printf "Found LocoBuffer-USB Rev n\n"
  /home/pi/JMRI/PanelPro -p LocoBufferUSB.3e6f829c
  exit 0
fi
result=$(lsusb | grep -e "0403:6015")
if [ $? -eq 0 ]; then
  printf "Found NCE Serial hardware\n"
  /home/pi/JMRI/PanelPro -p NCE_Serial.3f048691
  exit 0
fi
result=$(lsusb | grep -e "067b:2303")
if [ $? -eq 0 ]; then
  printf "Found NCE Serial hardware\n"
  /home/pi/JMRI/PanelPro -p NCE_Serial.3f048691
  exit 0
fi
result=$(lsusb | grep -e "FT232 USB-Serial (UART) IC")
if [ $? -eq 0 ]; then
  printf "Found NCE Serial hardware\n"
  /home/pi/JMRI/PanelPro -p NCE_Serial.3f048691
  exit 0
fi
result=$(lsusb | grep -e "04d8:000a")
if [ $? -eq 0 ]; then
  printf "Found LocoBuffer-NG hardware\n"
  /home/pi/JMRI/PanelPro -p LocoBuffer-NG.3e6f829d
  exit 0
fi
result=$(lsusb | grep -e "0483:5740")
if [ $? -eq 0 ]; then
  printf "Found LCC Buffer hardware\n"
  /home/pi/JMRI/PanelPro -p LCCBuffer-USB.3f66e424
  exit 0
fi
printf "No hardware recognized, starting with Digitrax Simulator\n"
/home/pi/JMRI/PanelPro -p Digitrax_Simulator.3f66e423
exit 0
