pid/zone: Restore PWM when fans returned to auto

This makes use of the improved write() interface, to allow the
PID-loop-determined PWM to be restored, when the fan is returned to
automatic mode.

Without this fix, a fan set to manual mode, then manually set to a
different speed, would not properly return to the correct speed, when
transitioning back to automatic from manual.

This patch also adds a stub to allow the caller to learn the raw PWM
value written as output, another useful write() interface improvement.
Although not the topic of this change, it is included here, to avoid
later patch conflicts.

Tested: I can now correctly toggle between automatic, and manual, fan
control. Upon resuming automatic control, after a few seconds, the fan
PWM is now properly restored, to what the PID loop wanted it to be at.

Signed-off-by: Josh Lehan <krellan@google.com>
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: I46fc65d6b931755d51093ea475c64cf5e3e6bacb
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 441031a..af40a2b 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -82,6 +82,12 @@
 void DbusPidZone::setManualMode(bool mode)
 {
     _manualMode = mode;
+
+    // If returning to automatic mode, need to restore PWM from PID loop
+    if (!mode)
+    {
+        _redundantWrite = true;
+    }
 }
 
 bool DbusPidZone::getFailSafeMode(void) const
@@ -432,6 +438,12 @@
     {
         p->process();
     }
+
+    if (_redundantWrite)
+    {
+        // This is only needed once
+        _redundantWrite = false;
+    }
 }
 
 void DbusPidZone::processThermals(void)
@@ -447,6 +459,11 @@
     return _mgr.getSensor(name);
 }
 
+bool DbusPidZone::getRedundantWrite(void) const
+{
+    return _redundantWrite;
+}
+
 bool DbusPidZone::manual(bool value)
 {
     std::cerr << "manual: " << value << std::endl;