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/controller.hpp b/pid/controller.hpp
new file mode 100644
index 0000000..0b1de3c
--- /dev/null
+++ b/pid/controller.hpp
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "fan.hpp"
+#include "ec/pid.hpp"
+
+class PIDZone;
+
+/*
+ * Base class for PID controllers.  Each PID that implements this needs to
+ * provide an input_proc, setpt_proc, and output_proc.
+ */
+class PIDController
+{
+    public:
+        PIDController(const std::string& id, std::shared_ptr<PIDZone> owner)
+            : _owner(owner),
+              _id(id)
+        { }
+
+        virtual ~PIDController() { }
+
+        virtual float input_proc(void) = 0;
+        virtual float setpt_proc(void) = 0;
+        virtual void output_proc(float value) = 0;
+
+        void pid_process(void);
+
+        std::string get_id(void)
+        {
+            return _id;
+        }
+        float get_setpoint(void)
+        {
+            return _setpoint;
+        }
+        void set_setpoint(float setpoint)
+        {
+            _setpoint = setpoint;
+        }
+
+        ec::pid_info_t* get_pid_info(void)
+        {
+            return &_pid_info;
+        }
+
+    protected:
+        std::shared_ptr<PIDZone> _owner;
+
+    private:
+        // parameters
+        ec::pid_info_t  _pid_info;
+        float           _setpoint;
+        std::string     _id;
+};
+