Advertisement
Guest User

temp-daemon.sh

a guest
Oct 23rd, 2014
1,360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # SoC/HDD temperature daemon. Writes the current temperatures to
  4. # /run/soc-temp and /run/hdd-temp (since we're experiencing always
  5. # timeouts under heavy load when trying to get the temperatures
  6. # directly from within RPi-Monitor.
  7.  
  8. Main() {
  9. # SoCTempAdjustment is needed because the A20 SoC delivers uncalibrated temp values
  10. SoCTempAdjustment=1447
  11.  
  12. # ensure module sunxi-dbgreg.ko is loaded
  13. grep -q sunxi_dbgreg </proc/modules || ( modprobe sunxi-dbgreg ; sleep 0.1 )
  14.  
  15. # prepare registers
  16. echo 'f1c25000:27003f' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  17. echo 'f1c25010:40000' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  18. echo 'f1c25018:10fff' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  19. echo 'f1c25004:10' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  20.  
  21. while [ 2 -ge 1 ]; do
  22. # let the value be written to syslog
  23. echo 'f1c25020' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/read;
  24.  
  25. # wait 0.1 seconds
  26. sleep 0.1
  27.  
  28. # read return value from syslog and transform it into degrees Celsius
  29. HexVal=$(tail /var/log/syslog | awk -F" 0x" '/ 0x/ {print $2}' | tail -n1 )
  30. SoCTemp=$(echo $(( 0x${HexVal} - ${SoCTempAdjustment} )) | awk '{printf ("%0.1f",$1/10); }')
  31. if [ "X${SoCTemp}" != "X" ]; then
  32. echo -n ${SoCTemp} >/run/soc-temp
  33. fi
  34.  
  35. # HDD/SSD temp
  36. DiskTemp=$(hddtemp -n /dev/sda)
  37. if [ "X${DiskTemp}" != "X" ]; then
  38. echo -n ${DiskTemp} >/run/hdd-temp
  39. fi
  40.  
  41. # sleep 5 secs
  42. sleep 5
  43. done
  44. } # Main
  45.  
  46. Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement