onCCWakeGpioChanged():

Use commands credit_switchWake/switchPower to reboot cc-terminal.
This commit is contained in:
Gerhard Hoffmann 2024-11-13 13:28:04 +01:00
parent a98ddbdb85
commit d3b1046a9f

View File

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