Add mapping logic, refactor stuff
This commit is contained in:
23
app/include/Mapping.h
Normal file
23
app/include/Mapping.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef MAPPING_H_
|
||||
#define MAPPING_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <fan/Fan.h>
|
||||
#include <fan/PwmControl.h>
|
||||
#include <sensor/Sensor.h>
|
||||
|
||||
class Mapping {
|
||||
public:
|
||||
std::vector<std::shared_ptr<Fan>>
|
||||
createMapping(std::vector<std::shared_ptr<Sensor>> rpmSensors,
|
||||
std::vector<std::shared_ptr<PwmControl>> pwmControls);
|
||||
|
||||
private:
|
||||
template <class Printable>
|
||||
void print(std::string listLabel,
|
||||
std::vector<std::shared_ptr<Printable>> list);
|
||||
};
|
||||
|
||||
#endif // MAPPING_H_
|
||||
11
app/include/Printable.h
Normal file
11
app/include/Printable.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef PRINTABLE_H_
|
||||
#define PRINTABLE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
class Printable {
|
||||
public:
|
||||
virtual const std::string toString() const = 0;
|
||||
};
|
||||
|
||||
#endif // PRINTABLE_H_
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef SENSORSWRAPPER_H_
|
||||
#define SENSORSWRAPPER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <sensors/sensors.h>
|
||||
|
||||
struct Sensor {
|
||||
sensors_chip_name chipName;
|
||||
sensors_feature feature;
|
||||
sensors_subfeature subFeature;
|
||||
};
|
||||
|
||||
class SensorsWrapper {
|
||||
public:
|
||||
SensorsWrapper();
|
||||
~SensorsWrapper();
|
||||
|
||||
std::vector<Sensor> getTemperatureSensors();
|
||||
int getValue(Sensor sensor);
|
||||
std::string getLabel(Sensor sensor);
|
||||
|
||||
private:
|
||||
std::vector<Sensor> mTemperatureSensors;
|
||||
std::vector<Sensor> mFanSensors;
|
||||
};
|
||||
|
||||
#endif // SENSORSWRAPPER_H_
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
class HwmonFan : public Fan {
|
||||
public:
|
||||
HwmonFan(std::unique_ptr<PwmControl> pwmControl,
|
||||
std::unique_ptr<Sensor> rpmSensor);
|
||||
HwmonFan(std::shared_ptr<PwmControl> pwmControl,
|
||||
std::shared_ptr<Sensor> rpmSensor);
|
||||
|
||||
void pwm(int percent) override;
|
||||
int rpm() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<PwmControl> mPwmControl;
|
||||
std::unique_ptr<Sensor> mRpmSensor;
|
||||
std::shared_ptr<PwmControl> mPwmControl;
|
||||
std::shared_ptr<Sensor> mRpmSensor;
|
||||
};
|
||||
|
||||
#endif // HWMONFAN_H_
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Printable.h>
|
||||
|
||||
enum class PWM_CONTROL_PROPERTY { CONTROL, ENABLE, MODE };
|
||||
enum class PWM_ENABLE { FULL_SPEED = 0, MANUAL_CONTROL };
|
||||
enum class PWM_MODE { DC = 0, PWM };
|
||||
|
||||
class PwmControl {
|
||||
class PwmControl : public Printable {
|
||||
public:
|
||||
PwmControl(std::string controlPath);
|
||||
|
||||
@@ -17,6 +19,8 @@ public:
|
||||
void enableManualControl();
|
||||
void reset();
|
||||
|
||||
const std::string toString() const override;
|
||||
|
||||
private:
|
||||
int readValue(std::string path);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
const sensors_subfeature *subfeature);
|
||||
|
||||
int value() override;
|
||||
std::string name() override;
|
||||
const std::string toString() const override;
|
||||
|
||||
private:
|
||||
const sensors_chip_name *mChipName;
|
||||
|
||||
@@ -9,7 +9,8 @@ public:
|
||||
~NvidiaSensor();
|
||||
|
||||
int value() override;
|
||||
std::string name() override;
|
||||
|
||||
const std::string toString() const override;
|
||||
};
|
||||
|
||||
#endif // NVIDIASENSOR_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
#ifndef SENSOR_H_
|
||||
#define SENSOR_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <Printable.h>
|
||||
|
||||
class Sensor {
|
||||
class Sensor : public Printable {
|
||||
public:
|
||||
// Read the current value
|
||||
virtual int value() = 0;
|
||||
// Name for displaying. Should be descriptive, e.g. "GPU" or the label from
|
||||
// libsensors.
|
||||
virtual std::string name() = 0;
|
||||
|
||||
virtual int max() const;
|
||||
virtual void max(int value);
|
||||
|
||||
protected:
|
||||
int mMax = 0;
|
||||
};
|
||||
|
||||
#endif // SENSOR_H_
|
||||
|
||||
26
app/include/sensor/SensorsWrapper.h
Normal file
26
app/include/sensor/SensorsWrapper.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef SENSORSWRAPPER_H_
|
||||
#define SENSORSWRAPPER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <sensors/sensors.h>
|
||||
|
||||
#include <fan/PwmControl.h>
|
||||
#include <sensor/Sensor.h>
|
||||
|
||||
class SensorsWrapper {
|
||||
public:
|
||||
SensorsWrapper();
|
||||
~SensorsWrapper();
|
||||
|
||||
std::vector<std::shared_ptr<Sensor>>
|
||||
Sensors(sensors_subfeature_type sensorType);
|
||||
|
||||
std::vector<std::shared_ptr<PwmControl>> PwmControls();
|
||||
|
||||
private:
|
||||
FILE *mConfigFile;
|
||||
};
|
||||
|
||||
#endif // SENSORSWRAPPER_H_
|
||||
Reference in New Issue
Block a user