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/oled_writer.cpp

113 lines
3.6 KiB
C++

#include "oled_writer.hpp"
#include "factory.hpp"
namespace acs
{
const unsigned char oled_writer::tick[] = {
0b00000000, 0b01111110, 0b00000000,
0b00000011, 0b11111111, 0b11000000,
0b00001111, 0b11111111, 0b11110000,
0b00011111, 0b11111111, 0b11111000,
0b00111111, 0b11111111, 0b11111100,
0b01111111, 0b11111111, 0b11111110,
0b01111111, 0b11111111, 0b11000110,
0b01111111, 0b11111111, 0b10000110,
0b11111111, 0b11111111, 0b00000111,
0b11111111, 0b11111110, 0b00001111,
0b11100011, 0b11111100, 0b00011111,
0b11100001, 0b11111000, 0b00111111,
0b11100000, 0b11110000, 0b01111111,
0b11110000, 0b01100000, 0b11111111,
0b11111000, 0b00000001, 0b11111111,
0b11111100, 0b00000011, 0b11111111,
0b01111110, 0b00000111, 0b11111110,
0b01111111, 0b00001111, 0b11111110,
0b01111111, 0b10011111, 0b11111110,
0b00111111, 0b11111111, 0b11111100,
0b00011111, 0b11111111, 0b11111000,
0b00001111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11000000,
0b00000000, 0b01111110, 0b00000000
};
const unsigned char oled_writer::cross[] = {
0b00000000, 0b11111111, 0b00000000,
0b00000011, 0b11111111, 0b11000000,
0b00001111, 0b11111111, 0b11110000,
0b00011111, 0b11111111, 0b11111000,
0b00110001, 0b11111111, 0b10001100,
0b00110000, 0b11111111, 0b00001100,
0b01110000, 0b01111110, 0b00001110,
0b01111000, 0b00111100, 0b00011110,
0b11111100, 0b00011000, 0b00111111,
0b11111110, 0b00000000, 0b01111111,
0b11111111, 0b00000000, 0b11111111,
0b11111111, 0b10000001, 0b11111111,
0b11111111, 0b10000001, 0b11111111,
0b11111111, 0b00000000, 0b11111111,
0b11111110, 0b00000000, 0b01111111,
0b11111100, 0b00011000, 0b00111111,
0b01111000, 0b00111100, 0b00011110,
0b01110000, 0b01111110, 0b00001110,
0b00110000, 0b11111111, 0b00001100,
0b00110001, 0b11111111, 0b10001100,
0b00011111, 0b11111111, 0b11111000,
0b00001111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11000000,
0b00000000, 0b11111111, 0b00000000
};
void oled_writer::refresh()
{
oled_->clear_display();
oled_->display();
}
oled_writer::oled_writer() : qr_encoder_(factory::get()->get_qr_encoder())
{
oled_ = factory::get()->get_devices()->oled();
oled_->set_text_color(WHITE);
oled_->display_init_seq();
refresh();
}
void oled_writer::authorized()
{
refresh([this]()
{
oled_->set_text_size(2);
oled_->set_cursor(5, 43);
oled_->print_str("Authorized");
oled_->draw_bitmap(52, 8, tick, 24, 24, WHITE);
});
}
void oled_writer::access_denied()
{
refresh([this]()
{
oled_->set_text_size(2);
oled_->set_cursor(9, 43);
oled_->print_str("Forbidden");
oled_->draw_bitmap(52, 8, cross, 24, 24, WHITE);
});
}
void oled_writer::write_qr_code()
{
refresh([this]()
{
auto width = qr_encoder_->get_width();
auto map = qr_encoder_->get_map();
auto border = (64 - width) / 2;
for (auto i = border; i < width + border; ++i)
{
for (auto j = border; j < width + border; ++j)
{
if (map[(i - border) * width + (j - border)])
oled_->draw_pixel(j, i, WHITE);
}
}
});
}
}