Skip to content

Commit

Permalink
Introduce valid limits for temperature sensors (arm)
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Aug 28, 2023
1 parent 6c3a650 commit 510e806
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions smctemp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/sysctl.h>
#include <algorithm>
#include <array>
#include <utility>

namespace {
std::string getCPUModel() {
Expand Down Expand Up @@ -407,6 +408,7 @@ double SmcTemp::GetCpuTemp() {
#elif defined(ARCH_TYPE_ARM64)
std::vector<std::string> sensors;
std::vector<std::string> aux_sensors;
const std::pair<unsigned int, unsigned int> valid_temperature_limits{10, 120};

const std::string cpumodel = getCPUModel();
if (cpumodel.find("m2") != std::string::npos) { // Apple M2
Expand Down Expand Up @@ -460,7 +462,7 @@ double SmcTemp::GetCpuTemp() {
size_t valid_sensor_count = 0;
for (auto sensor : sensors) {
auto sensor_value = smc_accessor_.ReadValue(sensor.c_str());
if (sensor_value > 0.0) {
if (sensor_value >= valid_temperature_limits.first && sensor_value <= valid_temperature_limits.second) {
temp += sensor_value;
valid_sensor_count++;
}
Expand All @@ -473,7 +475,7 @@ double SmcTemp::GetCpuTemp() {
size_t valid_aux_sensor_count = 0;
for (auto sensor : aux_sensors) {
auto sensor_value = smc_accessor_.ReadValue(sensor.c_str());
if (sensor_value > 0.0) {
if (sensor_value > valid_temperature_limits.first && sensor_value < valid_temperature_limits.second) {
temp += sensor_value;
valid_aux_sensor_count++;
}
Expand Down

0 comments on commit 510e806

Please sign in to comment.