11a153794SPatrick Venture #pragma once 21a153794SPatrick Venture 31a153794SPatrick Venture #include "sensors/sensor.hpp" 41a153794SPatrick Venture 51a153794SPatrick Venture #include <string> 61a153794SPatrick Venture 71a153794SPatrick Venture namespace pid_control 81a153794SPatrick Venture { 91a153794SPatrick Venture 107a98c19aSPatrick Venture /** 117a98c19aSPatrick Venture * In a Zone you have a set of PIDs which feed each other. Fan PIDs are fed set 127a98c19aSPatrick Venture * points from Thermal PIDs. 137a98c19aSPatrick Venture */ 141a153794SPatrick Venture class ZoneInterface 151a153794SPatrick Venture { 161a153794SPatrick Venture public: 171a153794SPatrick Venture virtual ~ZoneInterface() = default; 181a153794SPatrick Venture 19c51ba919SBonnie Lo /** Get Current Zone ID */ 20c51ba919SBonnie Lo virtual int64_t getZoneID(void) const = 0; 21c51ba919SBonnie Lo 227a98c19aSPatrick Venture /** If the zone implementation supports logging, initialize the log. */ 237a98c19aSPatrick Venture virtual void initializeLog(void) = 0; 247a98c19aSPatrick Venture /** If the zone implementation supports logging, write string to log. */ 257a98c19aSPatrick Venture virtual void writeLog(const std::string& value) = 0; 267a98c19aSPatrick Venture 277a98c19aSPatrick Venture /** Return a pointer to the sensor specified by name. */ 281a153794SPatrick Venture virtual Sensor* getSensor(const std::string& name) = 0; 297a98c19aSPatrick Venture 30*6df8bb50SJames Zheng /** Return the list of sensor names in the zone. */ 31*6df8bb50SJames Zheng virtual std::vector<std::string> getSensorNames(void) = 0; 32*6df8bb50SJames Zheng 337a98c19aSPatrick Venture /* updateFanTelemetry() and updateSensors() both clear the failsafe state 347a98c19aSPatrick Venture * for a sensor if it's no longer in that state. 357a98c19aSPatrick Venture */ 367a98c19aSPatrick Venture /** For each fan input in the zone, read each to update the cachedValue and 377a98c19aSPatrick Venture * check if the fan is beyond its timeout to trigger a failsafe condition. 387a98c19aSPatrick Venture */ 397a98c19aSPatrick Venture virtual void updateFanTelemetry(void) = 0; 407a98c19aSPatrick Venture /** For each thermal input in the zone, read each to update the cachedValue 417a98c19aSPatrick Venture * and check if the sensor is beyond its timeout to trigger a failsafe 427a98c19aSPatrick Venture * condition. 437a98c19aSPatrick Venture */ 447a98c19aSPatrick Venture virtual void updateSensors(void) = 0; 457a98c19aSPatrick Venture /** For each fan and thermal input in the zone, set the cachedValue to 0 and 467a98c19aSPatrick Venture * set the input as failsafe - to default the zone to failsafe before it 477a98c19aSPatrick Venture * starts processing values to control fans. 487a98c19aSPatrick Venture */ 497a98c19aSPatrick Venture virtual void initializeCache(void) = 0; 50a4146eb1SJosh Lehan 51b300575eSJosh Lehan /** Optionally adds fan outputs to an output cache, which is different 52b300575eSJosh Lehan * from the input cache accessed by getCachedValue(), so it is possible 53b300575eSJosh Lehan * to have entries with the same name in both the output cache and 54b300575eSJosh Lehan * the input cache. The output cache is used for logging, to show 55b300575eSJosh Lehan * the PWM values determined by the PID loop, next to the resulting RPM. 56b300575eSJosh Lehan */ 57b300575eSJosh Lehan virtual void setOutputCache(std::string_view name, 58b300575eSJosh Lehan const ValueCacheEntry& values) = 0; 59b300575eSJosh Lehan 607a98c19aSPatrick Venture /** Return cached value for sensor by name. */ 617a98c19aSPatrick Venture virtual double getCachedValue(const std::string& name) = 0; 62b300575eSJosh Lehan /** Return cached values, both scaled and original unscaled values, 63b300575eSJosh Lehan * for sensor by name. Subclasses can add trivial return {value, value}, 64b300575eSJosh Lehan * for subclasses that only implement getCachedValue() and do not care 65b300575eSJosh Lehan * about maintaining the distinction between scaled and unscaled values. 66b300575eSJosh Lehan */ 67b300575eSJosh Lehan virtual ValueCacheEntry getCachedValues(const std::string& name) = 0; 687a98c19aSPatrick Venture 697a98c19aSPatrick Venture /** Add a set point value for the Max Set Point computation. */ 70ccc8bb62SNirav Shah virtual void addSetPoint(double setpoint, const std::string& name) = 0; 717a98c19aSPatrick Venture /** Clear all set points specified via addSetPoint */ 727a98c19aSPatrick Venture virtual void clearSetPoints(void) = 0; 737a98c19aSPatrick Venture 747a98c19aSPatrick Venture /** Add maximum RPM value to drive fan pids. */ 757a98c19aSPatrick Venture virtual void addRPMCeiling(double ceiling) = 0; 767a98c19aSPatrick Venture /** Clear any RPM value set with addRPMCeiling. */ 777a98c19aSPatrick Venture virtual void clearRPMCeilings(void) = 0; 787a98c19aSPatrick Venture 797a98c19aSPatrick Venture /** Compute the value returned by getMaxSetPointRequest - called from the 807a98c19aSPatrick Venture * looping mechanism before triggering any Fan PIDs. The value computed is 817a98c19aSPatrick Venture * used by each fan PID. 827a98c19aSPatrick Venture */ 837a98c19aSPatrick Venture virtual void determineMaxSetPointRequest(void) = 0; 847a98c19aSPatrick Venture /** Given the set points added via addSetPoint, return the maximum value - 857a98c19aSPatrick Venture * called from the PID loop that uses that value to drive the fans. 867a98c19aSPatrick Venture */ 877a98c19aSPatrick Venture virtual double getMaxSetPointRequest() const = 0; 887a98c19aSPatrick Venture 897a98c19aSPatrick Venture /** Return if the zone has any sensors in fail safe mode. */ 907a98c19aSPatrick Venture virtual bool getFailSafeMode() const = 0; 917a98c19aSPatrick Venture /** Return the rpm or pwm percent value to drive fan pids when zone is in 927a98c19aSPatrick Venture * fail safe. 937a98c19aSPatrick Venture */ 9492f9f3c8SHarvey Wu virtual double getFailSafePercent() = 0; 957a98c19aSPatrick Venture 960e8fc398SBonnie Lo /** Return the zone's cycle time settings */ 970e8fc398SBonnie Lo virtual uint64_t getCycleIntervalTime(void) const = 0; 980e8fc398SBonnie Lo virtual uint64_t getUpdateThermalsCycle(void) const = 0; 990e8fc398SBonnie Lo 1007a98c19aSPatrick Venture /** Return if the zone is set to manual mode. false equates to automatic 1017a98c19aSPatrick Venture * mode (the default). 1027a98c19aSPatrick Venture */ 1037a98c19aSPatrick Venture virtual bool getManualMode(void) const = 0; 1047a98c19aSPatrick Venture 105a4146eb1SJosh Lehan /** Returns true if a redundant fan PWM write is needed. Redundant write 106a4146eb1SJosh Lehan * is used when returning the fan to automatic mode from manual mode. 107a4146eb1SJosh Lehan */ 108a4146eb1SJosh Lehan virtual bool getRedundantWrite(void) const = 0; 109a4146eb1SJosh Lehan 1109788963cSDelphine CC Chiu /** Returns true if user wants to accumulate the output PWM of different 1119788963cSDelphine CC Chiu * controllers with same sensor 1129788963cSDelphine CC Chiu */ 1139788963cSDelphine CC Chiu virtual bool getAccSetPoint(void) const = 0; 1149788963cSDelphine CC Chiu 1157a98c19aSPatrick Venture /** For each fan pid, do processing. */ 1167a98c19aSPatrick Venture virtual void processFans(void) = 0; 1177a98c19aSPatrick Venture /** For each thermal pid, do processing. */ 1187a98c19aSPatrick Venture virtual void processThermals(void) = 0; 11937180062SHarvey Wu 12037180062SHarvey Wu /** Update thermal/power debug dbus properties */ 121bd63bcacSPatrick Williams virtual void updateThermalPowerDebugInterface( 122bd63bcacSPatrick Williams std::string pidName, std::string leader, double input, 12337180062SHarvey Wu double output) = 0; 1241a153794SPatrick Venture }; 1251a153794SPatrick Venture 1261a153794SPatrick Venture } // namespace pid_control 127