1 #pragma once
2 
3 #include "ec/pid.hpp"
4 #include "pidcontroller.hpp"
5 
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 namespace pid_control
11 {
12 
13 /*
14  * A ThermalController is a PID controller that reads a number of sensors and
15  * provides the setpoints for the fans.
16  * With addition of support for power sensors, this name is misleading,
17  * as it now works for power sensors also, not just thermal sensors.
18  * If rewritten today, a better name would be "ComputationType".
19  */
20 
21 enum class ThermalType
22 {
23     margin,
24     absolute,
25     summation
26 };
27 
28 /**
29  * Get the ThermalType for a given string.
30  *
31  * @param[in] typeString - a string representation of a type.
32  * @return the ThermalType representation.
33  */
34 ThermalType getThermalType(const std::string& typeString);
35 
36 /**
37  * Is the type specified a thermal type?
38  *
39  * @param[in] typeString - a string representation of a PID type.
40  * @return true if it's a thermal PID type.
41  */
42 bool isThermalType(const std::string& typeString);
43 
44 class ThermalController : public PIDController
45 {
46   public:
47     static std::unique_ptr<PIDController>
48         createThermalPid(ZoneInterface* owner, const std::string& id,
49                          const std::vector<std::string>& inputs,
50                          double setpoint, const ec::pidinfo& initial,
51                          const ThermalType& type);
52 
53     ThermalController(const std::string& id,
54                       const std::vector<std::string>& inputs,
55                       const ThermalType& type, ZoneInterface* owner) :
56         PIDController(id, owner),
57         _inputs(inputs), type(type)
58     {}
59 
60     double inputProc(void) override;
61     double setptProc(void) override;
62     void outputProc(double value) override;
63 
64   private:
65     std::vector<std::string> _inputs;
66     ThermalType type;
67 };
68 
69 } // namespace pid_control
70