blob: d7f73b4d5a825d96b0845e839006674140fca38f [file] [log] [blame]
Patrick Venture1a153792020-08-11 08:41:47 -07001#pragma once
2
3#include "sensors/sensor.hpp"
4
5#include <string>
6
7namespace pid_control
8{
9
Patrick Venture7a98c192020-08-12 08:35:16 -070010/**
11 * In a Zone you have a set of PIDs which feed each other. Fan PIDs are fed set
12 * points from Thermal PIDs.
13 */
Patrick Venture1a153792020-08-11 08:41:47 -070014class ZoneInterface
15{
16 public:
17 virtual ~ZoneInterface() = default;
18
Patrick Venture7a98c192020-08-12 08:35:16 -070019 /** If the zone implementation supports logging, initialize the log. */
20 virtual void initializeLog(void) = 0;
21 /** If the zone implementation supports logging, write string to log. */
22 virtual void writeLog(const std::string& value) = 0;
23
24 /** Return a pointer to the sensor specified by name. */
Patrick Venture1a153792020-08-11 08:41:47 -070025 virtual Sensor* getSensor(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070026
27 /* updateFanTelemetry() and updateSensors() both clear the failsafe state
28 * for a sensor if it's no longer in that state.
29 */
30 /** For each fan input in the zone, read each to update the cachedValue and
31 * check if the fan is beyond its timeout to trigger a failsafe condition.
32 */
33 virtual void updateFanTelemetry(void) = 0;
34 /** For each thermal input in the zone, read each to update the cachedValue
35 * and check if the sensor is beyond its timeout to trigger a failsafe
36 * condition.
37 */
38 virtual void updateSensors(void) = 0;
39 /** For each fan and thermal input in the zone, set the cachedValue to 0 and
40 * set the input as failsafe - to default the zone to failsafe before it
41 * starts processing values to control fans.
42 */
43 virtual void initializeCache(void) = 0;
Josh Lehana4146eb2020-10-01 11:49:09 -070044
Josh Lehanb3005752022-02-22 20:48:07 -080045 /** Optionally adds fan outputs to an output cache, which is different
46 * from the input cache accessed by getCachedValue(), so it is possible
47 * to have entries with the same name in both the output cache and
48 * the input cache. The output cache is used for logging, to show
49 * the PWM values determined by the PID loop, next to the resulting RPM.
50 */
51 virtual void setOutputCache(std::string_view name,
52 const ValueCacheEntry& values) = 0;
53
Patrick Venture7a98c192020-08-12 08:35:16 -070054 /** Return cached value for sensor by name. */
55 virtual double getCachedValue(const std::string& name) = 0;
Josh Lehanb3005752022-02-22 20:48:07 -080056 /** Return cached values, both scaled and original unscaled values,
57 * for sensor by name. Subclasses can add trivial return {value, value},
58 * for subclasses that only implement getCachedValue() and do not care
59 * about maintaining the distinction between scaled and unscaled values.
60 */
61 virtual ValueCacheEntry getCachedValues(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070062
63 /** Add a set point value for the Max Set Point computation. */
Nirav Shahccc8bb62022-02-17 21:06:51 -080064 virtual void addSetPoint(double setpoint, const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070065 /** Clear all set points specified via addSetPoint */
66 virtual void clearSetPoints(void) = 0;
67
68 /** Add maximum RPM value to drive fan pids. */
69 virtual void addRPMCeiling(double ceiling) = 0;
70 /** Clear any RPM value set with addRPMCeiling. */
71 virtual void clearRPMCeilings(void) = 0;
72
73 /** Compute the value returned by getMaxSetPointRequest - called from the
74 * looping mechanism before triggering any Fan PIDs. The value computed is
75 * used by each fan PID.
76 */
77 virtual void determineMaxSetPointRequest(void) = 0;
78 /** Given the set points added via addSetPoint, return the maximum value -
79 * called from the PID loop that uses that value to drive the fans.
80 */
81 virtual double getMaxSetPointRequest() const = 0;
82
83 /** Return if the zone has any sensors in fail safe mode. */
84 virtual bool getFailSafeMode() const = 0;
85 /** Return the rpm or pwm percent value to drive fan pids when zone is in
86 * fail safe.
87 */
88 virtual double getFailSafePercent() const = 0;
89
Bonnie Lo0e8fc392022-10-05 10:20:55 +080090 /** Return the zone's cycle time settings */
91 virtual uint64_t getCycleIntervalTime(void) const = 0;
92 virtual uint64_t getUpdateThermalsCycle(void) const = 0;
93
Patrick Venture7a98c192020-08-12 08:35:16 -070094 /** Return if the zone is set to manual mode. false equates to automatic
95 * mode (the default).
96 */
97 virtual bool getManualMode(void) const = 0;
98
Josh Lehana4146eb2020-10-01 11:49:09 -070099 /** Returns true if a redundant fan PWM write is needed. Redundant write
100 * is used when returning the fan to automatic mode from manual mode.
101 */
102 virtual bool getRedundantWrite(void) const = 0;
103
Patrick Venture7a98c192020-08-12 08:35:16 -0700104 /** For each fan pid, do processing. */
105 virtual void processFans(void) = 0;
106 /** For each thermal pid, do processing. */
107 virtual void processThermals(void) = 0;
Patrick Venture1a153792020-08-11 08:41:47 -0700108};
109
110} // namespace pid_control