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