diff --git a/doorlockd/CMakeLists.txt b/doorlockd/CMakeLists.txt index e5ea988..54ed310 100644 --- a/doorlockd/CMakeLists.txt +++ b/doorlockd/CMakeLists.txt @@ -103,6 +103,10 @@ install(DIRECTORY images/ DESTINATION share/doorlockd/images FILES_MATCHING PATTERN "images/*.png" PERMISSIONS WORLD_READ OWNER_READ GROUP_READ) +install(DIRECTORY sounds/ DESTINATION share/doorlockd/sounds + FILES_MATCHING PATTERN "sounds/*.wav" + PERMISSIONS WORLD_READ OWNER_READ GROUP_READ) + install(FILES scripts/doorlockd.service DESTINATION /etc/systemd/system/) install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ diff --git a/doorlockd/client/mainwindow.cpp b/doorlockd/client/mainwindow.cpp index 255731e..0b67b9a 100644 --- a/doorlockd/client/mainwindow.cpp +++ b/doorlockd/client/mainwindow.cpp @@ -3,6 +3,9 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#define PLAY(file) \ + system("play -q " file " &") + MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow) @@ -22,7 +25,33 @@ void MainWindow::setClientmessage(const Clientmessage &msg) ui->qrwidget->setQRData(msg.token()); ui->tokenLabel->setText(QString::fromStdString(msg.token())); + const auto &doormsg = msg.doormessage(); + _LED(msg.isOpen()); + + if (_oldMessage.isOpen() && !msg.isOpen()) { + // regular close + PLAY(SOUND_LOCK); + } else if (!_oldMessage.isOpen() && msg.isOpen()) { + // regular open + PLAY(SOUND_UNLOCK); + } else { + // no change + } + + if (doormsg.isEmergencyUnlock) { + PLAY(SOUND_EMERGENCY_UNLOCK); + } else if (doormsg.isLockButton) { + PLAY(SOUND_LOCK_BUTTON); + } else if (doormsg.isUnlockButton) { + if (msg.isOpen()) { + PLAY(SOUND_ZONK); + } else { + PLAY(SOUND_UNLOCK_BUTTON); + } + } + + _oldMessage = msg; } void MainWindow::_LED(const bool on) diff --git a/doorlockd/client/mainwindow.h b/doorlockd/client/mainwindow.h index 1a67547..186f80d 100644 --- a/doorlockd/client/mainwindow.h +++ b/doorlockd/client/mainwindow.h @@ -25,6 +25,8 @@ public: private: Ui::MainWindow *ui; + Clientmessage _oldMessage = { }; + void _LED(const bool on); }; diff --git a/doorlockd/config.h.in b/doorlockd/config.h.in index ff8c627..26118c7 100644 --- a/doorlockd/config.h.in +++ b/doorlockd/config.h.in @@ -29,6 +29,14 @@ #define SHARED_LOCATION "@CMAKE_INSTALL_PREFIX@/share/doorlockd/" #define IMAGE_LOCATION SHARED_LOCATION "images/" +#define SOUNDS_LOCATION SHARED_LOCATION "sounds/" +#define SOUND_LOCK SOUNDS_LOCATION "lock.wav" +#define SOUND_UNLOCK SOUNDS_LOCATION "unlock.wav" +#define SOUND_EMERGENCY_UNLOCK SOUNDS_LOCATION "emergency_unlock.wav" +#define SOUND_ZONK SOUNDS_LOCATION "zonk.wav" +#define SOUND_LOCK_BUTTON SOUNDS_LOCATION "lock_button.wav" +#define SOUND_UNLOCK_BUTTON SOUNDS_LOCATION "unlock_button.wav" + #define PRE_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_lock &" #define POST_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_lock &" #define PRE_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_unlock &"