-
Notifications
You must be signed in to change notification settings - Fork 16
/
nvocdialog.cpp
173 lines (152 loc) · 5.65 KB
/
nvocdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "nvocdialog.h"
#include "ui_nvocdialog.h"
#include <QDebug>
nvOCDialog::nvOCDialog(nvidiaAPI *nvapi, QSettings *settings, QWidget *parent) :
QDialog(parent),
ui(new Ui::nvOCDialog),
_gpuIndex(0),
_settings(settings),
_nvapi(nvapi)
{
ui->setupUi(this);
setFixedSize(size());
unsigned int deviceNumber = _nvapi->getGPUCount();
if(deviceNumber)
{
for(unsigned int i = 0; i < deviceNumber; i++)
{
nvCard card;
card.gpuOffset = 0;
card.memOffset = 0;
card.powerOffset = 100;
card.fanSpeed = 50;
_cardList << card;
ui->comboBoxDevice->addItem(QString("device " + QString::number(i)));
}
updateSliders(0);
}
_settings->beginGroup("nvoc");
ui->checkBoxAllDevices->setChecked(_settings->value("nvoc_applyall").toBool());
ui->checkBoxOCMinerStart->setChecked(_settings->value("nvoc_applyonstart").toBool());
ui->checkBoxAutoSpeedFan->setChecked(_settings->value("fanspeed0").toInt() == 101 ? true : false);
if(_settings->value("fanspeed0").toInt() == 101) ui->horizontalSliderFanSpeed->hide();
_settings->endGroup();
}
nvOCDialog::~nvOCDialog()
{
delete ui;
}
void nvOCDialog::on_horizontalSliderPowerPercent_valueChanged(int value)
{
ui->lcdNumberPowerPercent->display(value);
_cardList[_gpuIndex].powerOffset = value;
}
void nvOCDialog::on_horizontalSliderGpuOffset_valueChanged(int value)
{
ui->lcdNumberGpuOffset->display(value);
_cardList[_gpuIndex].gpuOffset = value;
}
void nvOCDialog::on_horizontalSliderMemOffset_valueChanged(int value)
{
ui->lcdNumberMemClock->display(value);
_cardList[_gpuIndex].memOffset = value;
}
void nvOCDialog::on_horizontalSliderFanSpeed_valueChanged(int value)
{
ui->lcdNumberFanSpeed->display(value);
_cardList[_gpuIndex].fanSpeed = value;
}
void nvOCDialog::on_comboBoxDevice_activated(int index)
{
updateSliders(index);
_gpuIndex = index;
}
void nvOCDialog::updateSliders(unsigned int gpu)
{
int plimit = _nvapi->getPowerLimit(gpu);
int gpuoffset = _nvapi->getGPUOffset(gpu);
int memoffset = _nvapi->getMemOffset(gpu);
int fanspeed = _nvapi->getFanSpeed(gpu);
ui->horizontalSliderPowerPercent->setValue(plimit);
ui->horizontalSliderGpuOffset->setValue(gpuoffset);
ui->horizontalSliderMemOffset->setValue(memoffset);
ui->horizontalSliderFanSpeed->setValue(fanspeed);
}
void nvOCDialog::saveConfig()
{
int deviceIndex = ui->comboBoxDevice->currentIndex();
_settings->beginGroup("nvoc");
_settings->setValue("nvoc_applyall", ui->checkBoxAllDevices->isChecked());
_settings->setValue("nvoc_applyonstart", ui->checkBoxOCMinerStart->isChecked());
if(ui->checkBoxAllDevices->isChecked())
{
for(int i = 0; i < _cardList.size(); i++)
{
_settings->setValue(QString("powerlimitoffset" + QString::number(i)), _cardList.at(deviceIndex).powerOffset);
_settings->setValue(QString("gpuoffset" + QString::number(i)), _cardList.at(deviceIndex).gpuOffset);
_settings->setValue(QString("memoffset" + QString::number(i)), _cardList.at(deviceIndex).memOffset);
_settings->setValue(QString("fanspeed" + QString::number(i)), ui->checkBoxAutoSpeedFan->isChecked() ? 101 : _cardList.at(deviceIndex).fanSpeed);
}
}
else
{
_settings->setValue(QString("powerlimitoffset" + QString::number(deviceIndex)), _cardList.at(deviceIndex).powerOffset);
_settings->setValue(QString("gpuoffset" + QString::number(deviceIndex)), _cardList.at(deviceIndex).gpuOffset);
_settings->setValue(QString("memoffset" + QString::number(deviceIndex)), _cardList.at(deviceIndex).memOffset);
_settings->setValue(QString("fanspeed" + QString::number(deviceIndex)), ui->checkBoxAutoSpeedFan->isChecked() ? 101 : _cardList.at(deviceIndex).fanSpeed);
}
_settings->endGroup();
}
// Apply settings
void nvOCDialog::on_buttonBox_clicked(QAbstractButton *button)
{
if(button == (QAbstractButton*)ui->buttonBox->button(QDialogButtonBox::Apply))
{
int gpu = ui->comboBoxDevice->currentIndex();
if(ui->checkBoxAllDevices->isChecked())
{
for(unsigned int i = 0; i < _nvapi->getGPUCount(); i++)
{
_nvapi->setPowerLimitPercent(i, ui->horizontalSliderPowerPercent->value());
_nvapi->setGPUOffset(i, ui->horizontalSliderGpuOffset->value());
_nvapi->setMemClockOffset(i, ui->horizontalSliderMemOffset->value());
if(ui->checkBoxAutoSpeedFan->isChecked())
{
_nvapi->startFanThread();
}
else
{
_nvapi->stopFanThread();
_nvapi->setFanSpeed(i, ui->horizontalSliderFanSpeed->value());
}
}
}
else
{
_nvapi->setPowerLimitPercent(gpu, ui->horizontalSliderPowerPercent->value());
_nvapi->setGPUOffset(gpu, ui->horizontalSliderGpuOffset->value());
_nvapi->setMemClockOffset(gpu, ui->horizontalSliderMemOffset->value());
if(ui->checkBoxAutoSpeedFan->isChecked())
{
_nvapi->startFanThread();
}
else
{
_nvapi->stopFanThread();
_nvapi->setFanSpeed(gpu, ui->horizontalSliderFanSpeed->value());
}
}
saveConfig();
}
}
void nvOCDialog::on_checkBoxAutoSpeedFan_clicked(bool checked)
{
if(checked)
{
ui->horizontalSliderFanSpeed->hide();
}
else
{
ui->horizontalSliderFanSpeed->show();
}
}