From b1348d61b7c29f1337efc290ddb041ff3e443f23 Mon Sep 17 00:00:00 2001 From: edisionnano Date: Wed, 29 May 2024 06:07:50 +0300 Subject: [PATCH] Support temperature on NVMe drives --- mainwindow.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 89e3b81..b5b3134 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -81,18 +81,16 @@ void MainWindow::scanDevices() isNvme = true; } - for (const QJsonValue &attr : attributes) { // Need different logic for NVMe + int temperatureInt = localObj["temperature"].toObject()["current"].toInt(); + if (temperatureInt > 0) { + temperature = QString::number(temperatureInt) + " °C"; + } + + for (const QJsonValue &attr : attributes) { QJsonObject attrObj = attr.toObject(); - if (attrObj["id"] == 194 && !isNvme) { - QString raw = attrObj["raw"].toObject()["string"].toString(); - int spaceIndex = raw.indexOf(' '); - if (spaceIndex != -1) { - raw = raw.left(spaceIndex); - } - int tempInt = raw.toInt(); - temperature = QString::number(tempInt) + " °C"; - } else if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) { + if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) { caution = true; + break; } } @@ -137,6 +135,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString modelName = localObj["model_name"].toString(); QString firmwareVersion = localObj["firmware_version"].toString(); float userCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9; + int temperatureInt = localObj["temperature"].toObject()["current"].toInt(); QString userCapacityString = QString::number(static_cast(userCapacityGB)) + "." + QString::number(static_cast((userCapacityGB - static_cast(userCapacityGB)) * 10)) + " GB"; QString totalReads = "----"; QString totalWrites = "----"; @@ -145,7 +144,6 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString protocol = deviceObj["protocol"].toString(); QString type = deviceObj["type"].toString(); QString name = deviceObj["name"].toString(); - int tempInt = 0; bool isNvme = false; if (protocol == "NVMe") { @@ -200,13 +198,6 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal totalWrites = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; } else if (attrObj["id"] == 242 && !isNvme) { totalReads = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; - } else if (attrObj["id"] == 194 && !isNvme) { - QString raw = attrObj["raw"].toObject()["string"].toString(); - int spaceIndex = raw.indexOf(' '); - if (spaceIndex != -1) { - raw = raw.left(spaceIndex); - } - tempInt = raw.toInt(); } } @@ -216,11 +207,11 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal totalWritesLineEdit->setText(totalWrites); totalWritesLineEdit->setAlignment(Qt::AlignRight); - if (tempInt > 55) { + if (temperatureInt > 55) { temperatureValue->setStyleSheet("background-color: " + QColor(Qt::red).name() + ";"); - } else if ((tempInt < 55) && (tempInt > 50)){ + } else if ((temperatureInt < 55) && (temperatureInt > 50)){ temperatureValue->setStyleSheet("background-color: " + QColor(Qt::yellow).name() + ";"); - } else if (tempInt == 0) { + } else if (temperatureInt == 0) { temperatureValue->setStyleSheet("background-color: " + QColor(Qt::gray).name() + ";"); } else { temperatureValue->setStyleSheet("background-color: " + QColor(Qt::green).name() + ";"); @@ -228,8 +219,8 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString labelStyle = "font-size:12pt; font-weight:700; color:black"; - if (tempInt > 0) { - temperatureValue->setText("

" + QString::number(tempInt) + " °C

"); + if (temperatureInt > 0) { + temperatureValue->setText("

" + QString::number(temperatureInt) + " °C

"); } else { temperatureValue->setText("

N/A

"); }