blob: 861dde709d69df1fec5d2e4538010e8f916a3096 [file] [log] [blame]
Patrick Venture1a153792020-08-11 08:41:47 -07001#pragma once
2
Ed Tanousf8b6e552025-06-27 13:27:50 -07003#include "interfaces.hpp"
Patrick Venture1a153792020-08-11 08:41:47 -07004#include "sensors/sensor.hpp"
5
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <cstdint>
Harvey Wua4270072024-05-29 16:11:13 +08007#include <map>
Patrick Venture1a153792020-08-11 08:41:47 -07008#include <string>
Ed Tanousf8b6e552025-06-27 13:27:50 -07009#include <string_view>
10#include <utility>
11#include <vector>
Patrick Venture1a153792020-08-11 08:41:47 -070012
13namespace pid_control
14{
15
Patrick Venture7a98c192020-08-12 08:35:16 -070016/**
17 * In a Zone you have a set of PIDs which feed each other. Fan PIDs are fed set
18 * points from Thermal PIDs.
19 */
Patrick Venture1a153792020-08-11 08:41:47 -070020class ZoneInterface
21{
22 public:
23 virtual ~ZoneInterface() = default;
24
Bonnie Loc51ba912022-10-12 14:07:22 +080025 /** Get Current Zone ID */
26 virtual int64_t getZoneID(void) const = 0;
27
Patrick Venture7a98c192020-08-12 08:35:16 -070028 /** If the zone implementation supports logging, initialize the log. */
29 virtual void initializeLog(void) = 0;
30 /** If the zone implementation supports logging, write string to log. */
31 virtual void writeLog(const std::string& value) = 0;
32
33 /** Return a pointer to the sensor specified by name. */
Patrick Venture1a153792020-08-11 08:41:47 -070034 virtual Sensor* getSensor(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070035
James Zheng6df8bb52024-11-27 23:38:47 +000036 /** Return the list of sensor names in the zone. */
37 virtual std::vector<std::string> getSensorNames(void) = 0;
38
Patrick Venture7a98c192020-08-12 08:35:16 -070039 /* updateFanTelemetry() and updateSensors() both clear the failsafe state
40 * for a sensor if it's no longer in that state.
41 */
42 /** For each fan input in the zone, read each to update the cachedValue and
43 * check if the fan is beyond its timeout to trigger a failsafe condition.
44 */
45 virtual void updateFanTelemetry(void) = 0;
46 /** For each thermal input in the zone, read each to update the cachedValue
47 * and check if the sensor is beyond its timeout to trigger a failsafe
48 * condition.
49 */
50 virtual void updateSensors(void) = 0;
51 /** For each fan and thermal input in the zone, set the cachedValue to 0 and
52 * set the input as failsafe - to default the zone to failsafe before it
53 * starts processing values to control fans.
54 */
55 virtual void initializeCache(void) = 0;
Josh Lehana4146eb2020-10-01 11:49:09 -070056
Josh Lehanb3005752022-02-22 20:48:07 -080057 /** Optionally adds fan outputs to an output cache, which is different
58 * from the input cache accessed by getCachedValue(), so it is possible
59 * to have entries with the same name in both the output cache and
60 * the input cache. The output cache is used for logging, to show
61 * the PWM values determined by the PID loop, next to the resulting RPM.
62 */
63 virtual void setOutputCache(std::string_view name,
64 const ValueCacheEntry& values) = 0;
65
Patrick Venture7a98c192020-08-12 08:35:16 -070066 /** Return cached value for sensor by name. */
67 virtual double getCachedValue(const std::string& name) = 0;
Josh Lehanb3005752022-02-22 20:48:07 -080068 /** Return cached values, both scaled and original unscaled values,
69 * for sensor by name. Subclasses can add trivial return {value, value},
70 * for subclasses that only implement getCachedValue() and do not care
71 * about maintaining the distinction between scaled and unscaled values.
72 */
73 virtual ValueCacheEntry getCachedValues(const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070074
75 /** Add a set point value for the Max Set Point computation. */
Nirav Shahccc8bb62022-02-17 21:06:51 -080076 virtual void addSetPoint(double setpoint, const std::string& name) = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -070077 /** Clear all set points specified via addSetPoint */
78 virtual void clearSetPoints(void) = 0;
79
80 /** Add maximum RPM value to drive fan pids. */
81 virtual void addRPMCeiling(double ceiling) = 0;
82 /** Clear any RPM value set with addRPMCeiling. */
83 virtual void clearRPMCeilings(void) = 0;
84
85 /** Compute the value returned by getMaxSetPointRequest - called from the
86 * looping mechanism before triggering any Fan PIDs. The value computed is
87 * used by each fan PID.
88 */
89 virtual void determineMaxSetPointRequest(void) = 0;
90 /** Given the set points added via addSetPoint, return the maximum value -
91 * called from the PID loop that uses that value to drive the fans.
92 */
93 virtual double getMaxSetPointRequest() const = 0;
94
95 /** Return if the zone has any sensors in fail safe mode. */
96 virtual bool getFailSafeMode() const = 0;
97 /** Return the rpm or pwm percent value to drive fan pids when zone is in
98 * fail safe.
99 */
Harvey Wu92f9f3c2023-11-07 09:23:35 +0800100 virtual double getFailSafePercent() = 0;
Patrick Venture7a98c192020-08-12 08:35:16 -0700101
Harvey Wua4270072024-05-29 16:11:13 +0800102 /** Return failsafe sensor list */
103 virtual std::map<std::string, std::pair<std::string, double>>
104 getFailSafeSensors() const = 0;
105
Bonnie Lo0e8fc392022-10-05 10:20:55 +0800106 /** Return the zone's cycle time settings */
107 virtual uint64_t getCycleIntervalTime(void) const = 0;
108 virtual uint64_t getUpdateThermalsCycle(void) const = 0;
109
Patrick Venture7a98c192020-08-12 08:35:16 -0700110 /** Return if the zone is set to manual mode. false equates to automatic
111 * mode (the default).
112 */
113 virtual bool getManualMode(void) const = 0;
114
Josh Lehana4146eb2020-10-01 11:49:09 -0700115 /** Returns true if a redundant fan PWM write is needed. Redundant write
116 * is used when returning the fan to automatic mode from manual mode.
117 */
118 virtual bool getRedundantWrite(void) const = 0;
119
Delphine CC Chiu97889632023-11-06 11:32:46 +0800120 /** Returns true if user wants to accumulate the output PWM of different
121 * controllers with same sensor
122 */
123 virtual bool getAccSetPoint(void) const = 0;
124
Patrick Venture7a98c192020-08-12 08:35:16 -0700125 /** For each fan pid, do processing. */
126 virtual void processFans(void) = 0;
127 /** For each thermal pid, do processing. */
128 virtual void processThermals(void) = 0;
Harvey Wu37180062023-10-02 09:42:50 +0800129
130 /** Update thermal/power debug dbus properties */
Patrick Williamsbd63bca2024-08-16 15:21:10 -0400131 virtual void updateThermalPowerDebugInterface(
132 std::string pidName, std::string leader, double input,
133 double output) = 0;
Patrick Venture1a153792020-08-11 08:41:47 -0700134};
135
136} // namespace pid_control