Fixed Button-close bug

Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
Ralf Ramsauer 2015-08-30 22:14:35 +02:00
parent 39a9aa43b0
commit 368a22b9b1
2 changed files with 13 additions and 10 deletions

View File

@ -32,7 +32,7 @@ Door &Door::get()
return d;
}
const Door::State &Door::state() const
Door::State Door::state() const
{
return _state;
}
@ -82,13 +82,6 @@ void Door::unlock()
usleep(10000);
digitalWrite(_HEARTBEATPIN, LOW);
usleep(10000);
if (!digitalRead(_LOCKPIN)) {
std::thread([this] () {
_l(LogLevel::info, "Incoming door close request on button press");
lock();
}).detach();
}
};
// The default of the Schnapperpin: always high
@ -120,6 +113,16 @@ void Door::unlock()
// Heartbeat
beat();
if (!digitalRead(_LOCKPIN)) {
std::thread([this] () {
_l(LogLevel::info, "Incoming door close request on button press");
lock();
}).detach();
// Busy wait till door is locked
while(_state == State::Unlocked);
}
}
});

View File

@ -29,7 +29,7 @@ public:
enum class State {Locked, Unlocked};
// Current state of the door
const State &state() const;
State state() const;
// Lock the door
void lock();
@ -44,7 +44,7 @@ private:
const Logger &_l;
// Indicates the internal state: Door is open or locked
State _state = { Door::State::Locked };
volatile State _state = { Door::State::Locked };
// A Heartbeat thread is started when the door is unlocked
std::thread _heartbeat = { };