This repository has been archived on 2018-05-28. You can view files and clone it, but cannot push or open issues or pull requests.
BBB-Simple-ACS/client/access_controller.cpp

51 lines
1.3 KiB
C++

#include "access_controller.hpp"
#include "factory.hpp"
namespace acs
{
access_controller::access_controller() : state_(
factory::get()->get_state()), extra_gpio_(
factory::get()->get_devices()->extra()), reader_(
factory::get()->get_reader()), writer_(
factory::get()->get_writer()), timer_(
factory::get()->get_await_timer()) {}
void access_controller::authorized()
{
state_->set_status(state::entry_await);
writer_->authorized();
extra_gpio_->stream_write(gpio::high);
wait(4'000);
}
void access_controller::forbidden()
{
state_->set_status(state::entry_await);
writer_->access_denied();
wait(1'000);
}
void access_controller::force_reset_if_idle()
{
if (state_->get_status() == state::idle)
reset({ });
}
void access_controller::wait(unsigned duration)
{
timer_->defer_with(duration, boost::bind(
&access_controller::reset, this, boost::asio::placeholders::error));
}
void access_controller::reset(const boost::system::error_code& ec)
{
if (ec)
exit(1);
writer_->refresh();
state_->set_status(state::idle);
extra_gpio_->stream_write(gpio::low);
writer_->write_qr_code();
}
}