#!/bin/bash

killall evtest 2> /dev/null

device=$1

if [ -f "/opt/pos/common/addons/read_usb_keys/etc/device" ]; then
  device=`cat /opt/pos/common/addons/read_usb_keys/etc/device`
fi

if [ "$device" != "" ]; then
  echo "$device" > /opt/pos/common/addons/read_usb_keys/etc/device

  ps xa | grep process_keys | grep -v grep | awk '{ print $1 }' | xargs kill -9 2> /dev/null

  while [ true ]; do
    evtest /dev/input/by-id/$device | /opt/pos/common/addons/read_usb_keys/bin/process_keys.pl
    sleep 5
  done

else

  for device in `ls /dev/input/by-id`; do
    echo "DEVICE: $device"
  done

fi

