1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-09 09:46:18 +01:00
doorlockd-mirror/doorlockd/epaper.cpp

56 lines
1.1 KiB
C++
Raw Normal View History

2015-05-11 00:18:22 +02:00
#include <cstring>
#include <unistd.h>
#include <fcntl.h>
#include "logger.h"
extern "C" {
#include "epaper/bsp.h"
#include "epaper/Display_Controller.h"
}
#include "epaper.h"
2015-05-21 13:56:20 +02:00
#include "config.h"
2015-05-11 00:18:22 +02:00
using namespace std;
Epaper::Epaper() :
_logger(Logger::get())
{
2015-05-21 13:35:30 +02:00
memset(_prevImg, 0xFF, _ARRAY_SIZE);
// Initialize Epaper library
2015-05-11 00:18:22 +02:00
bsp_init();
}
Epaper::~Epaper()
{
}
Epaper &Epaper::get()
{
static Epaper e;
return e;
}
void Epaper::draw(const string &uri)
{
2015-05-21 13:35:30 +02:00
unsigned char buffer[_ARRAY_SIZE];
2015-05-21 13:56:20 +02:00
snprintf((char*)buffer, _ARRAY_SIZE,
"qrencode -l M -d 100 -s 5 \"%s\" -t png -o -"
"| composite -geometry +90+0 /dev/stdin " TEMPLATE_LOCATION " -colorspace gray -depth 1 gray:-",
uri.c_str());
2015-05-11 00:18:22 +02:00
2015-05-21 13:56:20 +02:00
FILE* f = popen((const char*)buffer, "r");
2015-05-21 13:35:30 +02:00
int i = fread(buffer, _ARRAY_SIZE, 1, f);
2015-05-11 00:18:22 +02:00
if (i != 1)
{
_logger(LogLevel::error, "Image format error");
pclose(f);
return;
}
pclose(f);
epd_DisplayImg(EPDType_270, buffer, _prevImg);
2015-05-21 13:35:30 +02:00
memcpy(_prevImg, buffer, _ARRAY_SIZE);
2015-05-11 00:18:22 +02:00
}