1#!/bin/bash
2
3# defines
4DIR="/sys/devices/virtual/thermal"
5
6# helper function
7direxists() {
8  [ `adb shell "[ -d $1 ] && echo found"` ]
9}
10fileexists() {
11  [ `adb shell "[ -f $1 ] && echo found"` ]
12}
13getprop() {
14  if fileexists $1; then
15    echo "`adb shell cat $1 | tr -d '\r'`"
16  else
17    echo "FILE $1 NOT FOUND"
18  fi
19}
20print_if_exists() {
21  if fileexists $1; then
22    local ERROR=`getprop $1 | grep "Invalid"`
23    if [ ${#ERROR} -eq 0 ]; then
24      eval "$2=`getprop $1`"
25    else
26      eval "$2=ERROR"
27    fi
28  else
29    eval "$2=DNE"
30  fi
31}
32
33# setup
34if [[ "`adb shell id | tr -d '\r' | awk -F'[()]' '{print $2}'`" != "root" ]]; then
35  adb root
36  adb wait-for-device
37fi
38
39# device name
40echo Device: `adb shell getprop ro.product.model`
41
42# get zones
43ZONES=`adb shell ls $DIR | tr -d '\r' | grep thermal_zone | tr -d thermal_zone | sort -n`
44
45# print temperature of each zone
46for ZONE in $ZONES; do
47  print_if_exists $DIR"/thermal_zone"$ZONE"/mode" MODE
48  print_if_exists $DIR"/thermal_zone"$ZONE"/temp" TEMP
49  print_if_exists $DIR"/thermal_zone"$ZONE"/type" TYPE
50  printf "Zone %02d:   MODE=%-8s   TEMP=%-5s   TYPE=%s\n" $ZONE $MODE $TEMP $TYPE
51done
52
53# error
54if ! direxists $DIR; then
55  echo "Thermal directory not found"
56fi
57
58