From 1199dbfd309c8a321c33829933d6dc5f641ab067 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 10 Jun 2024 11:50:34 +0200 Subject: [PATCH] Add CCWakelineAbstraction --- dCArun/CArun.cpp | 4 +++ dCArun/CArun.h | 4 ++- dCArun/CCWakelineAbstraction.cpp | 51 ++++++++++++++++++++++++++++++++ dCArun/CCWakelineAbstraction.h | 25 ++++++++++++++++ dCArun/dCArun.pro | 2 ++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 dCArun/CCWakelineAbstraction.cpp create mode 100644 dCArun/CCWakelineAbstraction.h diff --git a/dCArun/CArun.cpp b/dCArun/CArun.cpp index 29a636a..6b32ac4 100644 --- a/dCArun/CArun.cpp +++ b/dCArun/CArun.cpp @@ -1,6 +1,8 @@ #include "CArun.h" #include "datei.h" +#include "CCWakelineAbstraction.h" + CArun::CArun(QObject *parent) : QObject(parent) @@ -17,6 +19,8 @@ CArun::CArun(QObject *parent) qCritical() << "CArun: start setup..."; this->timerChainCtrl->start(); + + this->ccWakelineAbstraction = new CCWakelineAbstraction(this->HWaccess, this); } diff --git a/dCArun/CArun.h b/dCArun/CArun.h index cb44554..4be909e 100644 --- a/dCArun/CArun.h +++ b/dCArun/CArun.h @@ -22,7 +22,7 @@ enum class SETUP_STEP { }; - +class CCWakelineAbstraction; class CArun : public QObject { @@ -45,6 +45,8 @@ private: void openSerialPort(); + CCWakelineAbstraction* ccWakelineAbstraction; + signals: diff --git a/dCArun/CCWakelineAbstraction.cpp b/dCArun/CCWakelineAbstraction.cpp new file mode 100644 index 0000000..d5513d6 --- /dev/null +++ b/dCArun/CCWakelineAbstraction.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include + +#include "CCWakelineAbstraction.h" +#include "plugin.h" + +/** + * this is based on a solution from: + * https://embeddeduse.com/2018/09/18/monitoring-sys-files-qfilesystemwatcher/ + * + */ + +CCWakelineAbstraction::CCWakelineAbstraction(hwinf *dc, QObject *parent) + : QObject(parent) + , dc(dc) +{ + auto ccWakeMonitor = new QFileSystemWatcher(this); + + ccWakeMonitor->addPath("/sys/class/leds/wakeupctrl_cc/brightness"); + connect(ccWakeMonitor, &QFileSystemWatcher::fileChanged, + this, &CCWakelineAbstraction::ccWakeChanged); + + qCritical() << "... init CCWakelineAbstraction"; +} + + +void CCWakelineAbstraction::ccWakeChanged(const QString &path) +{ + QFile ccWakeFile(path); + if (!ccWakeFile.open(QIODevice::ReadOnly)) { + qWarning() << "ERROR: Could not open ccWakeFile file."; + return; + } + auto ccWake = ccWakeFile.readAll(); + if (!ccWake.isEmpty()) { + int state = ccWake.at(0); + //qCritical() << "INFO: ccWake = " << state; + switch (state) { + case 0x30: // '1' + qCritical() << "INFO: ccWake -> sleep"; + this->dc->credit_switchWake(true); // switch 'sleep' + break; + case 0x31: // '0' + qCritical() << "INFO: ccWake -> wake"; + this->dc->credit_switchWake(false); // switch 'wake' + break; + } + } +} diff --git a/dCArun/CCWakelineAbstraction.h b/dCArun/CCWakelineAbstraction.h new file mode 100644 index 0000000..9d3cb06 --- /dev/null +++ b/dCArun/CCWakelineAbstraction.h @@ -0,0 +1,25 @@ +#ifndef CCWAKELINEABSTRACTION_H +#define CCWAKELINEABSTRACTION_H + + +#include + +class hwinf; +class QFileSystemWatcher; + + +class CCWakelineAbstraction : public QObject +{ + Q_OBJECT + +public: + CCWakelineAbstraction(hwinf *dc, QObject *parent = nullptr); + +private: + hwinf *dc; + QFileSystemWatcher *ccWakeMonitor; + + void ccWakeChanged(const QString &path); +}; + +#endif // CCWAKELINEABSTRACTION_H diff --git a/dCArun/dCArun.pro b/dCArun/dCArun.pro index a8a3016..676dd16 100644 --- a/dCArun/dCArun.pro +++ b/dCArun/dCArun.pro @@ -40,12 +40,14 @@ DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" SOURCES += \ CArun.cpp \ + CCWakelineAbstraction.cpp \ main.cpp \ tslib.cpp \ datei.cpp HEADERS += \ CArun.h \ + CCWakelineAbstraction.h \ guidefs.h \ tslib.h \ versionHistory.txt \