blob: 43efe0e4e231075f8c77a9f1d472858991f74d84 [file] [log] [blame]
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "thermald/hwmon_temperature_sensor.h"
#include <string>
#include "base/check.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
using std::stoi;
using std::string;
namespace thermald {
HwmonTemperatureSensor::HwmonTemperatureSensor(int hwmon_dev_id, int sensor_id,
const std::string &name)
: TemperatureSensorCommon(name),
sysfs_attr_input_(base::StringPrintf(
"/sys/class/hwmon/hwmon%d/temp%d_input", hwmon_dev_id, sensor_id)) {
}
HwmonTemperatureSensor::HwmonTemperatureSensor(int hwmon_dev_id,
int sensor_id)
: HwmonTemperatureSensor(hwmon_dev_id, sensor_id,
base::StringPrintf("hwmon%d.temp%d", hwmon_dev_id,
sensor_id)) {
}
bool HwmonTemperatureSensor::ReadTemperature(int *value) {
DCHECK(value);
string contents;
if (!base::ReadFileToString(sysfs_attr_input_, &contents)) {
LOG(ERROR) << "[" << name() << "] Failed to read '"
<< sysfs_attr_input_.value() << "'";
return false;
}
*value = stoi(contents);
return true;
}
} // namespace thermald