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