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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// Copyright 2008-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "G15LCDEngine_helper.h"
#include "MumbleApplication.h"
static LCDEngine *G15LCDEngineNew() {
return new G15LCDEngineHelper();
}
static LCDEngineRegistrar registrar(G15LCDEngineNew);
G15LCDEngineHelper::G15LCDEngineHelper() : LCDEngine() {
bRunning = false;
bUnavailable = true;
#if defined(Q_OS_WIN)
qsHelperExecutable = QString::fromLatin1("\"%1/mumble-g15-helper.exe\"")
.arg(MumbleApplication::instance()->applicationVersionRootPath());
#elif defined(Q_OS_MAC)
qsHelperExecutable = QString::fromLatin1("\"%1/mumble-g15-helper\"")
.arg(MumbleApplication::instance()->applicationVersionRootPath());
#endif
qpHelper = new QProcess(this);
qpHelper->setObjectName(QLatin1String("Helper"));
qpHelper->setWorkingDirectory(qApp->applicationDirPath());
/*
* Call our helper to detect whether any Logitech Gamepanel devices
* are available on the system.
*/
qpHelper->start(qsHelperExecutable, QStringList(QLatin1String("/detect")));
qpHelper->waitForFinished();
if (qpHelper->exitCode() != 0) {
qWarning("G15LCDEngine_lglcd: Logitech LCD Manager not detected.");
return;
}
qlDevices << new G15LCDDeviceHelper(this);
bUnavailable = false;
QMetaObject::connectSlotsByName(this);
}
G15LCDEngineHelper::~G15LCDEngineHelper() {
setProcessStatus(false);
}
QList< LCDDevice * > G15LCDEngineHelper::devices() const {
return qlDevices;
}
void G15LCDEngineHelper::setProcessStatus(bool run) {
if (bUnavailable)
return;
if (run && !bRunning) {
bRunning = true;
qpHelper->start(qsHelperExecutable, QStringList(QLatin1String("/mumble")));
if (!qpHelper->waitForStarted(2000)) {
qWarning("G15LCDEngine_lglcd: Unable to launch G15 helper.");
bRunning = false;
return;
}
} else if (!run && bRunning) {
bRunning = false;
qpHelper->kill();
qpHelper->waitForFinished();
}
}
void G15LCDEngineHelper::on_Helper_finished(int exitCode, QProcess::ExitStatus status) {
/* Skip the signal if we killed ourselves. */
if (!bRunning)
return;
if (status == QProcess::CrashExit) {
qWarning("G15LCDEngine_lglcd: Helper process crashed. Restarting.");
qpHelper->start(qsHelperExecutable, QStringList(QLatin1String("/mumble")));
} else if (status == QProcess::NormalExit && exitCode != 0) {
qWarning("G15LCDEngine_lglcd: Helper process exited. Exit code was: `%i'. Not attempting recovery.", exitCode);
bUnavailable = true;
}
}
bool G15LCDEngineHelper::framebufferReady() const {
return !bUnavailable && (qpHelper->state() == QProcess::Running);
}
void G15LCDEngineHelper::submitFrame(bool alert, unsigned char *buf, qint64 len) {
char pri = alert ? 1 : 0;
if ((qpHelper->write(&pri, 1) != 1) || (qpHelper->write(reinterpret_cast< char * >(buf), len) != len))
qWarning("G15LCDEngine_lglcd: failed to write");
}
/* -- */
G15LCDDeviceHelper::G15LCDDeviceHelper(G15LCDEngineHelper *e) : LCDDevice(), bEnabled(false) {
engine = e;
}
G15LCDDeviceHelper::~G15LCDDeviceHelper() {
}
bool G15LCDDeviceHelper::enabled() {
return bEnabled;
}
void G15LCDDeviceHelper::setEnabled(bool b) {
engine->setProcessStatus(b);
bEnabled = b;
}
void G15LCDDeviceHelper::blitImage(QImage *img, bool alert) {
Q_ASSERT(img);
int len = G15_MAX_FBMEM_BITS;
uchar *tmp = img->bits();
uchar buf[G15_MAX_FBMEM];
if (!engine->framebufferReady())
return;
if (!bEnabled)
return;
/*
* The amount of copying/conversion we're doing is hideous.
*
* To draw to the LCD display using Logitech's SDK, we need to pass
* it a byte array (in which each byte represents a single pixel on
* the LCD.)
*
* Unfortunately, there's no way out, really. We *could* perhaps draw
* directly to a monochrome "bytemap" (via Format_Indexed8, and a mono-
* chrome colormap), but QPainter simply doesn't want to draw to a
* QImage of Format_Indexed8.
*
* (What's even worse is that the byte array passed to the Logitech SDK
* isn't even the native format of the LCD. It has to convert it once
* more, when it receives a frame.)
*/
for (int i = 0; i < len; i++) {
int idx = i * 8;
buf[idx + 7] = tmp[i] & 0x80 ? 0xff : 0x00;
buf[idx + 6] = tmp[i] & 0x40 ? 0xff : 0x00;
buf[idx + 5] = tmp[i] & 0x20 ? 0xff : 0x00;
buf[idx + 4] = tmp[i] & 0x10 ? 0xff : 0x00;
buf[idx + 3] = tmp[i] & 0x08 ? 0xff : 0x00;
buf[idx + 2] = tmp[i] & 0x04 ? 0xff : 0x00;
buf[idx + 1] = tmp[i] & 0x02 ? 0xff : 0x00;
buf[idx + 0] = tmp[i] & 0x01 ? 0xff : 0x00;
}
engine->submitFrame(alert, buf, G15_MAX_FBMEM);
}
QString G15LCDDeviceHelper::name() const {
return QString::fromLatin1("Logitech Gamepanel");
}
QSize G15LCDDeviceHelper::size() const {
return QSize(G15_MAX_WIDTH, G15_MAX_HEIGHT);
}
|