mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Added Schnapper functionality, added i2c and spi load stuff
This commit is contained in:
parent
7c063e77d3
commit
d08695cf74
50
door.cpp
50
door.cpp
@ -1,26 +1,26 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <wiringPi.h>
|
#include <wiringPi.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "door.h"
|
#include "door.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
Door::Door() :
|
||||||
constexpr int LOCKPIN = 10;
|
_l(Logger::get())
|
||||||
|
|
||||||
Door::Door() : _l(Logger::get())
|
|
||||||
{
|
{
|
||||||
_l(LogLevel::info, "Initializing Raspberry Pi GPIOs");
|
_l(LogLevel::info, "Initializing Raspberry Pi GPIOs");
|
||||||
wiringPiSetup();
|
wiringPiSetup();
|
||||||
pinMode(LOCKPIN, OUTPUT);
|
pinMode(_LOCKPIN, OUTPUT);
|
||||||
|
pinMode(_SCHNAPPER, OUTPUT);
|
||||||
lock();
|
lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Door::~Door()
|
Door::~Door()
|
||||||
{
|
{
|
||||||
|
lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Door &Door::get()
|
Door &Door::get()
|
||||||
@ -31,12 +31,44 @@ Door &Door::get()
|
|||||||
|
|
||||||
void Door::lock()
|
void Door::lock()
|
||||||
{
|
{
|
||||||
|
digitalWrite(_SCHNAPPER, HIGH);
|
||||||
_l(LogLevel::info, "Door closed");
|
_l(LogLevel::info, "Door closed");
|
||||||
digitalWrite(LOCKPIN, HIGH);
|
if (_open == true)
|
||||||
|
{
|
||||||
|
_open = false;
|
||||||
|
_heartbeat.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Door::unlock()
|
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");
|
_l(LogLevel::info, "Door opened");
|
||||||
digitalWrite(LOCKPIN, LOW);
|
|
||||||
}
|
}
|
||||||
|
9
door.h
9
door.h
@ -2,6 +2,7 @@
|
|||||||
#define DOOR_H
|
#define DOOR_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
@ -20,6 +21,14 @@ private:
|
|||||||
Door();
|
Door();
|
||||||
|
|
||||||
const Logger &_l;
|
const Logger &_l;
|
||||||
|
|
||||||
|
bool _open = { false };
|
||||||
|
std::thread _heartbeat = { };
|
||||||
|
|
||||||
|
bool _schnapper = { false };
|
||||||
|
|
||||||
|
static constexpr int _LOCKPIN = 10;
|
||||||
|
static constexpr int _SCHNAPPER = 7;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,16 +149,16 @@ Logic::Response Logic::_lock()
|
|||||||
|
|
||||||
Logic::Response Logic::_unlock()
|
Logic::Response Logic::_unlock()
|
||||||
{
|
{
|
||||||
|
_door.unlock();
|
||||||
|
_state = UNLOCKED;
|
||||||
|
_createNewToken(false);
|
||||||
|
|
||||||
if (_state == UNLOCKED)
|
if (_state == UNLOCKED)
|
||||||
{
|
{
|
||||||
_logger(LogLevel::warning, "Unable to unlock: already unlocked");
|
_logger(LogLevel::warning, "Unable to unlock: already unlocked");
|
||||||
return AlreadyUnlocked;
|
return AlreadyUnlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
_door.unlock();
|
|
||||||
_state = UNLOCKED;
|
|
||||||
_createNewToken(false);
|
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
main.cpp
3
main.cpp
@ -113,6 +113,9 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
l(LogLevel::notice, "Starting doorlockd");
|
l(LogLevel::notice, "Starting doorlockd");
|
||||||
|
|
||||||
|
system("/usr/bin/gpio load spi");
|
||||||
|
system("/usr/bin/gpio load i2c");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
unsigned int timeout;
|
unsigned int timeout;
|
||||||
po::options_description desc("usage: doorlockd");
|
po::options_description desc("usage: doorlockd");
|
||||||
|
Loading…
Reference in New Issue
Block a user