diff --git a/doorlockd/door.cpp b/doorlockd/door.cpp index af8ae20..4b27572 100644 --- a/doorlockd/door.cpp +++ b/doorlockd/door.cpp @@ -16,6 +16,8 @@ Door::Door() : wiringPiSetup(); pinMode(_HEARTBEATPIN, OUTPUT); pinMode(_SCHNAPPERPIN, OUTPUT); + pinMode(_LOCKPIN, INPUT); + pullUpDnControl(_LOCKPIN, PUD_UP); lock(); } @@ -70,11 +72,17 @@ void Door::unlock() _heartbeat = std::thread([this] () { // One "beat" is one complete cycle of the heartbeat clock - auto beat = [] () { + auto beat = [this] () { digitalWrite(_HEARTBEATPIN, HIGH); usleep(10000); digitalWrite(_HEARTBEATPIN, LOW); usleep(10000); + + if (digitalRead(_LOCKPIN)) { + std::thread([this] () { + lock(); + }).detach(); + } }; // The default of the Schnapperpin: always high diff --git a/doorlockd/door.h b/doorlockd/door.h index 5ed3d64..9f01234 100644 --- a/doorlockd/door.h +++ b/doorlockd/door.h @@ -52,6 +52,7 @@ private: // WiringPi GPIO Pins static constexpr int _HEARTBEATPIN = 10; static constexpr int _SCHNAPPERPIN = 7; + static constexpr int _LOCKPIN = 15; }; #endif