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
|
/*
* GraphLCD driver library
*
* simlcd.c - SimLCD driver class
* Output goes to a file instead of lcd.
* Use SimLCD tool to view this file.
*
* This file is released under the GNU General Public License. Refer
* to the COPYING file distributed with this package.
*
* (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de>
* (c) 2011 Dirk Heiser
* (c) 2011 Wolfgang Astleitner <mrwastl AT users.sourceforge.net>
*/
#include <stdio.h>
#include <syslog.h>
#include <cstring>
#include "common.h"
#include "config.h"
#include "simlcd.h"
#define DISPLAY_REFRESH_FILE "/tmp/simlcd.sem"
#define DISPLAY_DATA_FILE "/tmp/simlcd.dat"
#define TOUCH_REFRESH_FILE "/tmp/simtouch.sem"
#define TOUCH_DATA_FILE "/tmp/simtouch.dat"
#define FG_CHAR "#"
#define BG_CHAR "."
namespace GLCD
{
cDriverSimLCD::cDriverSimLCD(cDriverConfig * config) : cDriver(config)
{
}
int cDriverSimLCD::Init(void)
{
width = config->width;
if (width <= 0)
width = 240;
height = config->height;
if (height <= 0)
height = 128;
for (unsigned int i = 0; i < config->options.size(); i++)
{
if (config->options[i].name == "")
{
}
}
// setup lcd array
LCD = new uint32_t *[width];
if (LCD)
{
for (int x = 0; x < width; x++)
{
LCD[x] = new uint32_t[height];
//memset(LCD[x], 0, height);
}
}
*oldConfig = *config;
// clear display
Clear();
syslog(LOG_INFO, "%s: SIMLCD initialized.\n", config->name.c_str());
return 0;
}
int cDriverSimLCD::DeInit(void)
{
// free lcd array
if (LCD)
{
for (int x = 0; x < width; x++)
{
delete[] LCD[x];
}
delete[] LCD;
}
return 0;
}
int cDriverSimLCD::CheckSetup(void)
{
if (config->width != oldConfig->width ||
config->height != oldConfig->height)
{
DeInit();
Init();
return 0;
}
if (config->upsideDown != oldConfig->upsideDown ||
config->invert != oldConfig->invert)
{
oldConfig->upsideDown = config->upsideDown;
oldConfig->invert = config->invert;
return 1;
}
return 0;
}
void cDriverSimLCD::Clear(void)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
LCD[x][y] = GRAPHLCD_White;
}
}
}
void cDriverSimLCD::SetPixel(int x, int y, uint32_t data)
{
if (x >= width || y >= height)
return;
if (config->upsideDown)
{
// upside down orientation
x = width - 1 - x;
y = height - 1 - y;
}
LCD[x][y] = data;
}
void cDriverSimLCD::Refresh(bool refreshAll)
{
FILE * fp = NULL;
int x;
int y;
if (CheckSetup() > 0)
refreshAll = true;
fp = fopen(DISPLAY_REFRESH_FILE, "r");
if (!fp || refreshAll)
{
if (fp)
fclose(fp);
fp = fopen(DISPLAY_DATA_FILE, "w");
if (fp)
{
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
if (LCD[x][y] == GRAPHLCD_Black)
{
if (!config->invert)
{
fprintf(fp,FG_CHAR);
} else
{
fprintf(fp,BG_CHAR);
}
}
else
{
if (!config->invert)
{
fprintf(fp,BG_CHAR);
} else
{
fprintf(fp,FG_CHAR);
}
}
}
fprintf(fp,"\n");
}
fclose(fp);
}
fp = fopen(DISPLAY_REFRESH_FILE, "w");
fclose(fp);
}
else
{
fclose(fp);
}
}
uint32_t cDriverSimLCD::GetBackgroundColor(void)
{
return GRAPHLCD_White;
}
bool cDriverSimLCD::GetDriverFeature(const std::string & Feature, int & value)
{
if (strcasecmp(Feature.c_str(), "depth") == 0) {
value = 1;
return true;
} else if (strcasecmp(Feature.c_str(), "ismonochrome") == 0) {
value = true;
return true;
} else if (strcasecmp(Feature.c_str(), "isgreyscale") == 0 || strcasecmp(Feature.c_str(), "isgrayscale") == 0) {
value = false;
return true;
} else if (strcasecmp(Feature.c_str(), "iscolour") == 0 || strcasecmp(Feature.c_str(), "iscolor") == 0) {
value = false;
return true;
} else if (strcasecmp(Feature.c_str(), "touch") == 0 || strcasecmp(Feature.c_str(), "touchscreen") == 0) {
value = false;
return true;
}
value = 0;
return false;
}
} // end of namespace
|