1 /**
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 
19 #include "util.hpp"
20 #include "zone.hpp"
21 
22 std::unique_ptr<PIDController> ThermalController::createThermalPid(
23     ZoneInterface* owner, const std::string& id,
24     const std::vector<std::string>& inputs, float setpoint,
25     const ec::pidinfo& initial)
26 {
27     // ThermalController currently only supports precisely one input.
28     if (inputs.size() != 1)
29     {
30         return nullptr;
31     }
32 
33     auto thermal = std::make_unique<ThermalController>(id, inputs, owner);
34 
35     ec::pid_info_t* info = thermal->getPIDInfo();
36     thermal->setSetpoint(setpoint);
37 
38     initializePIDStruct(info, initial);
39 
40     return thermal;
41 }
42 
43 // bmc_host_sensor_value_float
44 float ThermalController::inputProc(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
55 float ThermalController::setptProc(void)
56 {
57     float setpoint = getSetpoint();
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
74 void ThermalController::outputProc(float value)
75 {
76     _owner->addRPMSetPoint(value);
77 
78     return;
79 }
80