Only show PWMs that are in the config
If we enable all the pwm from device tree, we should only
show the ones that are in the cofig to avoid confusion.
Tested-by: sensor list only showed pwms in the config
Change-Id: I9d3c1044045ee930b082ce2cbc4e55d33375b4d7
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 48ed692..0010ec5 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -92,6 +92,8 @@
return;
}
+ std::vector<uint8_t> pwmNumbers;
+
// iterate through all found fan sensors, and try to match them with
// configuration
for (const auto& path : paths)
@@ -269,9 +271,24 @@
path.string(), baseType, objectServer, dbusConnection,
std::move(presenceSensor), redundancy, io, sensorName,
std::move(sensorThresholds), *interfacePath, limits);
+
+ auto connector = sensorData->find(baseType + std::string(".Connector"));
+ if (connector != sensorData->end())
+ {
+ auto findPwm = connector->second.find("Pwm");
+ if (findPwm == connector->second.end())
+ {
+ std::cerr << "Connector Missing PWM!\n";
+ continue;
+ }
+
+ size_t pwm =
+ std::visit(VariantToUnsignedIntVisitor(), findPwm->second);
+ pwmNumbers.emplace_back(pwm);
+ }
}
std::vector<fs::path> pwms;
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwms))
+ if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+$)", pwms))
{
std::cerr << "No pwm in system\n";
return;
@@ -282,6 +299,21 @@
{
continue;
}
+ bool inConfig = false;
+ for (uint8_t index : pwmNumbers)
+ {
+ if (boost::ends_with(pwm.string(), std::to_string(index + 1)))
+ {
+ inConfig = true;
+ break;
+ }
+ }
+
+ if (!inConfig)
+ {
+ continue;
+ }
+
// only add new elements
pwmSensors.insert(std::pair<std::string, std::unique_ptr<PwmSensor>>(
pwm.string(),