Merge branch 'aristocratos:main' into battery-power-2

This commit is contained in:
vsey 2023-12-17 21:19:39 +01:00 committed by GitHub
commit 5792216eb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -16,6 +16,7 @@ indent = tab
tab-size = 4 tab-size = 4
*/ */
#include <Availability.h>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -56,7 +57,9 @@ tab-size = 4
#include "../btop_shared.hpp" #include "../btop_shared.hpp"
#include "../btop_tools.hpp" #include "../btop_tools.hpp"
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
#include "sensors.hpp" #include "sensors.hpp"
#endif
#include "smc.hpp" #include "smc.hpp"
using std::clamp, std::string_literals::operator""s, std::cmp_equal, std::cmp_less, std::cmp_greater; using std::clamp, std::string_literals::operator""s, std::cmp_equal, std::cmp_less, std::cmp_greater;
@ -250,6 +253,7 @@ namespace Cpu {
Logger::debug("get_sensors(): show_coretemp=" + std::to_string(Config::getB("show_coretemp")) + " check_temp=" + std::to_string(Config::getB("check_temp"))); Logger::debug("get_sensors(): show_coretemp=" + std::to_string(Config::getB("show_coretemp")) + " check_temp=" + std::to_string(Config::getB("check_temp")));
got_sensors = false; got_sensors = false;
if (Config::getB("show_coretemp") and Config::getB("check_temp")) { if (Config::getB("show_coretemp") and Config::getB("check_temp")) {
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
ThermalSensors sensors; ThermalSensors sensors;
if (sensors.getSensors() > 0) { if (sensors.getSensors() > 0) {
Logger::debug("M1 sensors found"); Logger::debug("M1 sensors found");
@ -257,6 +261,7 @@ namespace Cpu {
cpu_temp_only = true; cpu_temp_only = true;
macM1 = true; macM1 = true;
} else { } else {
#endif
// try SMC (intel) // try SMC (intel)
Logger::debug("checking intel"); Logger::debug("checking intel");
SMCConnection smcCon; SMCConnection smcCon;
@ -281,7 +286,9 @@ namespace Cpu {
// ignore, we don't have temp // ignore, we don't have temp
got_sensors = false; got_sensors = false;
} }
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
} }
#endif
} }
return got_sensors; return got_sensors;
} }
@ -290,11 +297,12 @@ namespace Cpu {
current_cpu.temp_max = 95; // we have no idea how to get the critical temp current_cpu.temp_max = 95; // we have no idea how to get the critical temp
try { try {
if (macM1) { if (macM1) {
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
ThermalSensors sensors; ThermalSensors sensors;
current_cpu.temp.at(0).push_back(sensors.getSensors()); current_cpu.temp.at(0).push_back(sensors.getSensors());
if (current_cpu.temp.at(0).size() > 20) if (current_cpu.temp.at(0).size() > 20)
current_cpu.temp.at(0).pop_front(); current_cpu.temp.at(0).pop_front();
#endif
} else { } else {
SMCConnection smcCon; SMCConnection smcCon;
int threadsPerCore = Shared::coreCount / Shared::physicalCoreCount; int threadsPerCore = Shared::coreCount / Shared::physicalCoreCount;

View file

@ -16,6 +16,8 @@ indent = tab
tab-size = 4 tab-size = 4
*/ */
#include <Availability.h>
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
#include "sensors.hpp" #include "sensors.hpp"
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
@ -109,3 +111,4 @@ long long Cpu::ThermalSensors::getSensors() {
if (temps.empty()) return 0ll; if (temps.empty()) return 0ll;
return round(std::accumulate(temps.begin(), temps.end(), 0ll) / temps.size()); return round(std::accumulate(temps.begin(), temps.end(), 0ll) / temps.size());
} }
#endif

View file

@ -16,9 +16,12 @@ indent = tab
tab-size = 4 tab-size = 4
*/ */
#include <Availability.h>
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101504
namespace Cpu { namespace Cpu {
class ThermalSensors { class ThermalSensors {
public: public:
long long getSensors(); long long getSensors();
}; };
} // namespace Cpu } // namespace Cpu
#endif