Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "sensors/sensor.hpp" |
| 4 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 5 | #include <map> |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | |
| 8 | namespace pid_control |
| 9 | { |
| 10 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 11 | /** |
| 12 | * In a Zone you have a set of PIDs which feed each other. Fan PIDs are fed set |
| 13 | * points from Thermal PIDs. |
| 14 | */ |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 15 | class ZoneInterface |
| 16 | { |
| 17 | public: |
| 18 | virtual ~ZoneInterface() = default; |
| 19 | |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 20 | /** Get Current Zone ID */ |
| 21 | virtual int64_t getZoneID(void) const = 0; |
| 22 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 23 | /** If the zone implementation supports logging, initialize the log. */ |
| 24 | virtual void initializeLog(void) = 0; |
| 25 | /** If the zone implementation supports logging, write string to log. */ |
| 26 | virtual void writeLog(const std::string& value) = 0; |
| 27 | |
| 28 | /** Return a pointer to the sensor specified by name. */ |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 29 | virtual Sensor* getSensor(const std::string& name) = 0; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 30 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 31 | /** Return the list of sensor names in the zone. */ |
| 32 | virtual std::vector<std::string> getSensorNames(void) = 0; |
| 33 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 34 | /* updateFanTelemetry() and updateSensors() both clear the failsafe state |
| 35 | * for a sensor if it's no longer in that state. |
| 36 | */ |
| 37 | /** For each fan input in the zone, read each to update the cachedValue and |
| 38 | * check if the fan is beyond its timeout to trigger a failsafe condition. |
| 39 | */ |
| 40 | virtual void updateFanTelemetry(void) = 0; |
| 41 | /** For each thermal input in the zone, read each to update the cachedValue |
| 42 | * and check if the sensor is beyond its timeout to trigger a failsafe |
| 43 | * condition. |
| 44 | */ |
| 45 | virtual void updateSensors(void) = 0; |
| 46 | /** For each fan and thermal input in the zone, set the cachedValue to 0 and |
| 47 | * set the input as failsafe - to default the zone to failsafe before it |
| 48 | * starts processing values to control fans. |
| 49 | */ |
| 50 | virtual void initializeCache(void) = 0; |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 51 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 52 | /** Optionally adds fan outputs to an output cache, which is different |
| 53 | * from the input cache accessed by getCachedValue(), so it is possible |
| 54 | * to have entries with the same name in both the output cache and |
| 55 | * the input cache. The output cache is used for logging, to show |
| 56 | * the PWM values determined by the PID loop, next to the resulting RPM. |
| 57 | */ |
| 58 | virtual void setOutputCache(std::string_view name, |
| 59 | const ValueCacheEntry& values) = 0; |
| 60 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 61 | /** Return cached value for sensor by name. */ |
| 62 | virtual double getCachedValue(const std::string& name) = 0; |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 63 | /** Return cached values, both scaled and original unscaled values, |
| 64 | * for sensor by name. Subclasses can add trivial return {value, value}, |
| 65 | * for subclasses that only implement getCachedValue() and do not care |
| 66 | * about maintaining the distinction between scaled and unscaled values. |
| 67 | */ |
| 68 | virtual ValueCacheEntry getCachedValues(const std::string& name) = 0; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 69 | |
| 70 | /** Add a set point value for the Max Set Point computation. */ |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 71 | virtual void addSetPoint(double setpoint, const std::string& name) = 0; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 72 | /** Clear all set points specified via addSetPoint */ |
| 73 | virtual void clearSetPoints(void) = 0; |
| 74 | |
| 75 | /** Add maximum RPM value to drive fan pids. */ |
| 76 | virtual void addRPMCeiling(double ceiling) = 0; |
| 77 | /** Clear any RPM value set with addRPMCeiling. */ |
| 78 | virtual void clearRPMCeilings(void) = 0; |
| 79 | |
| 80 | /** Compute the value returned by getMaxSetPointRequest - called from the |
| 81 | * looping mechanism before triggering any Fan PIDs. The value computed is |
| 82 | * used by each fan PID. |
| 83 | */ |
| 84 | virtual void determineMaxSetPointRequest(void) = 0; |
| 85 | /** Given the set points added via addSetPoint, return the maximum value - |
| 86 | * called from the PID loop that uses that value to drive the fans. |
| 87 | */ |
| 88 | virtual double getMaxSetPointRequest() const = 0; |
| 89 | |
| 90 | /** Return if the zone has any sensors in fail safe mode. */ |
| 91 | virtual bool getFailSafeMode() const = 0; |
| 92 | /** Return the rpm or pwm percent value to drive fan pids when zone is in |
| 93 | * fail safe. |
| 94 | */ |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 95 | virtual double getFailSafePercent() = 0; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 96 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 97 | /** Return failsafe sensor list */ |
| 98 | virtual std::map<std::string, std::pair<std::string, double>> |
| 99 | getFailSafeSensors() const = 0; |
| 100 | |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 101 | /** Return the zone's cycle time settings */ |
| 102 | virtual uint64_t getCycleIntervalTime(void) const = 0; |
| 103 | virtual uint64_t getUpdateThermalsCycle(void) const = 0; |
| 104 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 105 | /** Return if the zone is set to manual mode. false equates to automatic |
| 106 | * mode (the default). |
| 107 | */ |
| 108 | virtual bool getManualMode(void) const = 0; |
| 109 | |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 110 | /** Returns true if a redundant fan PWM write is needed. Redundant write |
| 111 | * is used when returning the fan to automatic mode from manual mode. |
| 112 | */ |
| 113 | virtual bool getRedundantWrite(void) const = 0; |
| 114 | |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 115 | /** Returns true if user wants to accumulate the output PWM of different |
| 116 | * controllers with same sensor |
| 117 | */ |
| 118 | virtual bool getAccSetPoint(void) const = 0; |
| 119 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 120 | /** For each fan pid, do processing. */ |
| 121 | virtual void processFans(void) = 0; |
| 122 | /** For each thermal pid, do processing. */ |
| 123 | virtual void processThermals(void) = 0; |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 124 | |
| 125 | /** Update thermal/power debug dbus properties */ |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 126 | virtual void updateThermalPowerDebugInterface( |
| 127 | std::string pidName, std::string leader, double input, |
| 128 | double output) = 0; |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace pid_control |