FanSensor: Add initial of pwm enable file

  For some fan controller, they need to set the specific regulator mode
to make the corresponding fan be able to be updated.
  For example, we are using fan controller MAX31790 and it need to write
1 into ./hwmon1/pwm1_enable to make ./hwmon1/fan1_input be able to be
updated.
  Add MAX31790 in sensor type and make it write 1 into pwm*_enable file
automatically.

Tested:
1. Remove entry "Pwm" in connector of some I2CFan in json and verify
   pass.

Signed-off-by: Jeff Lin <JeffLin2@quantatw.com>
Change-Id: Id97282bcd12b70fb7fc92f4d06e0e326522894a3
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index a34dd4d..e613494 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -83,7 +83,22 @@
     // todo: will we need to support other types?
     return FanTypes::i2c;
 }
+void enablePwm(const fs::path& filePath)
+{
+    std::fstream enableFile(filePath, std::ios::in | std::ios::out);
+    if (!enableFile.good())
+    {
+        std::cerr << "Error read/write " << filePath << "\n";
+        return;
+    }
 
+    std::string regulateMode;
+    std::getline(enableFile, regulateMode);
+    if (regulateMode == "0")
+    {
+        enableFile << 1;
+    }
+}
 void createRedundancySensor(
     const boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
         sensors,
@@ -372,7 +387,11 @@
                     auto findPwm = connector->second.find("Pwm");
                     if (findPwm != connector->second.end())
                     {
-
+                        fs::path pwmEnableFile =
+                            "pwm" + std::to_string(index + 1) + "_enable";
+                        fs::path enablePath =
+                            path.parent_path() / pwmEnableFile;
+                        enablePwm(enablePath);
                         size_t pwm = std::visit(VariantToUnsignedIntVisitor(),
                                                 findPwm->second);
                         pwmPath = directory / ("pwm" + std::to_string(pwm + 1));