blob: c44503ff1f2277b35da9b1e3ec02b10f9fe37d3f [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"
18#include "util.hpp"
19#include "zone.hpp"
20
21
22std::unique_ptr<PIDController> ThermalController::CreateThermalPid(
23 std::shared_ptr<PIDZone> owner,
24 const std::string& id,
25 std::vector<std::string>& inputs,
26 float setpoint,
27 ec::pidinfo initial)
28{
29 auto thermal = std::make_unique<ThermalController>(id, inputs, owner);
30
31 ec::pid_info_t* info = thermal->get_pid_info();
32 thermal->set_setpoint(setpoint);
33
34 InitializePIDStruct(info, &initial);
35
36 return thermal;
37}
38
39//bmc_host_sensor_value_float
40float ThermalController::input_proc(void)
41{
42 /*
43 * This only supports one thermal input because it doesn't yet know how to
44 * handle merging them, probably max?
45 */
46 double value = _owner->getCachedValue(_inputs.at(0));
47 return static_cast<float>(value);
48}
49
50// bmc_get_setpt
51float ThermalController::setpt_proc(void)
52{
53 float setpoint = get_setpoint();
54
55 /* TODO(venture): Thermal setpoint invalid? */
56#if 0
57 if (-1 == setpoint)
58 {
59 return 0.0f;
60 }
61 else
62 {
63 return setpoint;
64 }
65#endif
66 return setpoint;
67}
68
69// bmc_set_pid_output
70void ThermalController::output_proc(float value)
71{
72 _owner->addRPMSetPoint(value);
73
74 return;
75}
76