Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 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" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 18 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 19 | #include "util.hpp" |
| 20 | #include "zone.hpp" |
| 21 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 22 | std::unique_ptr<PIDController> ThermalController::CreateThermalPid( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 23 | ZoneInterface* owner, const std::string& id, |
Patrick Venture | f77d5a5 | 2018-10-23 09:32:52 -0700 | [diff] [blame] | 24 | const std::vector<std::string>& inputs, float setpoint, |
| 25 | const ec::pidinfo& initial) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 26 | { |
Patrick Venture | 3349ef2 | 2018-06-12 14:09:29 -0700 | [diff] [blame] | 27 | // ThermalController currently only supports precisely one input. |
| 28 | if (inputs.size() != 1) |
| 29 | { |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 33 | 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 Venture | f77d5a5 | 2018-10-23 09:32:52 -0700 | [diff] [blame] | 38 | InitializePIDStruct(info, initial); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 39 | |
| 40 | return thermal; |
| 41 | } |
| 42 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 43 | // bmc_host_sensor_value_float |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 44 | float 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 |
| 55 | float 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 |
| 74 | void ThermalController::output_proc(float value) |
| 75 | { |
| 76 | _owner->addRPMSetPoint(value); |
| 77 | |
| 78 | return; |
| 79 | } |