-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepdcontrol.cpp
More file actions
113 lines (94 loc) · 2.68 KB
/
Copy pathepdcontrol.cpp
File metadata and controls
113 lines (94 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (C) 2023 Jeremy Nieth
#include "epdcontrol.h"
#include <QDebug>
#define BRIGHTNESS_STEP_SIZE 10
#define REFRESH_RATE 30
EPDControl::EPDControl(QObject *parent) : QObject(parent)
{
brightnessFile = new QFile("/sys/class/backlight/mxc_msp430_fl.0/brightness", this);
brightnessFile->open(QIODevice::ReadOnly);
QTextStream instream(brightnessFile);
currentBrightness = instream.readLine().toInt();
brightnessFile->close();
emit brightnessChanged(currentBrightness);
screenRefreshTimer = new QTimer(this);
screenRefreshTimer->setInterval(1000 / REFRESH_RATE);
screenRefreshTimer->setSingleShot(true);
connect(screenRefreshTimer, SIGNAL(timeout()), this, SLOT(refreshScreen()));
updateQueue = new QVector<QRect>();
}
void EPDControl::setBrightness(int level)
{
if (level > 100)
level = 100;
else if (level < 0)
level = 0;
brightnessFile->open(QIODevice::WriteOnly);
QTextStream outstream(brightnessFile);
outstream << level;
brightnessFile->close();
currentBrightness = level;
emit brightnessChanged(level);
}
int EPDControl::getBrightness()
{
return currentBrightness;
}
bool EPDControl::getBLStatus()
{
return (bool)currentBrightness;
}
void EPDControl::decBrightness()
{
setBrightness(currentBrightness - BRIGHTNESS_STEP_SIZE);
}
void EPDControl::incBrightness()
{
setBrightness(currentBrightness + BRIGHTNESS_STEP_SIZE);
}
void EPDControl::toggleBacklight()
{
if (currentBrightness != 0)
{
lastBrightness = currentBrightness;
setBrightness(0);
}
else if (currentBrightness == 0)
setBrightness(lastBrightness);
}
void EPDControl::queueScreenUpdate(QRect rect)
{
updateQueue->append(rect);
screenRefreshTimer->start();
}
void EPDControl::refreshScreen()
{
if (updateQueue->size() > 1)
{
QRect temp = updateQueue->takeFirst();
while (!updateQueue->isEmpty())
temp = temp.united(updateQueue->takeFirst());
updateScreen(temp);
}
else
updateScreen(updateQueue->takeFirst());
}
using namespace std;
void EPDControl::updateScreen(QRect rect)
{
#ifdef Q_OS_LINUX
mxcfb_update_data update_data = {
rect.y(), rect.x(), rect.width(), rect.height(),
WAVEFORM_MODE_AUTO,
};
update_data.flags = EPDC_FLAG_FORCE_MONOCHROME;
int framebuffer = open("/dev/fb0", O_RDWR);
if (framebuffer != -1)
{
ioctl(framebuffer, MXCFB_SET_UPDATE_SCHEME, UPDATE_SCHEME_SNAPSHOT);
ioctl(framebuffer, MXCFB_SEND_UPDATE, &update_data);
close(framebuffer);
}
#endif
qDebug("Received coords %dx%d, %dx%d", rect.x(), rect.y(), rect.width(), rect.height());
}