#!/bin/bash
#
# Get temperature only i.e. without hysterisis
# Order of output
#  current: low: high: crit:

while getopts ":n" opt; do
  case $opt in
    n)
      nl="true";;
    :)
      Usage "Option $OPTARG requires a value.";;
   \?)
      Usage "Unknown option $OPTARG.";;
  esac
done

Root=/sys/bus/i2c/drivers/lm77/0-0048
cd $Root
if [ $? -ne 0 ]; then
  echo "Error: Cannot change to directory $Root"
  exit 1
fi
if [ ! \( -f temp1_input -a -f temp1_min -a -f temp1_max -a -f temp1_crit \) ]; then
  echo "Error: Needed file missing in $Root"
  exit 1
fi

echo -n "current:$((`cat temp1_input`/1000))"
echo -n " low:$((`cat temp1_min`/1000))"
echo -n " high:$((`cat temp1_max`/1000))"
echo -n " critical:$((`cat temp1_crit`/1000))"
if [ -n "$nl" ]; then
  echo
fi
