PID Objects & Algo

These are the PID controller implementations for fans,
and thermals.  This also includes the PID algorithm used.

Change-Id: I30471fbf7a8a7ed65f78bf105970d62815fedc56
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp
new file mode 100644
index 0000000..0816991
--- /dev/null
+++ b/pid/fancontroller.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "controller.hpp"
+#include "fan.hpp"
+#include "ec/pid.hpp"
+
+
+/*
+ * A FanController is a PID controller that reads a number of fans and given
+ * the output then tries to set them to the goal values set by the thermal
+ * controllers.
+ */
+class FanController : public PIDController
+{
+    public:
+        static std::unique_ptr<PIDController> CreateFanPid(
+            std::shared_ptr<PIDZone> owner,
+            const std::string& id,
+            std::vector<std::string>& inputs,
+            ec::pidinfo initial);
+
+        FanController(const std::string& id,
+                      std::vector<std::string>& inputs,
+                      std::shared_ptr<PIDZone> owner)
+            : PIDController(id, owner),
+              _inputs(inputs),
+              _direction(FanSpeedDirection::NEUTRAL)
+        { }
+
+        float input_proc(void) override;
+        float setpt_proc(void) override;
+        void output_proc(float value) override;
+
+        void setFanDirection(FanSpeedDirection direction)
+        {
+            _direction = direction;
+        };
+
+    private:
+        std::vector<std::string> _inputs;
+        FanSpeedDirection _direction;
+};