1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-16 20:19:13 +01:00
doorlockd-mirror/epaper.cpp

52 lines
1019 B
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"
using namespace std;
Epaper::Epaper() :
_logger(Logger::get())
{
memset(_prevImg, 0xFF, ARRAY_SIZE);
bsp_init();
}
Epaper::~Epaper()
{
}
Epaper &Epaper::get()
{
static Epaper e;
return e;
}
void Epaper::draw(const string &uri)
{
unsigned char buffer[ARRAY_SIZE];
snprintf((char*)buffer, ARRAY_SIZE, "qrencode -l M -d 100 -s 5 \"%s\" -o /tmp/qr.png", uri.c_str());
system((char*)buffer);
FILE* f = popen("composite -geometry +90+0 /tmp/qr.png /usr/local/share/doorlockd/template.png -colorspace gray -depth 1 gray:-", "r");
2015-05-11 00:18:22 +02:00
int i = fread(buffer, ARRAY_SIZE, 1, f);
if (i != 1)
{
_logger(LogLevel::error, "Image format error");
pclose(f);
return;
}
pclose(f);
epd_DisplayImg(EPDType_270, buffer, _prevImg);
memcpy(_prevImg, buffer, ARRAY_SIZE);
}