blob: f9d1e11d26aa7608f4dea30a0c36c21835588689 [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 Ventured8012182018-03-08 08:21:38 -080022std::unique_ptr<PIDController> ThermalController::CreateThermalPid(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023 ZoneInterface* owner, const std::string& id,
Patrick Venturef77d5a52018-10-23 09:32:52 -070024 const std::vector<std::string>& inputs, float setpoint,
25 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
35 ec::pid_info_t* info = thermal->get_pid_info();
36 thermal->set_setpoint(setpoint);
37
Patrick Venturef77d5a52018-10-23 09:32:52 -070038 InitializePIDStruct(info, initial);
Patrick Ventured8012182018-03-08 08:21:38 -080039
40 return thermal;
41}
42
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043// bmc_host_sensor_value_float
Patrick Ventured8012182018-03-08 08:21:38 -080044float ThermalController::input_proc(void)
45{
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));
51 return static_cast<float>(value);
52}
53
54// bmc_get_setpt
55float ThermalController::setpt_proc(void)
56{
57 float setpoint = get_setpoint();
58
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
74void ThermalController::output_proc(float value)
75{
76 _owner->addRPMSetPoint(value);
77
78 return;
79}