diff --git a/mainwindow.cpp b/mainwindow.cpp index cada3d2..f96f1f0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,6 +5,7 @@ #include "newprofile.h" #include "monitor.h" #include "plotwidget.h" +#include "nvidia.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -59,6 +60,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int))); connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor())); + + nvidia nv; + nv.setupXNVCtrl(); } MainWindow::~MainWindow() diff --git a/nvidia.cpp b/nvidia.cpp new file mode 100644 index 0000000..a688ea4 --- /dev/null +++ b/nvidia.cpp @@ -0,0 +1,177 @@ +#include "nvidia.h" +#include + +#include "NVCtrl/NVCtrlLib.h" + +nvidia::nvidia(QObject *parent) : QObject(parent) +{ + +} +bool nvidia::setupXNVCtrl() +{ + // Open the x-server connection and check if the extension exists + dpy = XOpenDisplay(nullptr); + Bool ret; + int *event_basep = nullptr; + int *error_basep = nullptr; + + ret = XNVCTRLQueryExtension(dpy, + event_basep, + error_basep); + qDebug() << ret; + + queryGPUCount(); + queryGPUNames(); + queryGPUUIDs(); + queryGPUFeatures(); + return ret; +} +void nvidia::queryGPUCount() +{ + Bool ret; + ret = XNVCTRLQueryTargetCount(dpy, NV_CTRL_TARGET_TYPE_GPU, &gpuCount); + if (!ret) { + qDebug() << "Failed to query amount of GPUs"; + } + // Create an appropriate number of GPU objects + for (int i=0; i> (32 - 16); + qDebug() << GPUList[GPUIndex].coreFreq << "freq" << core << mem; + GPUList[GPUIndex].coreFreq = core; + GPUList[GPUIndex].memFreq = mem; +} +void nvidia::queryGPUFanSpeed(int GPUIndex) +{ + Bool ret; + ret = XNVCTRLQueryTargetAttribute(dpy, + NV_CTRL_TARGET_TYPE_COOLER, + GPUIndex, + 0, + NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL, + &GPUList[GPUIndex].fanSpeed); + + qDebug() << GPUList[GPUIndex].fanSpeed; +} +bool nvidia::assignFanSpeed(int GPUIndex, int targetValue) +{ + Bool ret; + ret = XNVCTRLSetTargetAttributeAndGetStatus(dpy, + NV_CTRL_TARGET_TYPE_COOLER, + GPUIndex, + 0, + NV_CTRL_THERMAL_COOLER_LEVEL, + targetValue); + return ret; +} +/*bool nvidia::setup() +{ + dpy = XOpenDisplay(nullptr); + int *temp; + XNVCTRLQueryTargetAttribute(dpy, + NV_CTRL_TARGET_TYPE_THERMAL_SENSOR, + 0, + 0, + NV_CTRL_THERMAL_SENSOR_READING, + temp); + qDebug() << temp; + return true; +}*/ diff --git a/nvidia.h b/nvidia.h new file mode 100644 index 0000000..602e489 --- /dev/null +++ b/nvidia.h @@ -0,0 +1,51 @@ +#ifndef NVIDIA_H +#define NVIDIA_H + +#include +#include +#include + +class nvidia : public QObject +{ + Q_OBJECT +public: + explicit nvidia(QObject *parent = nullptr); + + struct GPU + { + bool status; + int index; + char *name; + char *uuid; + bool overVoltAvailable; + bool overClockAvailable; + int maxVoltageOffset; + + int coreFreq; + int memFreq; + int temp; + int voltage; + int fanSpeed; + }; + QVector GPUList; + int gpuCount = 0; +private: + Display *dpy; +signals: + +public slots: + bool setupXNVCtrl(); + void queryGPUCount(); + void queryGPUNames(); + void queryGPUUIDs(); + void queryGPUFeatures(); + void queryGPUVoltage(int GPUIndex); + void queryGPUTemp(int GPUIndex); + void queryGPUFrequency(int GPUIndex); + void queryGPUFanSpeed(int GPUIndex); + + bool assignFanSpeed(int GPUIndex, int targetValue); +private slots: +}; + +#endif // NVIDIA_H diff --git a/rojekti.pro b/rojekti.pro index 519e387..8a876a9 100644 --- a/rojekti.pro +++ b/rojekti.pro @@ -34,7 +34,7 @@ SOURCES += \ newprofile.cpp \ monitor.cpp \ plotwidget.cpp \ - #nvidia.cpp + nvidia.cpp HEADERS += \ mainwindow.h \ @@ -43,16 +43,16 @@ HEADERS += \ newprofile.h \ monitor.h \ plotwidget.h \ - #nvidia.h + nvidia.h FORMS += \ mainwindow.ui \ editprofile.ui \ newprofile.ui -#INCLUDEPATH += "/usr/lib" +INCLUDEPATH += "/usr/lib" -#LIBS += -lXext -lXNVCtrl -lX11 +LIBS += -lXext -lXNVCtrl -lX11 # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin