blob: 700f65101bce430485cd4a504bf2f30a21f24ff0 [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:
Patrick Williamsbd63bca2024-08-16 15:21:10 -040022 static std::unique_ptr<PIDController> createFanPid(
23 ZoneInterface* owner, const std::string& id,
24 const std::vector<std::string>& inputs, const ec::pidinfo& initial);
Patrick Ventured8012182018-03-08 08:21:38 -080025
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070026 FanController(const std::string& id, const std::vector<std::string>& inputs,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 ZoneInterface* owner) :
Patrick Williamsbd63bca2024-08-16 15:21:10 -040028 PIDController(id, owner), _inputs(inputs),
29 _direction(FanSpeedDirection::NEUTRAL)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070030 {}
Patrick Rudolph7e635022023-10-13 12:40:14 +020031 ~FanController();
Patrick Venture5f59c0f2018-11-11 12:55:14 -080032 double inputProc(void) override;
33 double setptProc(void) override;
34 void outputProc(double value) override;
Patrick Ventured8012182018-03-08 08:21:38 -080035
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070036 FanSpeedDirection getFanDirection(void) const
37 {
38 return _direction;
39 }
Patrick Venture566a1512018-06-12 14:51:07 -070040
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 void setFanDirection(FanSpeedDirection direction)
42 {
43 _direction = direction;
44 };
Patrick Ventured8012182018-03-08 08:21:38 -080045
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 private:
47 std::vector<std::string> _inputs;
48 FanSpeedDirection _direction;
Josh Lehandf597652023-12-19 15:05:53 -080049
50 // Cosmetic only, to reduce frequency of repetitive messages
51 bool failsafeTransition = true;
52 bool failsafePrevState = false;
Patrick Ventured8012182018-03-08 08:21:38 -080053};
Patrick Venturea0764872020-08-08 07:48:43 -070054
55} // namespace pid_control