1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 10:24:26 +01:00

Added Schnapper functionality, added i2c and spi load stuff

This commit is contained in:
Ralf Ramsauer 2015-05-14 19:36:49 +02:00
parent 7c063e77d3
commit d08695cf74
4 changed files with 59 additions and 15 deletions

View File

@ -1,26 +1,26 @@
#include <iostream>
#include <wiringPi.h>
#include <unistd.h>
#include "logger.h"
#include "door.h"
using namespace std;
constexpr int LOCKPIN = 10;
Door::Door() : _l(Logger::get())
Door::Door() :
_l(Logger::get())
{
_l(LogLevel::info, "Initializing Raspberry Pi GPIOs");
wiringPiSetup();
pinMode(LOCKPIN, OUTPUT);
pinMode(_LOCKPIN, OUTPUT);
pinMode(_SCHNAPPER, OUTPUT);
lock();
}
Door::~Door()
{
lock();
}
Door &Door::get()
@ -31,12 +31,44 @@ Door &Door::get()
void Door::lock()
{
digitalWrite(_SCHNAPPER, HIGH);
_l(LogLevel::info, "Door closed");
digitalWrite(LOCKPIN, HIGH);
if (_open == true)
{
_open = false;
_heartbeat.join();
}
}
void Door::unlock()
{
_schnapper = true;
if (_open == true)
{
return;
}
_open = true;
_heartbeat = std::thread([this] () {
digitalWrite(_SCHNAPPER, HIGH);
auto beat = [] () {
digitalWrite(_LOCKPIN, HIGH);
usleep(10000);
digitalWrite(_LOCKPIN, LOW);
usleep(10000);
};
while (_open) {
if (_schnapper == true)
{
digitalWrite(_SCHNAPPER, LOW);
for (int i = 0; i < 32 ; i++) beat();
digitalWrite(_SCHNAPPER, HIGH);
_schnapper = false;
}
beat();
}
});
_l(LogLevel::info, "Door opened");
digitalWrite(LOCKPIN, LOW);
}

9
door.h
View File

@ -2,6 +2,7 @@
#define DOOR_H
#include <string>
#include <thread>
#include "logger.h"
@ -20,6 +21,14 @@ private:
Door();
const Logger &_l;
bool _open = { false };
std::thread _heartbeat = { };
bool _schnapper = { false };
static constexpr int _LOCKPIN = 10;
static constexpr int _SCHNAPPER = 7;
};
#endif

View File

@ -149,16 +149,16 @@ Logic::Response Logic::_lock()
Logic::Response Logic::_unlock()
{
if (_state == UNLOCKED)
{
_logger(LogLevel::warning, "Unable to unlock: already unlocked");
return AlreadyUnlocked;
}
_door.unlock();
_state = UNLOCKED;
_createNewToken(false);
if (_state == UNLOCKED)
{
_logger(LogLevel::warning, "Unable to unlock: already unlocked");
return AlreadyUnlocked;
}
return Success;
}

View File

@ -113,6 +113,9 @@ int main(int argc, char** argv)
l(LogLevel::notice, "Starting doorlockd");
system("/usr/bin/gpio load spi");
system("/usr/bin/gpio load i2c");
try {
unsigned int timeout;
po::options_description desc("usage: doorlockd");