hwmon.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #include "hwmon.h"
  20. #include "sensors.h"
  21. #include "loader.h"
  22. #include <QDir>
  23. #include <QTextStream>
  24. #include <QtQml>
  25. #include <QDebug>
  26. Hwmon::Hwmon(const QString &path, Loader *parent) : QObject(parent),
  27. m_parent(parent),
  28. m_path(path)
  29. {
  30. m_index = path.split('/').last().remove("hwmon").toInt();
  31. QFile nameFile(path + "/name");
  32. if (nameFile.open(QFile::ReadOnly))
  33. m_name = QTextStream(&nameFile).readLine();
  34. else
  35. m_name = path.split('/').last();
  36. QDir dir(m_path);
  37. QStringList entrys = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
  38. foreach (QString entry, entrys)
  39. {
  40. QString str = entry;
  41. int index = str.remove(QRegExp("\\D+")).toInt();
  42. if (entry.contains("fan") && entry.contains("input"))
  43. {
  44. if (QFile::exists(m_path + "/pwm" + QString::number(index)))
  45. {
  46. PwmFan *newPwmFan = new PwmFan(this, index);
  47. connect(this, SIGNAL(sensorsUpdateNeeded()), newPwmFan, SLOT(update()));
  48. m_pwmFans << newPwmFan;
  49. emit pwmFansChanged();
  50. m_fans << qobject_cast<Fan *>(newPwmFan);
  51. emit fansChanged();
  52. }
  53. else
  54. {
  55. Fan *newFan = new Fan(this, index);
  56. connect(this, SIGNAL(sensorsUpdateNeeded()), newFan, SLOT(update()));
  57. m_fans << newFan;
  58. emit fansChanged();
  59. }
  60. }
  61. if (entry.contains("temp") && entry.contains("input"))
  62. {
  63. Temp *newTemp = new Temp(this, index);
  64. connect(this, SIGNAL(sensorsUpdateNeeded()), newTemp, SLOT(update()));
  65. m_temps << newTemp;
  66. emit tempsChanged();
  67. }
  68. }
  69. // qDebug() << "New Hwmon" << m_temps.size() << m_pwmFans.size();
  70. }
  71. QList<QObject *> Hwmon::fans() const
  72. {
  73. QList<QObject *> list;
  74. foreach (Fan *fan, m_fans)
  75. {
  76. list << qobject_cast<QObject *>(fan);
  77. }
  78. return list;
  79. }
  80. QList<QObject *> Hwmon::pwmFans() const
  81. {
  82. QList<QObject *> list;
  83. foreach (PwmFan *pwmFan, m_pwmFans)
  84. {
  85. list << qobject_cast<QObject *>(pwmFan);
  86. }
  87. return list;
  88. }
  89. QList<QObject *> Hwmon::temps() const
  90. {
  91. QList<QObject *> list;
  92. foreach (Temp *temp, m_temps)
  93. {
  94. list << qobject_cast<QObject *>(temp);
  95. }
  96. return list;
  97. }
  98. void Hwmon::testFans()
  99. {
  100. for (int i=0; i<m_pwmFans.size(); i++)
  101. {
  102. m_pwmFans.at(i)->test();
  103. }
  104. }