blob: 585cbeb5cff39597983d36f9751f8a9c62a5566f [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/* Configuration. */
Patrick Ventured8012182018-03-08 08:21:38 -080018#include "zone.hpp"
19
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020#include "conf.hpp"
21#include "pid/controller.hpp"
22#include "pid/ec/pid.hpp"
23#include "pid/fancontroller.hpp"
James Feist22c257a2018-08-31 14:07:12 -070024#include "pid/stepwisecontroller.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025#include "pid/thermalcontroller.hpp"
Patrick Venturec32e3fc2019-02-28 10:01:11 -080026#include "pid/tuning.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027
Patrick Ventured8012182018-03-08 08:21:38 -080028#include <algorithm>
29#include <chrono>
30#include <cstring>
31#include <fstream>
32#include <iostream>
Patrick Ventured8012182018-03-08 08:21:38 -080033#include <memory>
Josh Lehan55ccad62020-09-20 23:57:49 -070034#include <sstream>
Patrick Venture7a98c192020-08-12 08:35:16 -070035#include <string>
Patrick Ventured8012182018-03-08 08:21:38 -080036
Patrick Ventured8012182018-03-08 08:21:38 -080037using tstamp = std::chrono::high_resolution_clock::time_point;
38using namespace std::literals::chrono_literals;
39
Josh Lehan55ccad62020-09-20 23:57:49 -070040// Enforces minimum duration between events
41// Rreturns true if event should be allowed, false if disallowed
42bool allowThrottle(const tstamp& now, const std::chrono::seconds& pace)
43{
44 static tstamp then;
45 static bool first = true;
46
47 if (first)
48 {
49 // Special case initialization
50 then = now;
51 first = false;
52
53 // Initialization, always allow
54 return true;
55 }
56
57 auto elapsed = now - then;
58 if (elapsed < pace)
59 {
60 // Too soon since last time, disallow
61 return false;
62 }
63
64 // It has been long enough, allow
65 then = now;
66 return true;
67}
68
69namespace pid_control
70{
71
Patrick Venture597ebd62020-08-11 08:48:19 -070072double DbusPidZone::getMaxSetPointRequest(void) const
Patrick Ventured8012182018-03-08 08:21:38 -080073{
Patrick Venturef7a2dd52019-07-16 14:31:13 -070074 return _maximumSetPoint;
Patrick Ventured8012182018-03-08 08:21:38 -080075}
76
Patrick Venture597ebd62020-08-11 08:48:19 -070077bool DbusPidZone::getManualMode(void) const
Patrick Ventured8012182018-03-08 08:21:38 -080078{
79 return _manualMode;
80}
81
Patrick Venture597ebd62020-08-11 08:48:19 -070082void DbusPidZone::setManualMode(bool mode)
Patrick Ventured8012182018-03-08 08:21:38 -080083{
84 _manualMode = mode;
Josh Lehana4146eb2020-10-01 11:49:09 -070085
86 // If returning to automatic mode, need to restore PWM from PID loop
87 if (!mode)
88 {
89 _redundantWrite = true;
90 }
Patrick Ventured8012182018-03-08 08:21:38 -080091}
92
Patrick Venture597ebd62020-08-11 08:48:19 -070093bool DbusPidZone::getFailSafeMode(void) const
Patrick Ventured8012182018-03-08 08:21:38 -080094{
95 // If any keys are present at least one sensor is in fail safe mode.
96 return !_failSafeSensors.empty();
97}
98
Patrick Venture597ebd62020-08-11 08:48:19 -070099int64_t DbusPidZone::getZoneID(void) const
Patrick Ventured8012182018-03-08 08:21:38 -0800100{
101 return _zoneId;
102}
103
Nirav Shahccc8bb62022-02-17 21:06:51 -0800104void DbusPidZone::addSetPoint(double setPoint, const std::string& name)
Patrick Ventured8012182018-03-08 08:21:38 -0800105{
Nirav Shahccc8bb62022-02-17 21:06:51 -0800106 _SetPoints.push_back(setPoint);
107 /*
108 * if there are multiple thermal controllers with the same
109 * value, pick the first one in the iterator
110 */
111 if (_maximumSetPoint < setPoint)
112 {
113 _maximumSetPoint = setPoint;
114 _maximumSetPointName = name;
115 }
Patrick Ventured8012182018-03-08 08:21:38 -0800116}
117
Patrick Venture597ebd62020-08-11 08:48:19 -0700118void DbusPidZone::addRPMCeiling(double ceiling)
James Feist608304d2019-02-25 10:01:42 -0800119{
120 _RPMCeilings.push_back(ceiling);
121}
122
Patrick Venture597ebd62020-08-11 08:48:19 -0700123void DbusPidZone::clearRPMCeilings(void)
James Feist608304d2019-02-25 10:01:42 -0800124{
125 _RPMCeilings.clear();
126}
127
Patrick Venture597ebd62020-08-11 08:48:19 -0700128void DbusPidZone::clearSetPoints(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800129{
Patrick Venture9bbf3332019-07-16 10:50:37 -0700130 _SetPoints.clear();
Nirav Shahccc8bb62022-02-17 21:06:51 -0800131 _maximumSetPoint = 0;
Patrick Ventured8012182018-03-08 08:21:38 -0800132}
133
Patrick Venture597ebd62020-08-11 08:48:19 -0700134double DbusPidZone::getFailSafePercent(void) const
Patrick Ventured8012182018-03-08 08:21:38 -0800135{
136 return _failSafePercent;
137}
138
Nirav Shahccc8bb62022-02-17 21:06:51 -0800139double DbusPidZone::getMinThermalSetPoint(void) const
Patrick Ventured8012182018-03-08 08:21:38 -0800140{
James Feist3484bed2019-02-25 13:28:18 -0800141 return _minThermalOutputSetPt;
Patrick Ventured8012182018-03-08 08:21:38 -0800142}
143
Patrick Venture597ebd62020-08-11 08:48:19 -0700144void DbusPidZone::addFanPID(std::unique_ptr<Controller> pid)
Patrick Ventured8012182018-03-08 08:21:38 -0800145{
146 _fans.push_back(std::move(pid));
147}
148
Patrick Venture597ebd62020-08-11 08:48:19 -0700149void DbusPidZone::addThermalPID(std::unique_ptr<Controller> pid)
Patrick Ventured8012182018-03-08 08:21:38 -0800150{
151 _thermals.push_back(std::move(pid));
152}
153
Patrick Venture597ebd62020-08-11 08:48:19 -0700154double DbusPidZone::getCachedValue(const std::string& name)
Patrick Ventured8012182018-03-08 08:21:38 -0800155{
Josh Lehanb3005752022-02-22 20:48:07 -0800156 return _cachedValuesByName.at(name).scaled;
157}
158
159ValueCacheEntry DbusPidZone::getCachedValues(const std::string& name)
160{
Patrick Ventured8012182018-03-08 08:21:38 -0800161 return _cachedValuesByName.at(name);
162}
163
Josh Lehanb3005752022-02-22 20:48:07 -0800164void DbusPidZone::setOutputCache(std::string_view name,
165 const ValueCacheEntry& values)
166{
167 _cachedFanOutputs[std::string{name}] = values;
168}
169
Patrick Venture597ebd62020-08-11 08:48:19 -0700170void DbusPidZone::addFanInput(const std::string& fan)
Patrick Ventured8012182018-03-08 08:21:38 -0800171{
172 _fanInputs.push_back(fan);
173}
174
Patrick Venture597ebd62020-08-11 08:48:19 -0700175void DbusPidZone::addThermalInput(const std::string& therm)
Patrick Ventured8012182018-03-08 08:21:38 -0800176{
177 _thermalInputs.push_back(therm);
178}
179
Josh Lehan55ccad62020-09-20 23:57:49 -0700180// Updates desired RPM setpoint from optional text file
181// Returns true if rpmValue updated, false if left unchanged
182static bool fileParseRpm(const std::string& fileName, double& rpmValue)
183{
184 static constexpr std::chrono::seconds throttlePace{3};
185
186 std::string errText;
187
188 try
189 {
190 std::ifstream ifs;
191 ifs.open(fileName);
192 if (ifs)
193 {
194 int value;
195 ifs >> value;
196
197 if (value <= 0)
198 {
199 errText = "File content could not be parsed to a number";
200 }
201 else if (value <= 100)
202 {
203 errText = "File must contain RPM value, not PWM value";
204 }
205 else
206 {
207 rpmValue = static_cast<double>(value);
208 return true;
209 }
210 }
211 }
212 catch (const std::exception& e)
213 {
214 errText = "Exception: ";
215 errText += e.what();
216 }
217
218 // The file is optional, intentionally not an error if file not found
219 if (!(errText.empty()))
220 {
221 tstamp now = std::chrono::high_resolution_clock::now();
222 if (allowThrottle(now, throttlePace))
223 {
224 std::cerr << "Unable to read from '" << fileName << "': " << errText
225 << "\n";
226 }
227 }
228
229 return false;
230}
231
Patrick Venture597ebd62020-08-11 08:48:19 -0700232void DbusPidZone::determineMaxSetPointRequest(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800233{
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800234 std::vector<double>::iterator result;
Nirav Shahccc8bb62022-02-17 21:06:51 -0800235 double minThermalThreshold = getMinThermalSetPoint();
Patrick Ventured8012182018-03-08 08:21:38 -0800236
James Feist608304d2019-02-25 10:01:42 -0800237 if (_RPMCeilings.size() > 0)
238 {
239 result = std::min_element(_RPMCeilings.begin(), _RPMCeilings.end());
Nirav Shahccc8bb62022-02-17 21:06:51 -0800240 // if Max set point is larger than the lowest ceiling, reset to lowest
241 // ceiling.
242 if (*result < _maximumSetPoint)
243 {
244 _maximumSetPoint = *result;
245 // When using lowest ceiling, controller name is ceiling.
246 _maximumSetPointName = "Ceiling";
247 }
James Feist608304d2019-02-25 10:01:42 -0800248 }
249
Patrick Ventured8012182018-03-08 08:21:38 -0800250 /*
Patrick Venture7280e272019-02-11 10:45:32 -0800251 * If the maximum RPM setpoint output is below the minimum RPM
252 * setpoint, set it to the minimum.
Patrick Ventured8012182018-03-08 08:21:38 -0800253 */
Nirav Shahccc8bb62022-02-17 21:06:51 -0800254 if (minThermalThreshold >= _maximumSetPoint)
255 {
256 _maximumSetPoint = minThermalThreshold;
257 _maximumSetPointName = "";
258 }
259 else if (_maximumSetPointName.compare(_maximumSetPointNamePrev))
260 {
261 std::cerr << "PID Zone " << _zoneId << " max SetPoint "
262 << _maximumSetPoint << " requested by "
263 << _maximumSetPointName;
264 for (const auto& sensor : _failSafeSensors)
265 {
266 if (sensor.find("Fan") == std::string::npos)
267 {
268 std::cerr << " " << sensor;
269 }
270 }
271 std::cerr << "\n";
272 _maximumSetPointNamePrev.assign(_maximumSetPointName);
273 }
Patrick Venturede79ee02019-05-08 14:50:00 -0700274 if (tuningEnabled)
Patrick Ventured8012182018-03-08 08:21:38 -0800275 {
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800276 /*
277 * We received no setpoints from thermal sensors.
278 * This is a case experienced during tuning where they only specify
279 * fan sensors and one large fan PID for all the fans.
280 */
281 static constexpr auto setpointpath = "/etc/thermal.d/setpoint";
Patrick Venturedf766f22018-10-13 09:30:58 -0700282
Nirav Shahccc8bb62022-02-17 21:06:51 -0800283 fileParseRpm(setpointpath, _maximumSetPoint);
Josh Lehan55ccad62020-09-20 23:57:49 -0700284
285 // Allow per-zone setpoint files to override overall setpoint file
286 std::ostringstream zoneSuffix;
287 zoneSuffix << ".zone" << _zoneId;
288 std::string zoneSetpointPath = setpointpath + zoneSuffix.str();
289
Nirav Shahccc8bb62022-02-17 21:06:51 -0800290 fileParseRpm(zoneSetpointPath, _maximumSetPoint);
Patrick Ventured8012182018-03-08 08:21:38 -0800291 }
Patrick Ventured8012182018-03-08 08:21:38 -0800292 return;
293}
294
Patrick Venture597ebd62020-08-11 08:48:19 -0700295void DbusPidZone::initializeLog(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800296{
Patrick Venture5f02ad22018-04-24 10:18:40 -0700297 /* Print header for log file:
Josh Lehanb3005752022-02-22 20:48:07 -0800298 * epoch_ms,setpt,fan1,fan1_raw,fan1_pwm,fan1_pwm_raw,fan2,fan2_raw,fan2_pwm,fan2_pwm_raw,fanN,fanN_raw,fanN_pwm,fanN_pwm_raw,sensor1,sensor1_raw,sensor2,sensor2_raw,sensorN,sensorN_raw,failsafe
Patrick Venture5f02ad22018-04-24 10:18:40 -0700299 */
Patrick Ventured8012182018-03-08 08:21:38 -0800300
Nirav Shahccc8bb62022-02-17 21:06:51 -0800301 _log << "epoch_ms,setpt,requester";
Patrick Ventured8012182018-03-08 08:21:38 -0800302
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700303 for (const auto& f : _fanInputs)
Patrick Ventured8012182018-03-08 08:21:38 -0800304 {
Josh Lehanb3005752022-02-22 20:48:07 -0800305 _log << "," << f << "," << f << "_raw";
306 _log << "," << f << "_pwm," << f << "_pwm_raw";
Patrick Ventured8012182018-03-08 08:21:38 -0800307 }
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700308 for (const auto& t : _thermalInputs)
Patrick Venture5f02ad22018-04-24 10:18:40 -0700309 {
Josh Lehanb3005752022-02-22 20:48:07 -0800310 _log << "," << t << "," << t << "_raw";
Patrick Venture5f02ad22018-04-24 10:18:40 -0700311 }
Josh Lehanb3005752022-02-22 20:48:07 -0800312
Patrick Venture5f02ad22018-04-24 10:18:40 -0700313 _log << ",failsafe";
Patrick Ventured8012182018-03-08 08:21:38 -0800314 _log << std::endl;
Patrick Ventured8012182018-03-08 08:21:38 -0800315}
316
Patrick Venture7a98c192020-08-12 08:35:16 -0700317void DbusPidZone::writeLog(const std::string& value)
Patrick Ventured8012182018-03-08 08:21:38 -0800318{
Patrick Venture7a98c192020-08-12 08:35:16 -0700319 _log << value;
Patrick Ventured8012182018-03-08 08:21:38 -0800320}
Patrick Ventured8012182018-03-08 08:21:38 -0800321
322/*
323 * TODO(venture) This is effectively updating the cache and should check if the
324 * values they're using to update it are new or old, or whatnot. For instance,
325 * if we haven't heard from the host in X time we need to detect this failure.
326 *
327 * I haven't decided if the Sensor should have a lastUpdated method or whether
328 * that should be for the ReadInterface or etc...
329 */
330
331/**
332 * We want the PID loop to run with values cached, so this will get all the
333 * fan tachs for the loop.
334 */
Patrick Venture597ebd62020-08-11 08:48:19 -0700335void DbusPidZone::updateFanTelemetry(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800336{
337 /* TODO(venture): Should I just make _log point to /dev/null when logging
338 * is disabled? I think it's a waste to try and log things even if the
339 * data is just being dropped though.
340 */
Will Liangded0ab52019-05-15 17:10:06 +0800341 tstamp now = std::chrono::high_resolution_clock::now();
Patrick Venturede79ee02019-05-08 14:50:00 -0700342 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800343 {
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800344 _log << std::chrono::duration_cast<std::chrono::milliseconds>(
345 now.time_since_epoch())
346 .count();
Patrick Venturef7a2dd52019-07-16 14:31:13 -0700347 _log << "," << _maximumSetPoint;
Nirav Shahccc8bb62022-02-17 21:06:51 -0800348 _log << "," << _maximumSetPointName;
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800349 }
Patrick Ventured8012182018-03-08 08:21:38 -0800350
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700351 for (const auto& f : _fanInputs)
Patrick Ventured8012182018-03-08 08:21:38 -0800352 {
Patrick Venturea58197c2018-06-11 15:29:45 -0700353 auto sensor = _mgr.getSensor(f);
Patrick Ventured8012182018-03-08 08:21:38 -0800354 ReadReturn r = sensor->read();
Josh Lehanb3005752022-02-22 20:48:07 -0800355 _cachedValuesByName[f] = {r.value, r.unscaled};
Will Liangded0ab52019-05-15 17:10:06 +0800356 int64_t timeout = sensor->getTimeout();
357 tstamp then = r.updated;
Patrick Ventured8012182018-03-08 08:21:38 -0800358
Will Liangded0ab52019-05-15 17:10:06 +0800359 auto duration =
360 std::chrono::duration_cast<std::chrono::seconds>(now - then)
361 .count();
362 auto period = std::chrono::seconds(timeout).count();
Patrick Ventured8012182018-03-08 08:21:38 -0800363 /*
364 * TODO(venture): We should check when these were last read.
365 * However, these are the fans, so if I'm not getting updated values
366 * for them... what should I do?
367 */
Patrick Venturede79ee02019-05-08 14:50:00 -0700368 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800369 {
Josh Lehanb3005752022-02-22 20:48:07 -0800370 const auto& v = _cachedValuesByName[f];
371 _log << "," << v.scaled << "," << v.unscaled;
372 const auto& p = _cachedFanOutputs[f];
373 _log << "," << p.scaled << "," << p.unscaled;
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800374 }
Will Liangded0ab52019-05-15 17:10:06 +0800375
376 // check if fan fail.
377 if (sensor->getFailed())
378 {
379 _failSafeSensors.insert(f);
380 }
381 else if (timeout != 0 && duration >= period)
382 {
383 _failSafeSensors.insert(f);
384 }
385 else
386 {
387 // Check if it's in there: remove it.
388 auto kt = _failSafeSensors.find(f);
389 if (kt != _failSafeSensors.end())
390 {
391 _failSafeSensors.erase(kt);
392 }
393 }
Patrick Ventured8012182018-03-08 08:21:38 -0800394 }
395
Patrick Venturede79ee02019-05-08 14:50:00 -0700396 if (loggingEnabled)
Patrick Venture5f02ad22018-04-24 10:18:40 -0700397 {
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800398 for (const auto& t : _thermalInputs)
399 {
Josh Lehanb3005752022-02-22 20:48:07 -0800400 const auto& v = _cachedValuesByName[t];
401 _log << "," << v.scaled << "," << v.unscaled;
Patrick Venturec32e3fc2019-02-28 10:01:11 -0800402 }
Patrick Venture5f02ad22018-04-24 10:18:40 -0700403 }
Patrick Venture5f02ad22018-04-24 10:18:40 -0700404
Patrick Ventured8012182018-03-08 08:21:38 -0800405 return;
406}
407
Patrick Venture597ebd62020-08-11 08:48:19 -0700408void DbusPidZone::updateSensors(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800409{
410 using namespace std::chrono;
411 /* margin and temp are stored as temp */
412 tstamp now = high_resolution_clock::now();
413
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700414 for (const auto& t : _thermalInputs)
Patrick Ventured8012182018-03-08 08:21:38 -0800415 {
Patrick Venturea58197c2018-06-11 15:29:45 -0700416 auto sensor = _mgr.getSensor(t);
Patrick Ventured8012182018-03-08 08:21:38 -0800417 ReadReturn r = sensor->read();
Patrick Venture563a3562018-10-30 09:31:26 -0700418 int64_t timeout = sensor->getTimeout();
Patrick Ventured8012182018-03-08 08:21:38 -0800419
Josh Lehanb3005752022-02-22 20:48:07 -0800420 _cachedValuesByName[t] = {r.value, r.unscaled};
Patrick Ventured8012182018-03-08 08:21:38 -0800421 tstamp then = r.updated;
422
James Feist473d68d2019-02-25 09:19:13 -0800423 auto duration = duration_cast<std::chrono::seconds>(now - then).count();
424 auto period = std::chrono::seconds(timeout).count();
425
James Feist36b7d8e2018-10-05 15:39:01 -0700426 if (sensor->getFailed())
427 {
428 _failSafeSensors.insert(t);
429 }
James Feist473d68d2019-02-25 09:19:13 -0800430 else if (timeout != 0 && duration >= period)
Patrick Ventured8012182018-03-08 08:21:38 -0800431 {
James Feist473d68d2019-02-25 09:19:13 -0800432 // std::cerr << "Entering fail safe mode.\n";
433 _failSafeSensors.insert(t);
434 }
435 else
436 {
437 // Check if it's in there: remove it.
438 auto kt = _failSafeSensors.find(t);
439 if (kt != _failSafeSensors.end())
Patrick Ventured8012182018-03-08 08:21:38 -0800440 {
James Feist473d68d2019-02-25 09:19:13 -0800441 _failSafeSensors.erase(kt);
Patrick Ventured8012182018-03-08 08:21:38 -0800442 }
443 }
444 }
445
446 return;
447}
448
Patrick Venture597ebd62020-08-11 08:48:19 -0700449void DbusPidZone::initializeCache(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800450{
Josh Lehanb3005752022-02-22 20:48:07 -0800451 auto nan = std::numeric_limits<double>::quiet_NaN();
452
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700453 for (const auto& f : _fanInputs)
Patrick Ventured8012182018-03-08 08:21:38 -0800454 {
Josh Lehanb3005752022-02-22 20:48:07 -0800455 _cachedValuesByName[f] = {nan, nan};
456 _cachedFanOutputs[f] = {nan, nan};
Will Liangded0ab52019-05-15 17:10:06 +0800457
458 // Start all fans in fail-safe mode.
459 _failSafeSensors.insert(f);
Patrick Ventured8012182018-03-08 08:21:38 -0800460 }
461
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700462 for (const auto& t : _thermalInputs)
Patrick Ventured8012182018-03-08 08:21:38 -0800463 {
Josh Lehanb3005752022-02-22 20:48:07 -0800464 _cachedValuesByName[t] = {nan, nan};
Patrick Ventured8012182018-03-08 08:21:38 -0800465
466 // Start all sensors in fail-safe mode.
467 _failSafeSensors.insert(t);
468 }
469}
470
Patrick Venture597ebd62020-08-11 08:48:19 -0700471void DbusPidZone::dumpCache(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800472{
473 std::cerr << "Cache values now: \n";
Patrick Venture2a50eda2020-08-16 08:26:35 -0700474 for (const auto& [name, value] : _cachedValuesByName)
Patrick Ventured8012182018-03-08 08:21:38 -0800475 {
Josh Lehanb3005752022-02-22 20:48:07 -0800476 std::cerr << name << ": " << value.scaled << " " << value.unscaled
477 << "\n";
478 }
479
480 std::cerr << "Fan outputs now: \n";
481 for (const auto& [name, value] : _cachedFanOutputs)
482 {
483 std::cerr << name << ": " << value.scaled << " " << value.unscaled
484 << "\n";
Patrick Ventured8012182018-03-08 08:21:38 -0800485 }
486}
487
Patrick Venture597ebd62020-08-11 08:48:19 -0700488void DbusPidZone::processFans(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800489{
490 for (auto& p : _fans)
491 {
James Feist22c257a2018-08-31 14:07:12 -0700492 p->process();
Patrick Ventured8012182018-03-08 08:21:38 -0800493 }
Josh Lehana4146eb2020-10-01 11:49:09 -0700494
495 if (_redundantWrite)
496 {
497 // This is only needed once
498 _redundantWrite = false;
499 }
Patrick Ventured8012182018-03-08 08:21:38 -0800500}
501
Patrick Venture597ebd62020-08-11 08:48:19 -0700502void DbusPidZone::processThermals(void)
Patrick Ventured8012182018-03-08 08:21:38 -0800503{
504 for (auto& p : _thermals)
505 {
James Feist22c257a2018-08-31 14:07:12 -0700506 p->process();
Patrick Ventured8012182018-03-08 08:21:38 -0800507 }
508}
509
Patrick Venture597ebd62020-08-11 08:48:19 -0700510Sensor* DbusPidZone::getSensor(const std::string& name)
Patrick Ventured8012182018-03-08 08:21:38 -0800511{
Patrick Venturefe75b192018-06-08 11:19:43 -0700512 return _mgr.getSensor(name);
Patrick Ventured8012182018-03-08 08:21:38 -0800513}
514
Josh Lehana4146eb2020-10-01 11:49:09 -0700515bool DbusPidZone::getRedundantWrite(void) const
516{
517 return _redundantWrite;
518}
519
Patrick Venture597ebd62020-08-11 08:48:19 -0700520bool DbusPidZone::manual(bool value)
Patrick Ventured8012182018-03-08 08:21:38 -0800521{
522 std::cerr << "manual: " << value << std::endl;
523 setManualMode(value);
524 return ModeObject::manual(value);
525}
526
Patrick Venture597ebd62020-08-11 08:48:19 -0700527bool DbusPidZone::failSafe() const
Patrick Ventured8012182018-03-08 08:21:38 -0800528{
529 return getFailSafeMode();
530}
Patrick Venturea0764872020-08-08 07:48:43 -0700531
532} // namespace pid_control