Browse Source

some small improvements to temps

Malte Veerman 9 years ago
parent
commit
8192ffab11
4 changed files with 36 additions and 16 deletions
  1. 10 5
      lib/src/fan.cpp
  2. 11 6
      lib/src/temp.cpp
  3. 1 1
      package/contents/ui/PwmPoint.qml
  4. 14 4
      package/contents/ui/StatusPoint.qml

+ 10 - 5
lib/src/fan.cpp

@@ -34,7 +34,7 @@
 namespace Fancontrol
 {
 
-Fan::Fan(Hwmon *parent, uint index) : 
+Fan::Fan(Hwmon *parent, uint index) :
     Sensor(parent, index, QString(parent->name() + QString("/fan") + QString::number(index))),
     m_rpmStream(new QTextStream)
 {
@@ -84,7 +84,7 @@ void Fan::reset()
     QIODevice *oldFile = m_rpmStream->device();
     delete m_rpmStream;
     delete oldFile;
-    
+
     if (QDir(m_parent->path()).isReadable())
     {
         QFile *rpmFile = new QFile(m_parent->path() + "/fan" + QString::number(m_index) + "_input", this);
@@ -102,8 +102,13 @@ void Fan::reset()
 void Fan::update()
 {
     m_rpmStream->seek(0);
-    *m_rpmStream >> m_rpm;
-    emit rpmChanged();
+    int rpm;
+    *m_rpmStream >> rpm;
+    if (rpm != m_rpm)
+    {
+        m_rpm = rpm;
+        emit rpmChanged();
+    }
 }
 
-}
+}

+ 11 - 6
lib/src/temp.cpp

@@ -37,7 +37,7 @@
 namespace Fancontrol
 {
 
-Temp::Temp(Hwmon *parent, uint index) : 
+Temp::Temp(Hwmon *parent, uint index) :
     Sensor(parent, index, QString(parent->name() + QString("/temp") + QString::number(index))),
     m_valueStream(new QTextStream)
 {
@@ -96,7 +96,7 @@ void Temp::reset()
     QIODevice *oldFile = m_valueStream->device();
     delete m_valueStream;
     delete oldFile;
-    
+
     if (QDir(m_parent->path()).isReadable())
     {
         QFile *valueFile = new QFile(m_parent->path() + "/temp" + QString::number(m_index) + "_input", this);
@@ -115,9 +115,14 @@ void Temp::reset()
 void Temp::update()
 {
     m_valueStream->seek(0);
-    *m_valueStream >> m_value;
-    m_value /= 1000;
-    emit valueChanged();
+    int value;
+    *m_valueStream >> value;
+    value /= 1000;
+    if (value != m_value)
+    {
+        m_value = value;
+        emit valueChanged();
+    }
 }
 
-}
+}

+ 1 - 1
package/contents/ui/PwmPoint.qml

@@ -83,7 +83,7 @@ Rectangle {
 
                 id: temp
                 font.pixelSize: root.size * 1.5
-                text: Units.fromCelsius(Math.round(background.scaleTemp(root.centerX)), unit) + suffix
+                text: Math.round(Units.fromCelsius(background.scaleTemp(root.centerX)), unit) + suffix
             }
         }
     }

+ 14 - 4
package/contents/ui/StatusPoint.qml

@@ -20,6 +20,8 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.2
+import "../scripts/units.js" as Units
+import "../scripts/math.js" as MoreMath
 
 
 Rectangle {
@@ -27,7 +29,8 @@ Rectangle {
 
     property QtObject fan
     property Item background: parent
-    property real unscaledTemp: fan.temp ? fan.temp.value : minTemp
+    property real unsmoothedTemp: fan.temp ? fan.temp.value : minTemp
+    property real unscaledTemp: unsmoothedTemp
     property real unscaledPwm: fan.pwm
     property var locale: Qt.locale()
     readonly property real centerX: x + width / 2
@@ -35,14 +38,20 @@ Rectangle {
     readonly property point center: Qt.point(centerX, centerY)
     property int size: 10
     property int unit: 0
+    property int smoothing: 2
 
     width: size
     height: size
     radius: size / 2
-    x: background.scaleX(unscaledTemp) - width/2
+    x: MoreMath.bound(-width/2, background.scaleX(unscaledTemp) - width/2, background.width-width/2)
     y: background.scaleY(unscaledPwm) - height/2
     color: "black"
 
+    onUnsmoothedTempChanged: {
+        root.unscaledTemp = (root.unscaledTemp * smoothing + root.unsmoothedTemp) / (smoothing + 1);
+        console.log(root.unscaledTemp);
+    }
+
     Behavior on unscaledTemp {
         SpringAnimation {
             epsilon: 0.1
@@ -80,12 +89,13 @@ Rectangle {
 
                 id: temp
                 font.pixelSize: root.height * 1.5
-                text: (fan.hasTemp ? fan.temp.value : "0") + suffix
+                text: (fan.hasTemp ? Math.round(Units.fromCelsius(root.unscaledTemp, unit)) : "0") + suffix
+
             }
             Label {
                 id: pwm
                 font.pixelSize: root.height * 1.5
-                text: Number(Math.round(background.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + '%'
+                text: Number(Math.round(unscaledPwm / 2.55)).toLocaleString(locale, 'f', 1) + '%'
             }
             Label {
                 id: rpm