blob: cea21e519f4659f0e072a99017436257a4c04272 [file] [log] [blame]
James Feist22c257a2018-08-31 14:07:12 -07001/*
2// Copyright (c) 2018 Intel Corporation
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 "stepwisecontroller.hpp"
18
19#include "ec/stepwise.hpp"
20#include "util.hpp"
21#include "zone.hpp"
22
23#include <algorithm>
24#include <chrono>
25#include <iostream>
26#include <map>
27#include <memory>
28#include <thread>
29#include <vector>
30
31void StepwiseController::process(void)
32{
33 // Get input value
34 float input = input_proc();
35
36 // Calculate new output
37 float output = ec::stepwise(get_stepwise_info(), input);
38
39 // Output new value
40 output_proc(output);
41
42 return;
43}
44
45std::unique_ptr<Controller> StepwiseController::CreateStepwiseController(
46 ZoneInterface* owner, const std::string& id,
47 const std::vector<std::string>& inputs, const ec::StepwiseInfo& initial)
48{
49 // StepwiseController currently only supports precisely one input.
50 if (inputs.size() != 1)
51 {
52 return nullptr;
53 }
54
55 auto thermal = std::make_unique<StepwiseController>(id, inputs, owner);
56
57 ec::StepwiseInfo& info = thermal->get_stepwise_info();
58
59 info = initial;
60
61 return thermal;
62}
63
64float StepwiseController::input_proc(void)
65{
66 double value = _owner->getCachedValue(_inputs.at(0));
67 return static_cast<float>(value);
68}
69
70void StepwiseController::output_proc(float value)
71{
72 _owner->addRPMSetPoint(value);
73
74 return;
75}