Skip to content

Instantly share code, notes, and snippets.

@hdclark
Created August 6, 2011 01:37
Show Gist options
  • Save hdclark/1128895 to your computer and use it in GitHub Desktop.
Save hdclark/1128895 to your computer and use it in GitHub Desktop.
ACPI Temperature echoer
// Compile with 'g++ <thisfile>.cc -o <you_choose_the_program_name_here>
//
// Use with xmobar/xmonad by inserting a line like so into your .xmobarrc.
//Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
// , bgColor = "black"
// , fgColor = "grey"
// , position = Top
// , lowerOnStart = True
// , commands = [ Run Weather "EGPF" ["-t","<station>: <tempC>C","-L","18","-H","25","--normal","green","--high","red","--low","lightblue"] 36000
// , Run Network "eth0" ["-L","0","-H","32","--normal","green","--high","red"] 10
// , Run Network "wlan0" ["-L","0","-H","32","--normal","green","--high","red"] 10
// , Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
// , Run Memory ["-t","Mem: <usedratio>%"] 10
// , Run Swap [] 10
// , Run Com "uname" ["-s","-r"] "" 36000
// --- \/ \/ \/ This line right here!! \/ \/ \/
// , Run CommandReader "/home/hal/.xmonad/Read_Temp" "temperature"
// , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10
// ]
// , sepChar = "%"
// , alignSep = "}{"
// , template = "%cpu% | %memory% * %swap% | %eth0% - %wlan0% }{ %temperature% <fc=#ee9a00>%date%</fc>| %EGPF% | %uname%"
// }
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <ctime>
#include <sstream>
template <class T>
T stringtoX(std::string text){
std::stringstream ss(text);
T temp;
ss >> temp;
return temp;
}
int main(int argc, char * argv[]){
//The current temperature file.
const std::string FilenameCurr("/sys/class/hwmon/hwmon0/temp1_input");
///sys/class/thermal/thermal_zone0/temp
//The critical temperature file.
const std::string FilenameCrit("/sys/class/hwmon/hwmon0/temp1_crit");
///sys/class/thermal/thermal_zone0/temp_....?....trip
float tempA, tempB;
std::fstream FI;
std::string strbuffer;
//The current temperature file.
FI.open(FilenameCurr.c_str(), std::ifstream::in);
FI.close();
if( !FI.good() ) return 1;
FI.clear();
//The critical temperature file.
FI.open(FilenameCrit.c_str(), std::ifstream::in);
FI.close();
if( !FI.good() ) return 1;
FI.clear();
while(true){
FI.open(FilenameCurr.c_str(), std::ifstream::in);
getline(FI,strbuffer);
tempA = stringtoX<float>( strbuffer );
FI.close();
FI.open(FilenameCrit.c_str(), std::ifstream::in);
getline(FI,strbuffer);
tempB = stringtoX<float>( strbuffer );
FI.close();
//Scale milli-Celcius to Celcius.
tempA *= 0.001;
tempB *= 0.001;
if(tempA >= 90.0){
system("killall mplayer; killall globe");
std::cout << "THERMAL PRECAUTIONS! ";
}
std::cout << tempA << "/" << tempB << " C" << std::endl;
std::cout.flush();
usleep(1000000);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment