blob: 179c85689f5716cfcc4973fa330c5d4f148f3e63 [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
Bonnie Loc51ba912022-10-12 14:07:22 +080019 /** Get Current Zone ID */
20 virtual int64_t getZoneID(void) const = 0;
21
Patrick Venture7a98c192020-08-12 08:35:16 -070022 /** If the zone implementation supports logging, initialize the log. */
23 virtual void initializeLog(void) = 0;
24 /** If the zone implementation supports logging, write string to log. */
25 virtual void writeLog(const std::string& value) = 0;
26
27 /** Return a pointer to the sensor specified by name. */
Patrick Venture1a153792020-08-11 08:41:47 -070028 virtual Sensor* getSensor(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070029
30 /* updateFanTelemetry() and updateSensors() both clear the failsafe state
31 * for a sensor if it's no longer in that state.
32 */
33 /** For each fan input in the zone, read each to update the cachedValue and
34 * check if the fan is beyond its timeout to trigger a failsafe condition.
35 */
36 virtual void updateFanTelemetry(void) = 0;
37 /** For each thermal input in the zone, read each to update the cachedValue
38 * and check if the sensor is beyond its timeout to trigger a failsafe
39 * condition.
40 */
41 virtual void updateSensors(void) = 0;
42 /** For each fan and thermal input in the zone, set the cachedValue to 0 and
43 * set the input as failsafe - to default the zone to failsafe before it
44 * starts processing values to control fans.
45 */
46 virtual void initializeCache(void) = 0;
Josh Lehana4146eb2020-10-01 11:49:09 -070047
Josh Lehanb3005752022-02-22 20:48:07 -080048 /** Optionally adds fan outputs to an output cache, which is different
49 * from the input cache accessed by getCachedValue(), so it is possible
50 * to have entries with the same name in both the output cache and
51 * the input cache. The output cache is used for logging, to show
52 * the PWM values determined by the PID loop, next to the resulting RPM.
53 */
54 virtual void setOutputCache(std::string_view name,
55 const ValueCacheEntry& values) = 0;
56
Patrick Venture7a98c192020-08-12 08:35:16 -070057 /** Return cached value for sensor by name. */
58 virtual double getCachedValue(const std::string& name) = 0;
Josh Lehanb3005752022-02-22 20:48:07 -080059 /** Return cached values, both scaled and original unscaled values,
60 * for sensor by name. Subclasses can add trivial return {value, value},
61 * for subclasses that only implement getCachedValue() and do not care
62 * about maintaining the distinction between scaled and unscaled values.
63 */
64 virtual ValueCacheEntry getCachedValues(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070065
66 /** Add a set point value for the Max Set Point computation. */
Nirav Shahccc8bb62022-02-17 21:06:51 -080067 virtual void addSetPoint(double setpoint, const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070068 /** Clear all set points specified via addSetPoint */
69 virtual void clearSetPoints(void) = 0;
70
71 /** Add maximum RPM value to drive fan pids. */
72 virtual void addRPMCeiling(double ceiling) = 0;
73 /** Clear any RPM value set with addRPMCeiling. */
74 virtual void clearRPMCeilings(void) = 0;
75
76 /** Compute the value returned by getMaxSetPointRequest - called from the
77 * looping mechanism before triggering any Fan PIDs. The value computed is
78 * used by each fan PID.
79 */
80 virtual void determineMaxSetPointRequest(void) = 0;
81 /** Given the set points added via addSetPoint, return the maximum value -
82 * called from the PID loop that uses that value to drive the fans.
83 */
84 virtual double getMaxSetPointRequest() const = 0;
85
86 /** Return if the zone has any sensors in fail safe mode. */
87 virtual bool getFailSafeMode() const = 0;
88 /** Return the rpm or pwm percent value to drive fan pids when zone is in
89 * fail safe.
90 */
91 virtual double getFailSafePercent() const = 0;
92
Bonnie Lo0e8fc392022-10-05 10:20:55 +080093 /** Return the zone's cycle time settings */
94 virtual uint64_t getCycleIntervalTime(void) const = 0;
95 virtual uint64_t getUpdateThermalsCycle(void) const = 0;
96
Patrick Venture7a98c192020-08-12 08:35:16 -070097 /** Return if the zone is set to manual mode. false equates to automatic
98 * mode (the default).
99 */
100 virtual bool getManualMode(void) const = 0;
101
Josh Lehana4146eb2020-10-01 11:49:09 -0700102 /** Returns true if a redundant fan PWM write is needed. Redundant write
103 * is used when returning the fan to automatic mode from manual mode.
104 */
105 virtual bool getRedundantWrite(void) const = 0;
106
Patrick Venture7a98c192020-08-12 08:35:16 -0700107 /** For each fan pid, do processing. */
108 virtual void processFans(void) = 0;
109 /** For each thermal pid, do processing. */
110 virtual void processThermals(void) = 0;
Patrick Venture1a153792020-08-11 08:41:47 -0700111};
112
113} // namespace pid_control