From 6a8e917ede74cf90673bf860a4bba7adc18a999d Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Mon, 3 Aug 2015 21:01:58 +0200 Subject: [PATCH] Added Lock Button Signed-off-by: Ralf Ramsauer --- doorlockd/door.cpp | 10 +++++++++- doorlockd/door.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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