From 52c34ee61a1c292f1226cc61a10dd90e611e6d63 Mon Sep 17 00:00:00 2001 From: Raptor Engineering Development Team Date: Mon, 15 Jan 2018 19:21:39 -0600 Subject: Enable raw PWM control mode for systems without known fan types --- fan_speed.cpp | 33 +++++++++++++++++++++++++++++++-- hwmon.hpp | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fan_speed.cpp b/fan_speed.cpp index 65e5655..c6a9162 100644 --- a/fan_speed.cpp +++ b/fan_speed.cpp @@ -16,15 +16,44 @@ namespace hwmon uint64_t FanSpeed::target(uint64_t value) { + auto directPWM = false; auto curValue = FanSpeedObject::target(); + auto enable = env::getEnv("ENABLE", _type, _id); + if (!enable.empty()) + { + auto val = std::stoul(enable); + if (val == 1) + { + directPWM = true; + } + } if (curValue != value) { // Write target out to sysfs try { - _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries, - hwmonio::delay); + if (directPWM) + { + _ioAccess->write( + (value * 255) / 100, + type::pwm, + _id, + entry::rawpwm, + hwmonio::retries, + hwmonio::delay); + } + else + { + _ioAccess->write( + value, + _type, + _id, + entry::target, + hwmonio::retries, + hwmonio::delay); + } + } catch (const std::system_error& e) { diff --git a/hwmon.hpp b/hwmon.hpp index 4f4545c..6f85f5c 100644 --- a/hwmon.hpp +++ b/hwmon.hpp @@ -14,12 +14,14 @@ static constexpr auto clabel = "label"; static constexpr auto ctarget = "target"; static constexpr auto cenable = "enable"; static constexpr auto cfault = "fault"; +static constexpr auto crawpwm = ""; static const std::string input = cinput; static const std::string label = clabel; static const std::string target = ctarget; static const std::string enable = cenable; static const std::string fault = cfault; +static const std::string rawpwm = crawpwm; } // namespace entry namespace type -- cgit v1.2.1