blob: 485688a3b0f469ea02c04e2992dd5b5f0b4ddb02 [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001/**
2 * Copyright 2017 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "thermalcontroller.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070018
Patrick Ventured8012182018-03-08 08:21:38 -080019#include "util.hpp"
20#include "zone.hpp"
21
Patrick Venture563a3562018-10-30 09:31:26 -070022std::unique_ptr<PIDController> ThermalController::createThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023 ZoneInterface* owner, const std::string& id,
Patrick Venture5f59c0f2018-11-11 12:55:14 -080024 const std::vector<std::string>& inputs, double setpoint,
Patrick Venturef77d5a52018-10-23 09:32:52 -070025 const ec::pidinfo& initial)
Patrick Ventured8012182018-03-08 08:21:38 -080026{
Patrick Venture3349ef22018-06-12 14:09:29 -070027 // ThermalController currently only supports precisely one input.
28 if (inputs.size() != 1)
29 {
30 return nullptr;
31 }
32
Patrick Ventured8012182018-03-08 08:21:38 -080033 auto thermal = std::make_unique<ThermalController>(id, inputs, owner);
34
Patrick Venture563a3562018-10-30 09:31:26 -070035 ec::pid_info_t* info = thermal->getPIDInfo();
36 thermal->setSetpoint(setpoint);
Patrick Ventured8012182018-03-08 08:21:38 -080037
Patrick Venture7af157b2018-10-30 11:24:40 -070038 initializePIDStruct(info, initial);
Patrick Ventured8012182018-03-08 08:21:38 -080039
40 return thermal;
41}
42
Patrick Venture5f59c0f2018-11-11 12:55:14 -080043// bmc_host_sensor_value_double
44double ThermalController::inputProc(void)
Patrick Ventured8012182018-03-08 08:21:38 -080045{
46 /*
47 * This only supports one thermal input because it doesn't yet know how to
48 * handle merging them, probably max?
49 */
50 double value = _owner->getCachedValue(_inputs.at(0));
Patrick Venture5f59c0f2018-11-11 12:55:14 -080051 return value;
Patrick Ventured8012182018-03-08 08:21:38 -080052}
53
54// bmc_get_setpt
Patrick Venture5f59c0f2018-11-11 12:55:14 -080055double ThermalController::setptProc(void)
Patrick Ventured8012182018-03-08 08:21:38 -080056{
Patrick Venture5f59c0f2018-11-11 12:55:14 -080057 double setpoint = getSetpoint();
Patrick Ventured8012182018-03-08 08:21:38 -080058
59 /* TODO(venture): Thermal setpoint invalid? */
60#if 0
61 if (-1 == setpoint)
62 {
63 return 0.0f;
64 }
65 else
66 {
67 return setpoint;
68 }
69#endif
70 return setpoint;
71}
72
73// bmc_set_pid_output
Patrick Venture5f59c0f2018-11-11 12:55:14 -080074void ThermalController::outputProc(double value)
Patrick Ventured8012182018-03-08 08:21:38 -080075{
76 _owner->addRPMSetPoint(value);
77
78 return;
79}