2015-05-11 00:18:22 +02:00
|
|
|
#include <iostream>
|
2015-05-14 19:36:49 +02:00
|
|
|
|
2015-05-11 00:18:22 +02:00
|
|
|
#include <wiringPi.h>
|
2015-05-14 19:36:49 +02:00
|
|
|
#include <unistd.h>
|
2015-05-11 00:18:22 +02:00
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
#include "door.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-05-14 19:36:49 +02:00
|
|
|
Door::Door() :
|
|
|
|
_l(Logger::get())
|
2015-05-11 00:18:22 +02:00
|
|
|
{
|
|
|
|
_l(LogLevel::info, "Initializing Raspberry Pi GPIOs");
|
|
|
|
wiringPiSetup();
|
2015-05-14 19:36:49 +02:00
|
|
|
pinMode(_LOCKPIN, OUTPUT);
|
|
|
|
pinMode(_SCHNAPPER, OUTPUT);
|
2015-05-11 00:18:22 +02:00
|
|
|
lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
Door::~Door()
|
|
|
|
{
|
2015-05-14 19:36:49 +02:00
|
|
|
lock();
|
2015-05-11 00:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Door &Door::get()
|
|
|
|
{
|
|
|
|
static Door d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Door::lock()
|
|
|
|
{
|
2015-05-14 19:36:49 +02:00
|
|
|
digitalWrite(_SCHNAPPER, HIGH);
|
2015-05-11 00:18:22 +02:00
|
|
|
_l(LogLevel::info, "Door closed");
|
2015-05-14 19:36:49 +02:00
|
|
|
if (_open == true)
|
|
|
|
{
|
|
|
|
_open = false;
|
|
|
|
_heartbeat.join();
|
|
|
|
}
|
2015-05-18 22:22:08 +02:00
|
|
|
|
2015-05-18 22:25:47 +02:00
|
|
|
system("wget -O /dev/null --timeout 3 \"http://homer.binary.kitchen:8080/set?color=000000\" > /dev/null 2>&1");
|
2015-05-11 00:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Door::unlock()
|
|
|
|
{
|
2015-05-14 19:36:49 +02:00
|
|
|
_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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-11 00:18:22 +02:00
|
|
|
_l(LogLevel::info, "Door opened");
|
|
|
|
}
|