diff --git a/src/hwapi.cpp b/src/hwapi.cpp index 843e3d6..74e0262 100755 --- a/src/hwapi.cpp +++ b/src/hwapi.cpp @@ -138,39 +138,35 @@ hwapi::hwapi(QObject *parent) : QObject(parent) void hwapi::onCCWakeGpioChanged(QString const &fileName) { if (fileName == m_watchedFile) { + qCritical() << __func__ << ":" << __LINE__ << " " << m_watchedFile; QFile f(m_watchedFile); - if (f.open(QFile::ReadOnly | QFile::Text)) { + if (f.exists() && f.open(QFile::ReadOnly | QFile::Text)) { QTextStream stream(&f); QString const &content = stream.readAll(); if (content.startsWith("0")) { - qCritical() << __func__ << ":" << __LINE__ << "switching terminal off..."; - mod_switchWake(false); - mod_switchPower(false); - f.close(); - f.setFileName(m_watchedFile); - // to turn off cc-terminal, the content must be "0" - if (f.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - QTextStream s(&f); - s << "switching terminal off"; - } + qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal off..."; + credit_switchWake(false); + credit_switchPower(false); } else if (content.startsWith("1")) { - qCritical() << __func__ << ":" << __LINE__ << "switching terminal on..."; - mod_switchPower(true); - mod_switchWake(true); - f.close(); - f.setFileName(m_watchedFile); - // to turn on cc-terminal, the content must be "1" - if (f.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - QTextStream s(&f); - s << "switching terminal on"; - } + qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal on..."; + credit_switchPower(true); + credit_switchWake(true); + } else + if (content.startsWith("2")) { + qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal off and on..."; + credit_switchWake(false); + credit_switchPower(false); + QThread::sleep(1); + credit_switchPower(true); + credit_switchWake(true); } else { - qCritical() << "watched file contained" << content; + qCritical() << "switching cc-terminal watched file contained" << content; + QFile::resize(m_watchedFile, 0); // empty file } } } else { - qCritical() << "ERROR watching the wrong file" << fileName; + qCritical() << "ERROR watching the wrong file" << fileName << m_watchedFile; } }