Ticket #3502: sensors.diff
File sensors.diff, 12.9 KB (added by , 17 years ago) |
---|
-
libs/libmyth/util.cpp
32 32 #include <qpainter.h> 33 33 #include <qpixmap.h> 34 34 #include <qfont.h> 35 #include <qdir.h> 36 #include <qstringlist.h> 37 #include <qregexp.h> 35 38 36 39 // Myth headers 37 40 #include "mythconfig.h" … … 52 55 #include "jsmenuevent.h" 53 56 #endif 54 57 58 // lmsensors headers 59 #include "../../config.h" 60 #ifdef HAVE_LMSENSORS 61 #define LMSENSOR_DEFAULT_CONFIG_FILE "/etc/sensors.conf" 62 #include <sensors/sensors.h> 63 #include <sensors/chips.h> 64 #endif 65 55 66 /** \fn mythCurrentDateTime() 56 67 * \brief Returns the current QDateTime object, stripped of its msec component 57 68 */ … … 528 539 #endif 529 540 } 530 541 } 542 543 /** \fn get_acpi_cputemp(void) 544 * \brief Returns the current ACPI cpu temperature or an empty string on error. 545 */ 546 QString get_acpi_cputemp(void) 547 { 548 QString ret_value = ""; 549 QDir dir("/proc/acpi/thermal_zone"); 550 QString acpiTempDir; 551 if(dir.exists()) 552 { 553 QStringList lst = dir.entryList(); 554 QRegExp rxp = QRegExp ("TH?M?", TRUE, FALSE); 555 QString line, temp; 556 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) 557 { 558 if ( (*it).contains(rxp)) 559 { 560 acpiTempDir=dir.absFilePath(*it); 561 } 562 } 563 564 QFile acpiTempFile(acpiTempDir.append("/temperature")); 565 if (acpiTempFile.open(IO_ReadOnly)) 566 { 567 QTextStream stream (&acpiTempFile); 568 line = stream.readLine(); 569 rxp = QRegExp ("(\\d+)", TRUE, FALSE); 570 if (rxp.search(line) != -1 ) 571 { 572 ret_value=rxp.cap(1); 573 } 574 } 575 acpiTempFile.close(); 576 } 577 return ret_value; 578 } 579 580 /** \fn get_lms_sensordata(QString sensor_name) 581 * \brief Returns the value of an lmsensor witch's label matches sensor_name. 582 * 583 * sensor_name is regexped against all available sensor labels 584 * and the first match's value is returned. If none is found, 585 * an empty string is returned. 586 */ 587 QString get_lms_sensordata(QString sensor_name) 588 { 589 QString sensor_value = ""; 590 591 #ifdef HAVE_LMSENSORS 592 int chip_nr, a, b; 593 char *label = NULL; 594 double value; 595 const sensors_chip_name *chip; 596 const sensors_feature_data *data; 597 char* lmsensorConfigName = LMSENSOR_DEFAULT_CONFIG_FILE; 598 a = b = 0; 599 FILE *lmsensorConfigFile = fopen(lmsensorConfigName, "r"); 600 sensors_init(lmsensorConfigFile); 601 fclose(lmsensorConfigFile); 602 bool found = 0; 603 for (chip_nr = 0 ; (chip = sensors_get_detected_chips(&chip_nr)) && !found ; ) 604 { 605 while ((data = sensors_get_all_features(*chip, &a, &b)) && !found) 606 { 607 if ((!sensors_get_label(*chip, data->number, &label)) && 608 (!sensors_get_feature(*chip, data->number, &value))) 609 { 610 QRegExp rxp = QRegExp (sensor_name, FALSE, FALSE); 611 if (rxp.search(QString(label)) != -1) 612 { 613 sensor_value = QString("%1").arg(value); 614 found = 1; 615 } 616 617 } 618 } 619 } 620 sensors_cleanup(); 621 #endif 622 623 return sensor_value; 624 } 625 626 /** \fn QString get_cputemp(void) 627 * \brief Returns the current cpu temperature. 628 * 629 * Will try to get lmsensors cpu temperature first. 630 * If not possible, will try to get acpi cpu temperature. 631 * If both fails, returns an empty string. 632 */ 633 QString get_cputemp(void) 634 { 635 QString ret_value = ""; 636 637 #ifdef HAVE_LMSENSORS 638 ret_value = get_lms_sensordata("(CPU.+Temp)|(Temp.+CPU)"); 639 #endif 640 641 if(ret_value == "") 642 { 643 ret_value = get_acpi_cputemp(); 644 } 645 646 return ret_value; 647 } 648 649 /** \fn QString get_mbtemp(void) 650 * \brief Returns the current motherboard temperature. 651 * 652 * On error, returns an empty string. 653 */ 654 QString get_mbtemp(void) 655 { 656 QString ret_value = ""; 657 658 #ifdef HAVE_LMSENSORS 659 ret_value = get_lms_sensordata("M/B.+Temp"); 660 #endif 661 662 return ret_value; 663 } 664 665 /** \fn QString get_cpufanspeed(void) 666 * \brief Returns the current cpu fanspeed. 667 * 668 * On error, returns an empty string. 669 */ 670 QString get_cpufanspeed(void) 671 { 672 QString ret_value = ""; 673 674 #ifdef HAVE_LMSENSORS 675 ret_value = get_lms_sensordata("CPU.+Fan"); 676 #endif 677 678 return ret_value; 679 } -
libs/libmyth/util.h
67 67 68 68 MPUBLIC void myth_eject(void); 69 69 70 MPUBLIC QString get_acpi_cputemp(void); 71 MPUBLIC QString get_lms_sensordata(QString sensor_name); 72 MPUBLIC QString get_cputemp(void); 73 MPUBLIC QString get_mbtemp(void); 74 MPUBLIC QString get_cpufanspeed(void); 75 70 76 #endif // UTIL_H_ -
libs/libmyth/libmyth.pro
178 178 SOURCES += DisplayResX.cpp 179 179 } 180 180 181 using_lmsensors { 182 LIBS += -lsensors 183 } 184 181 185 contains( TARGET_MMX, yes ) { 182 186 HEADERS += ../../libs/libavcodec/i386/mmx.h ../../libs/libavcodec/dsputil.h 183 187 } -
programs/mythfrontend/statusbox.cpp
3 3 #include <qsqldatabase.h> 4 4 #include <qwidgetstack.h> 5 5 #include <qvbox.h> 6 #include <qdir.h> 6 7 #include <qgrid.h> 7 8 #include <qregexp.h> 8 9 #include <qhostaddress.h> … … 24 25 #include "mythdbcon.h" 25 26 #include "cardutil.h" 26 27 28 #include "libmyth/util.h" 29 27 30 #define REC_CAN_BE_DELETED(rec) \ 28 31 ((((rec)->programflags & FL_INUSEPLAYING) == 0) && \ 29 32 ((((rec)->programflags & FL_INUSERECORDING) == 0) || \ … … 1500 1503 detailString = ""; 1501 1504 } 1502 1505 1506 // Hardware Monitor ----------------- 1507 1508 QString cputemp = get_cputemp(); 1509 QString cpufanspeed = get_cpufanspeed(); 1510 QString mbtemp = get_mbtemp(); 1511 1512 if(cputemp != "") 1513 { 1514 contentLines[count] = QObject::tr("Harware Monitor:"); 1515 detailString += contentLines[count] + "\n"; 1516 count++; 1517 1518 contentLines[count] = QObject::tr(" Current CPU temperature: "+cputemp+" °C"); 1519 detailString += contentLines[count] + "\n"; 1520 count++; 1521 1522 if(cpufanspeed != "") 1523 { 1524 contentLines[count] = QObject::tr(" Current CPU fan speed: "+cpufanspeed+" RPM"); 1525 detailString += contentLines[count] + "\n"; 1526 count++; 1527 } 1528 1529 if(mbtemp != "") 1530 { 1531 contentLines[count] = QObject::tr(" Current motherboard temperature: "+mbtemp+" °C"); 1532 detailString += contentLines[count] + "\n"; 1533 count++; 1534 } 1535 1536 for (detailLoop = detailBegin; detailLoop < count; detailLoop++) 1537 contentDetail[detailLoop] = detailString; 1538 1539 detailBegin = count; 1540 detailString = ""; 1541 } 1542 1503 1543 contentTotalLines = count; 1504 1544 update(ContentRect); 1505 1545 } -
programs/mythbackend/mythbackend.pro
33 33 using_dvb:DEFINES += USING_DVB 34 34 35 35 using_valgrind:DEFINES += USING_VALGRIND 36 37 using_lmsensors:LIBS += -lsensors -
programs/mythbackend/httpstatus.cpp
4 4 // Purpose - Html & XML status HttpServerExtension 5 5 // 6 6 // Created By : David Blain Created On : Oct. 24, 2005 7 // Modified By : Modified On:7 // Modified By : Pinguin Modified On: Jun. 05, 2007 8 8 // 9 9 ////////////////////////////////////////////////////////////////////////////// 10 10 … … 23 23 #include <qbuffer.h> 24 24 #include <math.h> 25 25 26 #include "../../config.h"27 #ifdef HAVE_LMSENSORS28 #define LMSENSOR_DEFAULT_CONFIG_FILE "/etc/sensors.conf"29 #include <sensors/sensors.h>30 #include <sensors/chips.h>31 #endif32 26 33 27 ///////////////////////////////////////////////////////////////////////////// 34 28 // … … 369 363 } 370 364 371 365 372 //temperature ----------------- 373 // Try ACPI first, then lmsensor 2nd 374 QDir dir("/proc/acpi/thermal_zone"); 375 bool found_acpi = false; 376 QString acpiTempDir; 377 if (dir.exists()) 366 // Hardware Monitor ----------------- 367 368 QString cputemp = get_cputemp(); 369 QString cpufanspeed = get_cpufanspeed(); 370 QString mbtemp = get_mbtemp(); 371 372 if(cputemp != "") 378 373 { 379 QStringList lst = dir.entryList(); 380 QRegExp rxp = QRegExp ("TH?M?", TRUE, FALSE); 381 QString line, temp; 382 for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) 383 { 384 if ( (*it).contains(rxp)) 385 { 386 acpiTempDir = dir.absFilePath(*it); 387 } 388 } 374 mInfo.appendChild(thermal); 375 thermal.setAttribute("cputemp", cputemp); 376 thermal.setAttribute("cpufanspeed", cpufanspeed); 377 thermal.setAttribute("mbtemp", mbtemp); 378 } 389 379 390 QFile acpiTempFile(acpiTempDir.append("/temperature"));391 if (acpiTempFile.open(IO_ReadOnly))392 {393 QTextStream stream (&acpiTempFile);394 line = stream.readLine();395 rxp = QRegExp ("(\\d+)", TRUE, FALSE);396 if (rxp.search(line) != -1 )397 {398 temp = rxp.cap(1);399 temp += " ℃"; // print degress Celsius400 mInfo.appendChild(thermal);401 thermal.setAttribute("temperature", temp);402 found_acpi = true;403 }404 }405 acpiTempFile.close();406 }407 408 #ifdef HAVE_LMSENSORS409 m_settingLock.lock();410 411 if (!found_acpi)412 {413 int chip_nr, a, b;414 char *label = NULL;415 double value;416 const sensors_chip_name *chip;417 const sensors_feature_data *data;418 char* lmsensorConfigName = LMSENSOR_DEFAULT_CONFIG_FILE;419 a = b = 0;420 FILE *lmsensorConfigFile = fopen(lmsensorConfigName, "r");421 sensors_init(lmsensorConfigFile);422 fclose(lmsensorConfigFile);423 for (chip_nr = 0 ; (chip = sensors_get_detected_chips(&chip_nr)) ; )424 {425 while ((data = sensors_get_all_features(*chip, &a, &b)))426 {427 if ((!sensors_get_label(*chip, data->number, &label)) &&428 (!sensors_get_feature(*chip, data->number, &value)))429 {430 // Find label matching "CPU Temp" or "Temp/CPU"431 QRegExp rxp = QRegExp ("(CPU.+Temp)|(Temp.+CPU)", FALSE, FALSE);432 if (rxp.search(QString(label)) != -1 && value > 0)433 {434 QString temp = QString("%1").arg(value);435 temp += " ℃";436 mInfo.appendChild(thermal);437 thermal.setAttribute("temperature", temp);438 }439 }440 }441 }442 sensors_cleanup();443 }444 m_settingLock.unlock();445 #endif446 447 380 // Guide Data --------------------- 448 381 449 382 QDateTime GuideDataThrough; … … 1151 1084 } 1152 1085 } 1153 1086 1154 // ACPI temperature------------------1087 // Hardware Monitor ------------------ 1155 1088 1156 1089 node = info.namedItem( "Thermal" ); 1157 1090 … … 1161 1094 1162 1095 if (!e.isNull()) 1163 1096 { 1164 QString temperature = e.attribute( "temperature" , "0" ); 1097 QString cpu_temp = e.attribute("cputemp","0"); 1098 QString cpu_fan_speed = e.attribute("cpufanspeed",""); 1099 QString mb_temp = e.attribute("mbtemp",""); 1165 1100 1166 os << " Current CPU temperature: " 1167 << temperature 1168 << ".<br />\r\n"; 1101 os << " Hardware Monitor:<br />\r\n"; 1102 os << " <ul>\r\n"; 1103 os << " <li>Current CPU temperature: " << cpu_temp << " °C</li>\r\n"; 1104 1105 if(cpu_fan_speed != "") 1106 { 1107 os << " <li>Current CPU fan speed: " << cpu_fan_speed << " RPM</li>\r\n"; 1108 } 1109 1110 if(mb_temp != "") 1111 { 1112 os << " <li>Current motherboard temperature: " << mb_temp << " °C</li>\r\n"; 1113 } 1114 1115 os << " </ul>\r\n"; 1169 1116 } 1170 1117 } 1171 1118