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