2015-05-11 00:18:22 +02:00
|
|
|
#ifndef DOOR_H
|
|
|
|
#define DOOR_H
|
|
|
|
|
|
|
|
#include <string>
|
2015-05-14 19:36:49 +02:00
|
|
|
#include <thread>
|
2015-05-11 00:18:22 +02:00
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
/*
|
|
|
|
* The Door class.
|
|
|
|
*
|
|
|
|
* This class exists as a singleton as only one door and hence one object may exist.
|
|
|
|
* Available via the get() method.
|
|
|
|
*
|
|
|
|
* This class is responsible for opening and closing the door by sending
|
|
|
|
* the heartbeat to the AVR board via Raspberry Pi GPIOs
|
|
|
|
*
|
|
|
|
* Whenever the unlock() is called, this class also sends a 0x55 resp. 0xaa
|
|
|
|
* to the AVR in order to klacker the schnapper.
|
|
|
|
*/
|
2015-05-11 00:18:22 +02:00
|
|
|
class Door {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// Returns the singleton
|
|
|
|
static Door &get();
|
2015-05-11 00:18:22 +02:00
|
|
|
~Door();
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
enum class State {Locked, Unlocked};
|
|
|
|
|
2015-08-27 20:30:32 +02:00
|
|
|
// Current state of the door
|
2015-08-30 22:14:35 +02:00
|
|
|
State state() const;
|
2015-08-27 20:30:32 +02:00
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// Lock the door
|
2015-05-11 00:18:22 +02:00
|
|
|
void lock();
|
2015-05-21 13:35:30 +02:00
|
|
|
// Unlock the door
|
2015-05-11 00:18:22 +02:00
|
|
|
void unlock();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Door();
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// used for logging
|
2015-05-11 00:18:22 +02:00
|
|
|
const Logger &_l;
|
2015-05-14 19:36:49 +02:00
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// Indicates the internal state: Door is open or locked
|
2015-08-30 22:14:35 +02:00
|
|
|
volatile State _state = { Door::State::Locked };
|
2015-05-21 13:35:30 +02:00
|
|
|
|
|
|
|
// A Heartbeat thread is started when the door is unlocked
|
2015-05-14 19:36:49 +02:00
|
|
|
std::thread _heartbeat = { };
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// Read by the Heartbeat thread if it should klacker the schnapper or not
|
2015-05-14 19:36:49 +02:00
|
|
|
bool _schnapper = { false };
|
|
|
|
|
2015-05-21 13:35:30 +02:00
|
|
|
// WiringPi GPIO Pins
|
|
|
|
static constexpr int _HEARTBEATPIN = 10;
|
|
|
|
static constexpr int _SCHNAPPERPIN = 7;
|
2015-08-03 21:01:58 +02:00
|
|
|
static constexpr int _LOCKPIN = 15;
|
2015-05-11 00:18:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|