1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-16 03:59:11 +01:00
doorlockd-mirror/doorlockd/door.h

58 lines
1.2 KiB
C
Raw Normal View History

2015-05-11 00:18:22 +02:00
#ifndef DOOR_H
#define DOOR_H
#include <string>
#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};
// 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-21 13:35:30 +02:00
// Indicates the internal state: Door is open or locked
State _state = { Door::State::Locked };
// A Heartbeat thread is started when the door is unlocked
std::thread _heartbeat = { };
2015-05-21 13:35:30 +02:00
// Read by the Heartbeat thread if it should klacker the schnapper or not
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-05-11 00:18:22 +02:00
};
#endif