Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "sensors/sensor.hpp" |
| 4 | |
| 5 | #include <string> |
| 6 | |
| 7 | namespace pid_control |
| 8 | { |
| 9 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 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 | */ |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 14 | class ZoneInterface |
| 15 | { |
| 16 | public: |
| 17 | virtual ~ZoneInterface() = default; |
| 18 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 19 | /** If the zone implementation supports logging, initialize the log. */ |
| 20 | virtual void initializeLog(void) = 0; |
| 21 | /** If the zone implementation supports logging, write string to log. */ |
| 22 | virtual void writeLog(const std::string& value) = 0; |
| 23 | |
| 24 | /** Return a pointer to the sensor specified by name. */ |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 25 | virtual Sensor* getSensor(const std::string& name) = 0; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 26 | |
| 27 | /* updateFanTelemetry() and updateSensors() both clear the failsafe state |
| 28 | * for a sensor if it's no longer in that state. |
| 29 | */ |
| 30 | /** For each fan input in the zone, read each to update the cachedValue and |
| 31 | * check if the fan is beyond its timeout to trigger a failsafe condition. |
| 32 | */ |
| 33 | virtual void updateFanTelemetry(void) = 0; |
| 34 | /** For each thermal input in the zone, read each to update the cachedValue |
| 35 | * and check if the sensor is beyond its timeout to trigger a failsafe |
| 36 | * condition. |
| 37 | */ |
| 38 | virtual void updateSensors(void) = 0; |
| 39 | /** For each fan and thermal input in the zone, set the cachedValue to 0 and |
| 40 | * set the input as failsafe - to default the zone to failsafe before it |
| 41 | * starts processing values to control fans. |
| 42 | */ |
| 43 | virtual void initializeCache(void) = 0; |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 44 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 45 | /** Return cached value for sensor by name. */ |
| 46 | virtual double getCachedValue(const std::string& name) = 0; |
| 47 | |
| 48 | /** Add a set point value for the Max Set Point computation. */ |
| 49 | virtual void addSetPoint(double setpoint) = 0; |
| 50 | /** Clear all set points specified via addSetPoint */ |
| 51 | virtual void clearSetPoints(void) = 0; |
| 52 | |
| 53 | /** Add maximum RPM value to drive fan pids. */ |
| 54 | virtual void addRPMCeiling(double ceiling) = 0; |
| 55 | /** Clear any RPM value set with addRPMCeiling. */ |
| 56 | virtual void clearRPMCeilings(void) = 0; |
| 57 | |
| 58 | /** Compute the value returned by getMaxSetPointRequest - called from the |
| 59 | * looping mechanism before triggering any Fan PIDs. The value computed is |
| 60 | * used by each fan PID. |
| 61 | */ |
| 62 | virtual void determineMaxSetPointRequest(void) = 0; |
| 63 | /** Given the set points added via addSetPoint, return the maximum value - |
| 64 | * called from the PID loop that uses that value to drive the fans. |
| 65 | */ |
| 66 | virtual double getMaxSetPointRequest() const = 0; |
| 67 | |
| 68 | /** Return if the zone has any sensors in fail safe mode. */ |
| 69 | virtual bool getFailSafeMode() const = 0; |
| 70 | /** Return the rpm or pwm percent value to drive fan pids when zone is in |
| 71 | * fail safe. |
| 72 | */ |
| 73 | virtual double getFailSafePercent() const = 0; |
| 74 | |
| 75 | /** Return if the zone is set to manual mode. false equates to automatic |
| 76 | * mode (the default). |
| 77 | */ |
| 78 | virtual bool getManualMode(void) const = 0; |
| 79 | |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 80 | /** Returns true if a redundant fan PWM write is needed. Redundant write |
| 81 | * is used when returning the fan to automatic mode from manual mode. |
| 82 | */ |
| 83 | virtual bool getRedundantWrite(void) const = 0; |
| 84 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 85 | /** For each fan pid, do processing. */ |
| 86 | virtual void processFans(void) = 0; |
| 87 | /** For each thermal pid, do processing. */ |
| 88 | virtual void processThermals(void) = 0; |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace pid_control |