From f6238e5a369db8e5bd3c1f35bebeeb40f7f9b69e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 17 Nov 2023 11:44:51 +0100 Subject: [PATCH] integrate wakeup line --- src/ATBAPP/support/VMC/vmc.cpp | 63 ++++++++++++++++++++++++++++++++-- src/ATBAPP/support/VMC/vmc.h | 18 +++++++--- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/ATBAPP/support/VMC/vmc.cpp b/src/ATBAPP/support/VMC/vmc.cpp index 2d932b0..1a0ba80 100644 --- a/src/ATBAPP/support/VMC/vmc.cpp +++ b/src/ATBAPP/support/VMC/vmc.cpp @@ -13,6 +13,13 @@ VMC::VMC(QObject *appControl, QSettings const *settings, QObject *parent) : QObject(parent) { + + this->REMOTE_OUT_gpio_outstream = nullptr; + this->REMOTE_OUT_gpio = nullptr; + this->sendBuffer = nullptr; + this->receiveBuffer = nullptr; + this->com_interface = nullptr; + this->flag_blockVMCScreen = 0; this->currentCachedScreen = VMC_CMD_SCREEN_START; @@ -23,6 +30,8 @@ VMC::VMC(QObject *appControl, QSettings const *settings, this->receiveBuffer = new ReceiveBuffer(com_interface, this); this->sendBuffer = new SendBuffer(com_interface, this); + this->privateInit_REMOTE_OUT(); + connect(receiveBuffer, SIGNAL(ReceiveResponse(quint8)), sendBuffer, SLOT(onReceiveResponse(quint8))); com_interface->open(settings->value("VMC/serialPort", "ttymxc2").toString(), @@ -41,11 +50,59 @@ VMC::VMC(QObject *appControl, QSettings const *settings, VMC::~VMC() { - delete(this->sendBuffer); - delete(this->receiveBuffer); - delete(this->com_interface); + if (this->REMOTE_OUT_gpio_outstream) { + delete(this->REMOTE_OUT_gpio_outstream); + } + if (this->REMOTE_OUT_gpio) { + delete(this->REMOTE_OUT_gpio); + } + if (this->sendBuffer) { + delete(this->sendBuffer); + } + if (this->receiveBuffer) { + delete(this->receiveBuffer); + } + if (this->com_interface) { + delete(this->com_interface); + } } +/***************************************************************************** + * functions for wake vmc +*/ + +void VMC::onWakeVMC() { + this->privateWakeVMC(); +} + +void VMC::privateWakeVMC() { + QTimer::singleShot (100, this, SLOT(privateSuspendVMC())); + this->privateSet_REMOTE_OUT(true); +} + +void VMC::privateSuspendVMC() { + this->privateSet_REMOTE_OUT(false); +} + +void VMC::privateSet_REMOTE_OUT(bool state) { + if (state) { *(this->REMOTE_OUT_gpio_outstream) << "1"; } + else { *(this->REMOTE_OUT_gpio_outstream) << "0"; } + + this->REMOTE_OUT_gpio_outstream->flush(); +} + +void VMC::privateInit_REMOTE_OUT() { + QString sysfs_remout_out("/sys/class/leds/REMOTE_OUT/brightness"); + + this->REMOTE_OUT_gpio = new QFile(sysfs_remout_out); + if (!REMOTE_OUT_gpio->open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug() << "ATB_system::privateInit_REMOTE_OUT() cannot open file: " << sysfs_remout_out; + qDebug() << " file.errorString() = " << REMOTE_OUT_gpio->errorString(); + return; + } + + this->REMOTE_OUT_gpio_outstream = new QTextStream(this->REMOTE_OUT_gpio); +} /******************************************************************************** * S E N D M E S S A G E S t o V M C diff --git a/src/ATBAPP/support/VMC/vmc.h b/src/ATBAPP/support/VMC/vmc.h index d5a459a..8fa419f 100644 --- a/src/ATBAPP/support/VMC/vmc.h +++ b/src/ATBAPP/support/VMC/vmc.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #define VMC_RECEIVE_TIMEOUT 1000 @@ -147,11 +149,8 @@ class SendBuffer; using FormatedStringList = QList; -class VMC : public QObject -{ +class VMC : public QObject { Q_OBJECT - - private: QObject *m_appControl; COM_interface *com_interface; @@ -159,6 +158,9 @@ private: SendBuffer *sendBuffer; QSettings const *m_settings; + QFile *REMOTE_OUT_gpio; + QTextStream *REMOTE_OUT_gpio_outstream; + // internal: write a ByteArray to com-port: int SendMessage(QByteArray ba, bool enqueue = false); @@ -185,10 +187,14 @@ private: quint8 flag_blockVMCScreen; quint16 currentCachedScreen; + void privateInit_REMOTE_OUT(); + private slots: void onDelayedMessageTimerTimeout(); - void skipDiscount(); + void privateSet_REMOTE_OUT(bool state); + void privateWakeVMC(); + void privateSuspendVMC(); public: explicit VMC(QObject *eventReceiver, QSettings const *settings, @@ -387,6 +393,8 @@ public slots: void ccStartTransactionRequest(); // called to start/restart a CC transaction void ccStartConfirmTransaction(); // called to start confirmation void ccPrintReceipt(QString receipt); // called to send receipt to vmc + + void onWakeVMC(); }; #endif // VMC_H