Page 1 of 1

temperature conversion in app

Posted: Tue Mar 12, 2013 6:08 am
by hikecraze
Ok I'm a total noob when it comes to the linux/debian/raspian"wheezy" file system and am in need of assistance. Yes I'm from the United States and most of us use the Imperial measuring system... and thats my problem.....you guys built a wonderfully stable Os with several helps for noobs like me and i love it. but i find it bothersome to have to do conversions in my head when it comes to the built in graphical cpu temp. I'm a codeing noob and can see where the sensor data is stored so i could take the time and reinvent the wheel as it were writing all new code and graphical interface for Ferinheight.....at my current skill level a 3 or more day project... not very productive. or could someone point me to the, i guess modual or subroutine? that takes the centigrade data and prints it on the gui interface. so that i can add my subroutines and switches to allow the added maths to be done or undone at the click of a mouse . ie
if butonA=true
then
tempdata=(tempraw)*9/5+32
print "(tempdata)F"
else
if butonA=false
then
print"(tempdata)C"
endif

or something like that...I'm still learning.....lol that's what the Pi is for. anyway I know Its a pain but I realy would appreciate some help and guidance thank you. btw if I were to rate my pc skill level as far as equating it ...... a mechanic I can fix anything on it ,but I'm trying to attach a NOS kit by reading the manual that came with the kit ......and that can be dangerous lol

Re: temperature conversion in app

Posted: Tue Mar 12, 2013 12:18 pm
by DBryant
You'd have no problem Googling the answer to this, but try the following but you'll have to install bc for the example below

Code: Select all

sudo apt-get install bc
Then try:

Code: Select all

#!/bin/bash

function c2F () {

  if [ "$1" != "" ]; then
     f=$(echo "scale=2; (32.0 + ( $1 * 9 / 5 ))" | bc)
  else
     f="Invalid #"
  fi

  echo $f
}

function f2C () {

  if [ "$1" != "" ]; then
     t=$(echo "scale=2;(( $1  - 32.00 ) * 5 / 9 )" | bc)
  else
     t="Invalid #"
  fi

  echo $t
}

for t in 0.0 -40 100.0; do
  printf "%6.2f> %s\n" "$t" "$(c2F $t)"
done 

for f in 32.0 -40.0 212.0; do
  printf "%6.2f> %s\n" "$f" "$(f2C $f)"
done 
gives

Code: Select all

  0.00> 32.00
-40.00> -40.00
100.00> 212.00
 32.00> 0
-40.00> -40.00
212.00> 100.00
I'll leave it to you to handle errors through mis-use!
Some bash tutorials are listed at http://ubuntuforums.org/showthread.php?t=1558206

Re: temperature conversion in app

Posted: Tue Mar 12, 2013 3:11 pm
by hikecraze
thankyou so so much! now off to learn, lol and tinker! lol