blob: 89b3d5e6007ebe2e91ad1155926cfe83d8a9f472 [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001#pragma once
2
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "ec/pid.hpp"
4#include "fan.hpp"
James Feist22c257a2018-08-31 14:07:12 -07005#include "pidcontroller.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006
Patrick Ventured8012182018-03-08 08:21:38 -08007#include <memory>
8#include <string>
9#include <vector>
10
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
13
Patrick Ventured8012182018-03-08 08:21:38 -080014/*
15 * A FanController is a PID controller that reads a number of fans and given
16 * the output then tries to set them to the goal values set by the thermal
17 * controllers.
18 */
19class FanController : public PIDController
20{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070021 public:
22 static std::unique_ptr<PIDController>
Patrick Venture563a3562018-10-30 09:31:26 -070023 createFanPid(ZoneInterface* owner, const std::string& id,
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070024 const std::vector<std::string>& inputs,
Patrick Venturef77d5a52018-10-23 09:32:52 -070025 const ec::pidinfo& initial);
Patrick Ventured8012182018-03-08 08:21:38 -080026
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070027 FanController(const std::string& id, const std::vector<std::string>& inputs,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 ZoneInterface* owner) :
29 PIDController(id, owner),
30 _inputs(inputs), _direction(FanSpeedDirection::NEUTRAL)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070031 {}
Patrick Ventured8012182018-03-08 08:21:38 -080032
Patrick Venture5f59c0f2018-11-11 12:55:14 -080033 double inputProc(void) override;
34 double setptProc(void) override;
35 void outputProc(double value) override;
Patrick Ventured8012182018-03-08 08:21:38 -080036
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 FanSpeedDirection getFanDirection(void) const
38 {
39 return _direction;
40 }
Patrick Venture566a1512018-06-12 14:51:07 -070041
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 void setFanDirection(FanSpeedDirection direction)
43 {
44 _direction = direction;
45 };
Patrick Ventured8012182018-03-08 08:21:38 -080046
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070047 private:
48 std::vector<std::string> _inputs;
49 FanSpeedDirection _direction;
Bonnie Loc51ba912022-10-12 14:07:22 +080050 bool failsafePrint = true;
Patrick Ventured8012182018-03-08 08:21:38 -080051};
Patrick Venturea0764872020-08-08 07:48:43 -070052
53} // namespace pid_control