Fork of phoebetria OpenSource BitFenix Recon software to support newer Qt5.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gui_softwareautosetup.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /* Copyright 2012 Craig Robbins and Christopher Ferris
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with the program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "gui_softwareautosetup.h"
  14. #include "ui_gui_softwareautosetup.h"
  15. #include "fancontrollerdata.h"
  16. #include "phoebetriaapp.h"
  17. #include "bfx-recon/fancontrollerio.h"
  18. gui_SoftwareAutoSetup::gui_SoftwareAutoSetup(QWidget *parent) :
  19. QDialog(parent),
  20. ui(new Ui::gui_SoftwareAutoSetup),
  21. m_ignoreSignals(false),
  22. m_wasAccepted(false)
  23. {
  24. ui->setupUi(this);
  25. restoreGeometry(ph_prefs().windowSWAutoGeometry());
  26. ui->ctrl_explanation->setText(
  27. "The values for hysteresis are temperature thresholds that aim to stop"
  28. " the fan speeds changing due to small fluctuations in"
  29. " temperature. For example, if Hysteresis Up is set to 2"
  30. " then the probe temperature will have to increase by 2"
  31. " degrees before the RPM is increased."
  32. // "\n\nHysteresis Up is the threshold temperature for increasing RPM\n"
  33. // "Hysteresis Down is for decreasing RPM\n"
  34. // "Hysteresis Fan Off is the threshold for turning the fan off (if applicable)"
  35. );
  36. // FIXME: Temporarily hide controls for pre-release preview release
  37. ui->ctrl_isFanConstantSpeed->hide();
  38. }
  39. gui_SoftwareAutoSetup::~gui_SoftwareAutoSetup()
  40. {
  41. delete ui;
  42. }
  43. void gui_SoftwareAutoSetup::init(FanControllerData *fcdata)
  44. {
  45. m_fcdata = fcdata;
  46. m_isCelcius = fcdata->isCelcius();
  47. m_currChannel = 0;
  48. setupChannelComboBox();
  49. setupAxes(*fcdata, m_currChannel);
  50. setupTemperatureCtrlLimits(*fcdata);
  51. setupSpeedCtrlLimits(fcdata->maxRPM(m_currChannel));
  52. /* Use m_ramp internally and copy to/from fcdata when required */
  53. m_ramp[m_currChannel] = fcdata->ramp(m_currChannel);
  54. //xferSettings_toGui(*fcdata, m_currChannel);
  55. drawPlot();
  56. }
  57. void gui_SoftwareAutoSetup::setupAxes(const FanControllerData& fcdata, int channel)
  58. {
  59. const FanControllerIO* fc = &ph_fanControllerIO();
  60. int minProbeTemp = fc->minProbeTemp(fcdata.isCelcius())-10;
  61. int maxProbeTemp = fc->maxProbeTemp(fcdata.isCelcius())+10;
  62. ui->ctrl_plot->xAxis->setRange(minProbeTemp, maxProbeTemp);
  63. ui->ctrl_plot->yAxis->setRange(0, m_ramp[channel].maxUsableRpm() + 100);
  64. }
  65. void gui_SoftwareAutoSetup::setupRpmAxis_currentRamp(void)
  66. {
  67. ui->ctrl_plot->yAxis->setRange(0, m_ramp[m_currChannel].maxUsableRpm()+100);
  68. }
  69. void gui_SoftwareAutoSetup::setupTemperatureCtrlLimits(
  70. const FanControllerData& fcdata)
  71. {
  72. const FanControllerIO* fc = &ph_fanControllerIO();
  73. int t_lowerLimit = fc->minProbeTemp(fcdata.isCelcius());
  74. int t_upperLimit = fc->maxProbeTemp(fcdata.isCelcius());
  75. ui->ctrl_fanOnTemp->setMinimum(t_lowerLimit);
  76. ui->ctrl_fanOnTemp->setMaximum(t_upperLimit);
  77. ui->ctrl_rampStartTemp->setMinimum(t_lowerLimit);
  78. ui->ctrl_rampStartTemp->setMaximum(t_upperLimit);
  79. ui->ctrl_rampMidTemp->setMinimum(t_lowerLimit);
  80. ui->ctrl_rampMidTemp->setMaximum(t_upperLimit);
  81. ui->ctrl_rampEndTemp->setMinimum(t_lowerLimit);
  82. ui->ctrl_rampEndTemp->setMaximum(t_upperLimit);
  83. ui->fan_fanToMaxTemp->setMinimum(t_lowerLimit);
  84. ui->fan_fanToMaxTemp->setMaximum(t_upperLimit);
  85. }
  86. void gui_SoftwareAutoSetup::setupSpeedCtrlLimits(int maxRpm)
  87. {
  88. //int min = m_ramp[m_currChannel].snapToStepSize(maxRpm * 2/3);
  89. //maxRpm += 5000; // Adding some room for user adjustment
  90. maxRpm = 65535;
  91. ui->ctrl_minRpm->setMaximum(maxRpm);
  92. ui->ctrl_rampStartSpeed->setMaximum(maxRpm);
  93. ui->ctrl_rampMidSpeed->setMaximum(maxRpm);
  94. ui->ctrl_rampEndSpeed->setMaximum(maxRpm);
  95. }
  96. void gui_SoftwareAutoSetup::setupChannelComboBox(void)
  97. {
  98. int channelCount = m_fcdata->channelCount();
  99. bool bs = blockSignals(true);
  100. for (int i = 0; i < channelCount; ++i)
  101. ui->ctrl_channel->insertItem(i,
  102. tr("Channel %1").arg(i+1),
  103. ph_prefs().channelName(i));
  104. blockSignals(bs);
  105. }
  106. void gui_SoftwareAutoSetup::xferSettings_toGui(const FanControllerData& fcdata,
  107. int channel)
  108. {
  109. const FanSpeedRampParameters& setup = m_ramp[m_currChannel].rampParameters();
  110. int t_fanOn = fcdata.toCurrTempScale(setup.temperatureF_fanOn);
  111. int t_rampStart = fcdata.toCurrTempScale(setup.temperatureF_rampStart);
  112. int t_rampMid = fcdata.toCurrTempScale(setup.temperatureF_rampMid);
  113. int t_rampEnd = fcdata.toCurrTempScale(setup.temperatureF_rampEnd);
  114. int t_fanToMax = fcdata.toCurrTempScale(setup.temperatureF_fanToMax);
  115. bool bs = ignoreSignals(true);
  116. ui->ctrl_channel->setCurrentIndex (channel);
  117. ui->ctrl_minRpm->setValue (setup.minUsableRpm);
  118. ui->ctrl_fanOnTemp->setValue (t_fanOn);
  119. ui->ctrl_rampStartTemp->setValue (t_rampStart);
  120. ui->ctrl_rampMidTemp->setValue (t_rampMid);
  121. ui->ctrl_rampEndTemp->setValue (t_rampEnd);
  122. ui->fan_fanToMaxTemp->setValue (t_fanToMax);
  123. ui->ctrl_fanOnSpeed->setValue (setup.speed_fanOn);
  124. ui->ctrl_rampStartSpeed->setValue (setup.speed_rampStart);
  125. ui->ctrl_rampMidSpeed->setValue (setup.speed_rampMid);
  126. ui->ctrl_rampEndSpeed->setValue (setup.speed_rampEnd);
  127. ui->ctrl_isFanConstantSpeed->setChecked (setup.fixedRpm);
  128. ui->ctrl_probeAffinity->setValue (setup.probeAffinity+1);
  129. ui->ctrl_isFanAlwaysOn->setChecked (!setup.allowFanToTurnOff);
  130. ui->ctrl_fanOnSpeed->setEnabled (setup.allowFanToTurnOff);
  131. ui->ctrl_fanOnTemp->setEnabled (setup.allowFanToTurnOff);
  132. ui->ctrl_channelName->setText (ph_prefs().channelName(channel));
  133. ui->ctrl_hysteresisUp->setValue (setup.tHysteresisUp);
  134. ui->ctrl_hysteresisDown->setValue (setup.tHysteresisDown);
  135. ui->ctrl_hysteresisFanOff->setValue (setup.tHysteresisFanOff);
  136. ignoreSignals(bs);
  137. }
  138. void gui_SoftwareAutoSetup::drawPlot(void)
  139. {
  140. const QList<QPoint> ramp = m_ramp[m_currChannel].ramp();
  141. //ui->ctrl_plot->clearGraphs();
  142. ui->ctrl_plot->removeGraph(0);
  143. QCPGraph* gr = ui->ctrl_plot->addGraph();
  144. gr->setScatterStyle(QCP::ssDisc);
  145. gr->setLineStyle(QCPGraph::lsStepLeft);
  146. for (int i = 0; i < ramp.count(); ++i)
  147. {
  148. double t;
  149. t = m_fcdata->toCurrTempScaleReal(ramp.at(i).x());
  150. gr->addData(t, ramp.at(i).y());
  151. }
  152. ui->ctrl_plot->replot();
  153. }
  154. void gui_SoftwareAutoSetup::regenerateCurve(void)
  155. {
  156. m_ramp[m_currChannel].generateCurve();
  157. drawPlot();
  158. }
  159. int gui_SoftwareAutoSetup::tempInF(int t) const
  160. {
  161. return m_isCelcius ? m_fcdata->toFahrenheit(t) : t;
  162. }
  163. void gui_SoftwareAutoSetup::on_ctrl_fanOnTemp_valueChanged(int arg1)
  164. {
  165. if (m_ignoreSignals) return;
  166. m_ramp[m_currChannel].setTemperatureFanOn(tempInF(arg1));
  167. regenerateCurve();
  168. }
  169. void gui_SoftwareAutoSetup::on_ctrl_rampStartTemp_valueChanged(int arg1)
  170. {
  171. if (m_ignoreSignals) return;
  172. m_ramp[m_currChannel].setTemperatureRampStart(tempInF(arg1));
  173. regenerateCurve();
  174. }
  175. void gui_SoftwareAutoSetup::on_ctrl_rampMidTemp_valueChanged(int arg1)
  176. {
  177. if (m_ignoreSignals) return;
  178. m_ramp[m_currChannel].setTemperatureRampMid(tempInF(arg1));
  179. regenerateCurve();
  180. }
  181. void gui_SoftwareAutoSetup::on_ctrl_rampEndTemp_valueChanged(int arg1)
  182. {
  183. if (m_ignoreSignals) return;
  184. m_ramp[m_currChannel].setTemperatureRampEnd(tempInF(arg1));
  185. regenerateCurve();
  186. }
  187. void gui_SoftwareAutoSetup::on_fan_fanToMaxTemp_valueChanged(int arg1)
  188. {
  189. if (m_ignoreSignals) return;
  190. m_ramp[m_currChannel].setTemperatureFanToMax(tempInF(arg1));
  191. regenerateCurve();
  192. }
  193. void gui_SoftwareAutoSetup::on_ctrl_fanOnSpeed_valueChanged(int arg1)
  194. {
  195. if (m_ignoreSignals) return;
  196. m_ramp[m_currChannel].setSpeedFanOn(arg1);
  197. regenerateCurve();
  198. }
  199. void gui_SoftwareAutoSetup::on_ctrl_rampStartSpeed_valueChanged(int arg1)
  200. {
  201. if (m_ignoreSignals) return;
  202. m_ramp[m_currChannel].setSpeedRampStart(arg1);
  203. regenerateCurve();
  204. }
  205. void gui_SoftwareAutoSetup::on_ctrl_rampMidSpeed_valueChanged(int arg1)
  206. {
  207. if (m_ignoreSignals) return;
  208. m_ramp[m_currChannel].setSpeedRampMid(arg1);
  209. regenerateCurve();
  210. }
  211. void gui_SoftwareAutoSetup::on_ctrl_rampEndSpeed_valueChanged(int arg1)
  212. {
  213. if (m_ignoreSignals) return;
  214. m_ramp[m_currChannel].setSpeedRampEnd(arg1);
  215. m_ramp[m_currChannel].setMaxUsableRpm(arg1);
  216. setupRpmAxis_currentRamp();
  217. regenerateCurve();
  218. }
  219. void gui_SoftwareAutoSetup::on_ctrl_minRpm_valueChanged(int arg1)
  220. {
  221. if (m_ignoreSignals) return;
  222. m_ramp[m_currChannel].setMinUsableRpm(arg1);
  223. // TODO possibly check all speed values
  224. /* Could check other values here, but maybe not worth it...
  225. User is probably expecting to have to change the other values
  226. anyway if they are wrong.
  227. */
  228. if (m_ramp[m_currChannel].rampParameters().speed_fanOn < arg1)
  229. {
  230. m_ramp[m_currChannel].setSpeedFanOn(arg1);
  231. bool bs = ui->ctrl_fanOnSpeed->blockSignals(true);
  232. ui->ctrl_fanOnSpeed->setValue(arg1);
  233. ui->ctrl_fanOnSpeed->blockSignals(bs);
  234. }
  235. if (m_ramp[m_currChannel].rampParameters().speed_rampStart < arg1)
  236. {
  237. m_ramp[m_currChannel].setSpeedRampStart(arg1);
  238. bool bs = ui->ctrl_rampStartSpeed->blockSignals(true);
  239. ui->ctrl_rampStartSpeed->setValue(arg1);
  240. ui->ctrl_rampStartSpeed->blockSignals(bs);
  241. }
  242. regenerateCurve();
  243. }
  244. void gui_SoftwareAutoSetup::on_ctrl_channel_currentIndexChanged(int index)
  245. {
  246. bool bs = ignoreSignals(true);
  247. m_currChannel = index;
  248. if (!m_ramp[m_currChannel].isInitialised())
  249. m_ramp[m_currChannel] = m_fcdata->ramp(m_currChannel);
  250. setupAxes(*m_fcdata, index);
  251. setupTemperatureCtrlLimits(*m_fcdata);
  252. setupSpeedCtrlLimits(m_fcdata->maxRPM(m_currChannel));
  253. drawPlot();
  254. xferSettings_toGui(*m_fcdata, index);
  255. ignoreSignals(bs);
  256. }
  257. void gui_SoftwareAutoSetup::on_ctrl_probeAffinity_valueChanged(int arg1)
  258. {
  259. m_ramp[m_currChannel].setProbeAffinity(arg1-1);
  260. }
  261. void gui_SoftwareAutoSetup::on_buttonBox_accepted()
  262. {
  263. for (int i = 0; i < FC_MAX_CHANNELS; ++i)
  264. {
  265. if (m_ramp[i].isInitialised() && m_ramp[i].isModified())
  266. {
  267. m_fcdata->setRamp(i, m_ramp[i]);
  268. }
  269. }
  270. m_wasAccepted = true;
  271. }
  272. void gui_SoftwareAutoSetup::on_ctrl_isFanAlwaysOn_clicked(bool checked)
  273. {
  274. ui->ctrl_fanOnSpeed->setEnabled(!checked);
  275. ui->ctrl_fanOnTemp->setEnabled(!checked);
  276. m_ramp[m_currChannel].setAllowFanToTurnOff(!checked);
  277. regenerateCurve();
  278. }
  279. void gui_SoftwareAutoSetup::on_ctrl_hysteresisUp_editingFinished()
  280. {
  281. m_ramp[m_currChannel].setHysteresisUp(ui->ctrl_hysteresisUp->value());
  282. }
  283. void gui_SoftwareAutoSetup::on_ctrl_hysteresisDown_editingFinished()
  284. {
  285. m_ramp[m_currChannel].setHysteresisDown(ui->ctrl_hysteresisDown->value());
  286. }
  287. void gui_SoftwareAutoSetup::on_ctrl_hysteresisFanOff_editingFinished()
  288. {
  289. m_ramp[m_currChannel].setHysteresisFanOff(ui->ctrl_hysteresisFanOff->value());
  290. }
  291. void gui_SoftwareAutoSetup::done(int result)
  292. {
  293. ph_prefs().setWindowSWAutoGeometry(saveGeometry());
  294. QDialog::done(result);
  295. }