-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrifeLCD.cpp
More file actions
298 lines (250 loc) · 6.52 KB
/
StrifeLCD.cpp
File metadata and controls
298 lines (250 loc) · 6.52 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// StrifeLCD.cpp : Defines the entry point for the console application.
//
#include "StrifeLCD.h"
#include <stdio.h>
TCHAR monoImageFileName[] = _T("LogiLogoMono.bmp");
ULONG_PTR g_gdiplusToken;
StrifeLCD::StrifeLCD(){}
bool StrifeLCD::initStrifeLCD()
{
gold = STARTING_GOLD;
gpm = STARTING_GPM;
kills = STARTING_KILLS;
deaths = STARTING_DEATHS;
assists = STARTING_ASSISTS;
level = STARTING_LEVEL;
// Start Gdiplus
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&g_gdiplusToken, &gdiplusStartupInput, NULL);
currentScreen = 0;
printf("Initialized\n");
if (true)
{
if (!LogiLcdInit(STRIFELCD_APP_NAME, LOGI_LCD_TYPE_MONO))
{
return false;
}
printf("Connected To Keyboard\n");
displaySplashScreen();
return true;
}
printf("Not Connected To Keyboard\n");
return false;
}
void StrifeLCD::clearDisplay()
{
BYTE pixels[LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT];
for (int i = 0; i < (LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT); i++)
{
pixels[i] = (BYTE)0;
}
LogiLcdMonoSetBackground(pixels);
LogiLcdMonoSetText(0, L"");
LogiLcdMonoSetText(1, L"");
LogiLcdMonoSetText(2, L"");
LogiLcdMonoSetText(3, L"");
}
void StrifeLCD::displaySplashScreen()
{
clearDisplay();
printf("I displayed the splash screen\n");
setMonoBackgroundFromFile(monoImageFileName);
LogiLcdUpdate();
}
void StrifeLCD::displayStatsScreen1()
{
clearDisplay();
LogiLcdMonoSetText(0, L"Stats about GPM , Kills");
LogiLcdMonoSetText(1, L"Stats about Gold , Deaths");
LogiLcdMonoSetText(2, L"Stats about Level , Assists");
LogiLcdMonoSetText(3, L"More stats.");
}
void StrifeLCD::displayStatsScreen2()
{
clearDisplay();
int progressBars[4];
progressBars[0] = -1;
progressBars[1] = 75;
progressBars[2] = -1;
progressBars[3] = 50;
LogiLcdMonoSetText(0, L"Health");
LogiLcdMonoSetText(2, L"Mana");
drawProgressBar(progressBars);
}
void StrifeLCD::updateScreen()
{
if (LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_0))
{
currentScreen = 0;
}
if (LogiLcdIsButtonPressed(LOGI_LCD_MONO_BUTTON_1))
{
currentScreen = 1;
}
switch (currentScreen)
{
case 0:
displayStatsScreen1();
break;
case 1:
displayStatsScreen2();
break;
default:
break;
}
LogiLcdUpdate();
}
bool StrifeLCD::drawProgressBar(int lineNumbers[4])
{
BYTE pixels[LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT];
char lines[6];
for (int p = 0; p < sizeof(lineNumbers); p++)
{
if (lineNumbers[p] > -1)
{
switch (p)
{
case 0:
lines[0] = 1;
lines[1] = 2;
lines[2] = 3;
lines[3] = 4;
lines[4] = 5;
lines[5] = 6;
break;
case 1:
lines[0] = 11;
lines[1] = 12;
lines[2] = 13;
lines[3] = 14;
lines[4] = 15;
lines[5] = 16;
break;
case 2:
lines[0] = 22;
lines[1] = 23;
lines[2] = 24;
lines[3] = 25;
lines[4] = 26;
lines[5] = 27;
break;
case 3:
lines[0] = 33;
lines[1] = 34;
lines[2] = 35;
lines[3] = 36;
lines[4] = 37;
lines[5] = 38;
break;
default:
return false;
}
//Create the top of the line.
for (int i = ((160 * lines[0]) + 9); i <= ((160 * (lines[0] + 1)) - 10); i++)
{
pixels[i] = (BYTE)128;
}
//Create the bottom line.
for (int i = ((160 * lines[5]) + 9); i <= ((160 * (lines[5] + 1)) - 10); i++)
{
pixels[i] = (BYTE)128;
}
//Create the ends.
pixels[((160 * lines[1]) + 9)] = (BYTE)128;
pixels[((160 * lines[2]) + 9)] = (BYTE)128;
pixels[((160 * lines[3]) + 9)] = (BYTE)128;
pixels[((160 * lines[4]) + 9)] = (BYTE)128;
pixels[((160 * (lines[1] + 1)) - 10)] = (BYTE)128;
pixels[((160 * (lines[2] + 1)) - 10)] = (BYTE)128;
pixels[((160 * (lines[3] + 1)) - 10)] = (BYTE)128;
pixels[((160 * (lines[4] + 1)) - 10)] = (BYTE)128;
//Fill the bars with progress!
int progress = (140 * lineNumbers[p]) / 100;
for (int i = 0; i <= progress; i++)
{
pixels[((160 * lines[1]) + 9 + i)] = 128;
pixels[((160 * lines[2]) + 9 + i)] = 128;
pixels[((160 * lines[3]) + 9 + i)] = 128;
pixels[((160 * lines[4]) + 9 + i)] = 128;
}
}
}
//Fill all the empty bits with 0.
for (int i = 0; i < (LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT); i++)
{
if (pixels[i] != 128)
pixels[i] = (BYTE)0;
}
LogiLcdMonoSetBackground(pixels);
return true;
}
bool StrifeLCD::setMonoBackgroundFromFile(TCHAR* fileName)
{
HDC hdc = ::GetDC(NULL);
Gdiplus::Bitmap* imageMono = Gdiplus::Bitmap::FromFile( fileName );
if (NULL == imageMono)
return false;
// Get the bitmap handle
HBITMAP hBitmap = NULL;
Gdiplus::Status status = imageMono->GetHBITMAP(RGB(0, 0, 0), &hBitmap);
if (status != Gdiplus::Ok)
return false;
BITMAPINFO bitmapInfoMono = { 0 };
bitmapInfoMono.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Check what we got
int ret = GetDIBits(hdc, hBitmap, 0,
0,
NULL,
&bitmapInfoMono, DIB_RGB_COLORS);
if (LOGI_LCD_MONO_WIDTH != bitmapInfoMono.bmiHeader.biWidth || LOGI_LCD_MONO_HEIGHT != bitmapInfoMono.bmiHeader.biHeight)
{
::MessageBoxW(NULL, _T("Oooops. Make sure to use a 160 by 43 image for mono background."), _T("LCDDemo"), MB_ICONEXCLAMATION);
return false;;
}
bitmapInfoMono.bmiHeader.biCompression = BI_RGB;
bitmapInfoMono.bmiHeader.biHeight = -bitmapInfoMono.bmiHeader.biHeight; // this value needs to be inverted, or else image will show up upside/down
BYTE byteBitmapMono[LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT * 4];
// Gets the "bits" from the bitmap and copies them into a buffer
// which is pointed to by byteBitmapMono.
ret = GetDIBits(hdc, hBitmap, 0,
-bitmapInfoMono.bmiHeader.biHeight, // height here needs to be positive. Since we made it negative previously, let's reverse it again to make it positive.
&byteBitmapMono,
(BITMAPINFO *)&bitmapInfoMono, DIB_RGB_COLORS);
BYTE byteBitmapMono8bpp[LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT];
// Transform 32bpp data into 8bpp. Let's just take the value of first of 4 bytes (Blue)
for (int ii = 0; ii < (LOGI_LCD_MONO_WIDTH * LOGI_LCD_MONO_HEIGHT * 4); ii = ii + 4)
{
byteBitmapMono8bpp[ii / 4] = byteBitmapMono[ii];
}
LogiLcdMonoSetBackground(byteBitmapMono8bpp);
// delete the image when done
if (imageMono)
{
delete imageMono;
imageMono = NULL;
}
return true;
}
bool StrifeLCD::shutdownStrifeLCD()
{
LogiLcdShutdown();
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
bool done = false;
time_t startTime = time(NULL);
static StrifeLCD strife;
strife.initStrifeLCD();
while ((startTime + 2) > time(NULL)){
}
while (!done){
strife.updateScreen();
if ((startTime + 20) < time(NULL))
{
done = true;
}
}
strife.shutdownStrifeLCD();
return 0;
}