xref: /openbmc/phosphor-pid-control/pid/fancontroller.hpp (revision bd63bcaca2ac9edf1778136cf240e3bbe8b31566)
1d8012181SPatrick Venture #pragma once
2d8012181SPatrick Venture 
3da4a5dd1SPatrick Venture #include "ec/pid.hpp"
4da4a5dd1SPatrick Venture #include "fan.hpp"
522c257abSJames Feist #include "pidcontroller.hpp"
6da4a5dd1SPatrick Venture 
7d8012181SPatrick Venture #include <memory>
8d8012181SPatrick Venture #include <string>
9d8012181SPatrick Venture #include <vector>
10d8012181SPatrick Venture 
11a076487aSPatrick Venture namespace pid_control
12a076487aSPatrick Venture {
13a076487aSPatrick Venture 
14d8012181SPatrick Venture /*
15d8012181SPatrick Venture  * A FanController is a PID controller that reads a number of fans and given
16d8012181SPatrick Venture  * the output then tries to set them to the goal values set by the thermal
17d8012181SPatrick Venture  * controllers.
18d8012181SPatrick Venture  */
19d8012181SPatrick Venture class FanController : public PIDController
20d8012181SPatrick Venture {
21d8012181SPatrick Venture   public:
22*bd63bcacSPatrick Williams     static std::unique_ptr<PIDController> createFanPid(
23*bd63bcacSPatrick Williams         ZoneInterface* owner, const std::string& id,
24*bd63bcacSPatrick Williams         const std::vector<std::string>& inputs, const ec::pidinfo& initial);
25d8012181SPatrick Venture 
FanController(const std::string & id,const std::vector<std::string> & inputs,ZoneInterface * owner)264a2dc4d8SPatrick Venture     FanController(const std::string& id, const std::vector<std::string>& inputs,
27da4a5dd1SPatrick Venture                   ZoneInterface* owner) :
28*bd63bcacSPatrick Williams         PIDController(id, owner), _inputs(inputs),
29*bd63bcacSPatrick Williams         _direction(FanSpeedDirection::NEUTRAL)
30a83a3eccSPatrick Venture     {}
317e63502aSPatrick Rudolph     ~FanController();
325f59c0fdSPatrick Venture     double inputProc(void) override;
335f59c0fdSPatrick Venture     double setptProc(void) override;
345f59c0fdSPatrick Venture     void outputProc(double value) override;
35d8012181SPatrick Venture 
getFanDirection(void) const36566a1518SPatrick Venture     FanSpeedDirection getFanDirection(void) const
37566a1518SPatrick Venture     {
38566a1518SPatrick Venture         return _direction;
39566a1518SPatrick Venture     }
40566a1518SPatrick Venture 
setFanDirection(FanSpeedDirection direction)41d8012181SPatrick Venture     void setFanDirection(FanSpeedDirection direction)
42d8012181SPatrick Venture     {
43d8012181SPatrick Venture         _direction = direction;
44d8012181SPatrick Venture     };
45d8012181SPatrick Venture 
46d8012181SPatrick Venture   private:
47d8012181SPatrick Venture     std::vector<std::string> _inputs;
48d8012181SPatrick Venture     FanSpeedDirection _direction;
49df597657SJosh Lehan 
50df597657SJosh Lehan     // Cosmetic only, to reduce frequency of repetitive messages
51df597657SJosh Lehan     bool failsafeTransition = true;
52df597657SJosh Lehan     bool failsafePrevState = false;
53d8012181SPatrick Venture };
54a076487aSPatrick Venture 
55a076487aSPatrick Venture } // namespace pid_control
56