Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 547 lines (469 sloc) 14.899 kb
c23b9745 » michux
2009-03-25 add vnc driver
1 /* $Id$
2 * $URL$
3 *
4 * Libvncserver driver
5 *
6 * Copyright (C) 2009 Michael Vogt <michu@neophob.com>
7 * Modified from sample code by:
8 * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
9 * Copyright (C) 2005, 2006, 2007, 2008, 2009 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
10 *
11 * This file is part of LCD4Linux.
12 *
13 * LCD4Linux is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * LCD4Linux is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28
29 /*
30 *
31 * exported fuctions:
32 *
33 * struct DRIVER drv_vnc
34 *
35 */
36
37 #include "config.h"
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <string.h>
43 #include <errno.h>
44
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
45 #include <rfb/rfb.h>
c23b9745 » michux
2009-03-25 add vnc driver
46
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
47 /* struct timeval */
48 #include <sys/time.h>
49
c23b9745 » michux
2009-03-25 add vnc driver
50 #include "debug.h"
51 #include "cfg.h"
52 #include "qprintf.h"
53 #include "udelay.h"
54 #include "plugin.h"
55 #include "widget.h"
56 #include "widget_text.h"
57 #include "widget_icon.h"
58 #include "widget_bar.h"
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
59 #include "widget_keypad.h"
c23b9745 » michux
2009-03-25 add vnc driver
60 #include "drv.h"
61 #include "drv_generic_graphic.h"
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
62 #include "drv_generic_keypad.h"
c23b9745 » michux
2009-03-25 add vnc driver
63
48525314 » michux
2009-03-30 add fps limiter
64 //todo: key widget text
c23b9745 » michux
2009-03-25 add vnc driver
65
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
66 #define NO_MOUSE_BUTTON_PRESSED 0
67 #define LEFT_MOUSE_BUTTON_PRESSED 1
48525314 » michux
2009-03-30 add fps limiter
68 #define SLEEP_STEPS 1000
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
69
c23b9745 » michux
2009-03-25 add vnc driver
70 static char Name[] = "VNC";
71
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
72 static int xres = 320; /* screen settings */
c23b9745 » michux
2009-03-25 add vnc driver
73 static int yres = 200;
74 static int BPP = 4;
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
75 static int max_clients = 2; /* max connected clients */
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
76 static int osd_showtime = 2000; /* time to display the osd in ms */
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
77 static int buttons = 2; /* number of keypad buttons */
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
78 static int buttonsize = 50; /* size of keypad buttons */
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
79 static int keypadxofs = 0;
80 static int keypadyofs = 0;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
81 static int keypadgap = 0;
3c865cea » michux
2009-03-27 add server port as config option, rename options
82 static int port = 5900;
3428f32c » michux
2009-03-31 drv_vnc: http port as option
83 static int httpPort = 5800;
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
84 static unsigned char framer = 0;
85 static unsigned char frameg = 0;
86 static unsigned char frameb = 0;
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
87
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
88 static rfbScreenInfoPtr server; /* vnc device */
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
89 static struct timeval osd_timestamp;
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
90 static int show_keypad_osd = 0; /* is the osd active? */
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
91 static int clientCount = 0; /* currently connected clients */
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
92 static int mouse_x = 0;
93 static int mouse_y = 0;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
94 static int mouse_stat_old = 0;
95 static int process_event = 0;
48525314 » michux
2009-03-30 add fps limiter
96 static long frames = 0;
a4601a3a » michux
2009-03-30 add UNSECURE password option to drv_vnc - SSH would be the better cho…
97 static char *password;
27bba2d8 » michux
2009-03-31 drv_vnc: run as http daemon
98 static char *javaClassFiles;
48525314 » michux
2009-03-30 add fps limiter
99 static struct timeval startDriver;
100 static int maxfps = -1;
c23b9745 » michux
2009-03-25 add vnc driver
101
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
102 /* draws a simple rect, used to display keypad */
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
103 int draw_rect(int x, int y, int size, unsigned char col, char *buffer)
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
104 {
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
105 int ofs, ofs2, i, ret;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
106 unsigned char colr, colg;
107 colr = colg = col;
108 ret = 0;
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
109
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
110 /* check if mouse is in current rect */
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
111 if (mouse_x > x && mouse_x < (x + size))
3c865cea » michux
2009-03-27 add server port as config option, rename options
112 if (mouse_y > y && mouse_y < (y + size)) {
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
113 colr = framer;
114 colg = frameg;
115 col = frameb;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
116 ret = 1;
117 }
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
118
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
119 ofs2 = size * xres * BPP;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
120 for (i = x; i < x + size; i++) {
121 ofs = (i + xres * y) * BPP;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
122 buffer[ofs + ofs2] = colr;
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
123 buffer[ofs++] = colr;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
124 buffer[ofs + ofs2] = colg;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
125 buffer[ofs++] = colg;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
126 buffer[ofs + ofs2] = col;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
127 buffer[ofs++] = col;
128 }
129
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
130 ofs2 = size * BPP;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
131 for (i = y; i <= y + size; i++) {
132 ofs = (i * xres + x) * BPP;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
133 buffer[ofs + ofs2] = colr;
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
134 buffer[ofs++] = colr;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
135 buffer[ofs + ofs2] = colg;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
136 buffer[ofs++] = colg;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
137 buffer[ofs + ofs2] = col;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
138 buffer[ofs++] = col;
139 }
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
140 return ret;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
141 }
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
142
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
143 void display_keypad()
144 {
145 int i, rectx, recty;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
146 int active;
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
147 for (i = 0; i < buttons; i++) {
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
148 rectx = keypadxofs + (i * (buttonsize + keypadgap));
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
149 recty = keypadyofs /*+ (i*(buttonsize+gap)) */ ;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
150 active = draw_rect(rectx, recty, buttonsize, 0, server->frameBuffer);
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
151
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
152 /* if the lmb button is pressed and we didnt processed the event yet - do it now */
153 if (active == 1 && process_event == 1) {
3c865cea » michux
2009-03-27 add server port as config option, rename options
154 drv_generic_keypad_press(i + 1);
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
155 //debug("mouse in keypad nr %d", i);
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
156 process_event = 0;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
157 }
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
158 }
159 }
160
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
161 /* called if a vnc client disconnects */
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
162 static void clientgone( __attribute__ ((unused)) rfbClientPtr cl)
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
163 {
164 if (clientCount > 0)
165 clientCount--;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
166 debug("%d clients connected", clientCount);
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
167 }
168
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
169 /* called if a vnc client connect */
170 static enum rfbNewClientAction hook_newclient(rfbClientPtr cl)
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
171 {
89efe119 » michux
2009-03-26 add max client option
172 if (clientCount < max_clients) {
173 clientCount++;
174 cl->clientGoneHook = clientgone;
baa22cf1 » michux
2009-03-26 add sample cfg for vnc driver, indent
175 debug("%d clients connected", clientCount);
89efe119 » michux
2009-03-26 add max client option
176 return RFB_CLIENT_ACCEPT;
177 } else {
baa22cf1 » michux
2009-03-26 add sample cfg for vnc driver, indent
178 info("client refused due max. client connections (%d)", clientCount);
89efe119 » michux
2009-03-26 add max client option
179 return RFB_CLIENT_REFUSE;
180 }
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
181 }
182
e3d860b9 » michux
2009-03-25 minor fixup
183 /* handle mouse action */
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
184 static void hook_mouseaction(int buttonMask, int x, int y, rfbClientPtr cl)
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
185 {
186 if (x >= 0 && y >= 0 && x < xres && y < yres) {
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
187 process_event = 0;
188
189 /* process ONLY if mouse button is released. */
190 if (buttonMask == NO_MOUSE_BUTTON_PRESSED && mouse_stat_old == LEFT_MOUSE_BUTTON_PRESSED) {
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
191 gettimeofday(&osd_timestamp, NULL);
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
192 process_event = 1;
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
193 mouse_x = x;
194 mouse_y = y;
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
195 }
196 //debug("btnMask: %d, old state: %d, processevent: %d", buttonMask, mouse_stat_old, process_event);
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
197
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
198 /* show osd display if mouse is pressed */
199 if (buttonMask == 1) {
200 gettimeofday(&osd_timestamp, NULL);
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
201 mouse_x = x;
202 mouse_y = y;
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
203 if (show_keypad_osd == 0) {
204 /* no osd until yet, activate osd keypad ... */
205 show_keypad_osd = 1;
206 }
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
207 }
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
208
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
209 }
210
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
211 mouse_stat_old = buttonMask;
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
212 rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
213 }
214
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
215 static int drv_vnc_keypad(const int num)
216 {
217 int val = WIDGET_KEY_PRESSED;
218
219 switch (num) {
220 case 1:
221 val += WIDGET_KEY_UP;
222 break;
223 case 2:
224 val += WIDGET_KEY_DOWN;
225 break;
226 case 3:
227 val += WIDGET_KEY_LEFT;
228 break;
229 case 4:
230 val += WIDGET_KEY_RIGHT;
231 break;
232 case 5:
233 val += WIDGET_KEY_CONFIRM;
234 break;
235 case 6:
236 val += WIDGET_KEY_CANCEL;
237 break;
238 default:
239 error("%s: unknown keypad value %d", Name, num);
240 }
c23b9745 » michux
2009-03-25 add vnc driver
241
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
242 return val;
243 }
244
245 /* init the driver, read config */
c23b9745 » michux
2009-03-25 add vnc driver
246 static int drv_vnc_open(const char *Section)
247 {
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
248 int keypadcol;
3c865cea » michux
2009-03-27 add server port as config option, rename options
249 if (cfg_number(Section, "Xres", 320, 32, 2048, &xres) < 1) {
250 info("[DRV_VNC] no '%s.Xres' entry from %s using default %d", Section, cfg_source(), xres);
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
251 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
252 if (cfg_number(Section, "Yres", 200, 32, 2048, &yres) < 1) {
253 info("[DRV_VNC] no '%s.Yres' entry from %s using default %d", Section, cfg_source(), yres);
c23b9745 » michux
2009-03-25 add vnc driver
254 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
255 if (cfg_number(Section, "Bpp", 4, 1, 4, &BPP) < 1) {
256 info("[DRV_VNC] no '%s.Bpp' entry from %s using default %d", Section, cfg_source(), BPP);
c23b9745 » michux
2009-03-25 add vnc driver
257 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
258 if (cfg_number(Section, "Maxclients", 2, 1, 64, &max_clients) < 1) {
259 info("[DRV_VNC] no '%s.Maxclients' entry from %s using default %d", Section, cfg_source(), max_clients);
89efe119 » michux
2009-03-26 add max client option
260 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
261 if (cfg_number(Section, "Osd_showtime", 2000, 500, 60000, &osd_showtime) < 1) {
262 info("[DRV_VNC] no '%s.Osd_showtime' entry from %s using default %d", Section, cfg_source(), osd_showtime);
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
263 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
264 if (cfg_number(Section, "Buttons", 2, 0, 6, &buttons) < 1) {
265 info("[DRV_VNC] no '%s.Buttons' entry from %s using default %d", Section, cfg_source(), buttons);
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
266 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
267 if (cfg_number(Section, "Buttonsize", 50, 8, 256, &buttonsize) < 1) {
268 info("[DRV_VNC] no '%s.Buttonsize' entry from %s using default %d", Section, cfg_source(), buttonsize);
fec42ab3 » michux
2009-03-27 some more keypad stuff for vnc driver...
269 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
270 if (cfg_number(Section, "Keypadxofs", 0, 0, 4096, &keypadxofs) < 1) {
271 info("[DRV_VNC] no '%s.Keypadxofs' entry from %s using default %d", Section, cfg_source(), keypadxofs);
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
272 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
273 if (cfg_number(Section, "Keypadyofs", 0, 0, 4096, &keypadyofs) < 1) {
274 info("[DRV_VNC] no '%s.Keypadyofs' entry from %s using default %d", Section, cfg_source(), keypadyofs);
275 }
7ca8109b » michux
2009-03-28 update keypad handling, add more options, remove compiler waarnings
276 if (cfg_number(Section, "Keypadgap", 10, 0, 2048, &keypadgap) < 1) {
277 info("[DRV_VNC] no '%s.Keypadgap' entry from %s using default %d", Section, cfg_source(), keypadgap);
278 }
6200a307 » michux
2009-03-28 add keypadframe color as parameter, some minor fixups
279 if (cfg_number(Section, "Keypadcol", 255, 0, 0xffffff, &keypadcol) < 1) {
280 info("[DRV_VNC] no '%s.Keypadcol' entry from %s using default red", Section, cfg_source());
281 framer = 255;
282 } else {
283 framer = keypadcol & 0xff;
284 frameg = (keypadcol & 0xff00) >> 8;
285 frameb = (keypadcol & 0xff0000) >> 16;
286 }
3c865cea » michux
2009-03-27 add server port as config option, rename options
287 if (cfg_number(Section, "Port", 5900, 1, 65535, &port) < 1) {
288 info("[DRV_VNC] no '%s.Port' entry from %s using default %d", Section, cfg_source(), port);
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
289 }
3428f32c » michux
2009-03-31 drv_vnc: http port as option
290 if (cfg_number(Section, "HttpPort", 5800, 1, 65535, &httpPort) < 1) {
291 info("[DRV_VNC] no '%s.HttpPort' entry from %s using default %d", Section, cfg_source(), httpPort);
292 }
48525314 » michux
2009-03-30 add fps limiter
293 if (cfg_number(Section, "Maxfps", -1, -1, 512, &maxfps) < 1) {
294 info("[DRV_VNC] no '%s.Maxfps' entry from %s using default %d", Section, cfg_source(), maxfps);
295 }
a4601a3a » michux
2009-03-30 add UNSECURE password option to drv_vnc - SSH would be the better cho…
296 password = cfg_get(Section, "Password", NULL);
297 if (password != NULL) {
298 info("[DRV_VNC] password enabled");
299 }
27bba2d8 » michux
2009-03-31 drv_vnc: run as http daemon
300 javaClassFiles = cfg_get(Section, "HttpDir", NULL);
301 if (javaClassFiles != NULL) {
302 info("[DRV_VNC] HTTP server enabled");
303 }
c23b9745 » michux
2009-03-25 add vnc driver
304 return 0;
305 }
306
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
307 /* shutdown driver, release allocated stuff */
c23b9745 » michux
2009-03-25 add vnc driver
308 static int drv_vnc_close(void)
309 {
310 rfbShutdownServer(server, TRUE);
311 free(server->frameBuffer);
312 return 0;
313 }
314
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
315
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
316 /* actual blitting method */
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
317 static void drv_vnc_blit_it(const int row, const int col, const int height, const int width, unsigned char *buffer)
c23b9745 » michux
2009-03-25 add vnc driver
318 {
48525314 » michux
2009-03-30 add fps limiter
319 static int sleep = 0;
c23b9745 » michux
2009-03-25 add vnc driver
320 int r, c, ofs;
321 RGBA p;
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
322
c23b9745 » michux
2009-03-25 add vnc driver
323 for (r = row; r < row + height; r++) {
324 for (c = col; c < col + width; c++) {
325 p = drv_generic_graphic_rgb(r, c);
326 ofs = (r * xres + c) * BPP;
327 buffer[ofs++] = p.R;
328 buffer[ofs++] = p.G;
329 buffer[ofs++] = p.B;
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
330 buffer[ofs] = 255;
c23b9745 » michux
2009-03-25 add vnc driver
331 }
332 }
611fcee6 » michux
2009-03-27 update keypad function for vnc driver
333
334 /* display osd keypad */
335 if (show_keypad_osd == 1) {
336 display_keypad();
337
338 /* check if the osd should be disabled after the waittime */
339 struct timeval now;
340 gettimeofday(&now, NULL);
341 int timedelta = (now.tv_sec - osd_timestamp.tv_sec) * 1000 + (now.tv_usec - osd_timestamp.tv_usec) / 1000;
342
343 if (timedelta > osd_showtime) {
344 show_keypad_osd = 0;
345 }
346 }
48525314 » michux
2009-03-30 add fps limiter
347 frames++;
348 if ((frames % 10) == 0 && maxfps > 0) {
349 struct timeval blittime;
350 gettimeofday(&blittime, NULL);
351 int time_since_start =
352 (blittime.tv_sec - startDriver.tv_sec) * 1000 + (blittime.tv_usec - startDriver.tv_usec) / 1000;
6322058d » michux
2009-04-15 timer fix for vnc driver
353
354 /* if time changed since start of lcd4linux */
355 if (time_since_start < 0) {
356 gettimeofday(&startDriver, NULL);
357 time_since_start =
358 (blittime.tv_sec - startDriver.tv_sec) * 1000 + (blittime.tv_usec - startDriver.tv_usec) / 1000;
359 if (time_since_start == 0)
360 time_since_start = 1;
361 }
362 //info("time :%d, frames: %d, sleep: %d", time_since_start, frames, sleep);
363
48525314 » michux
2009-03-30 add fps limiter
364 int fps = (int) (1000 * frames / time_since_start);
365
366 if (fps > maxfps) {
367 sleep += SLEEP_STEPS;
368 }
369
7228a0e8 » michux
2009-03-30 fix fps delay error
370 if (fps < maxfps && sleep >= SLEEP_STEPS) {
48525314 » michux
2009-03-30 add fps limiter
371 sleep -= SLEEP_STEPS;
372 }
373 }
374 usleep(sleep);
375
c23b9745 » michux
2009-03-25 add vnc driver
376 }
377
48525314 » michux
2009-03-30 add fps limiter
378
c23b9745 » michux
2009-03-25 add vnc driver
379 static void drv_vnc_blit(const int row, const int col, const int height, const int width)
380 {
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
381
89efe119 » michux
2009-03-26 add max client option
382 if (rfbIsActive(server)) {
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
383 drv_vnc_blit_it(row, col, height, width, (unsigned char *) server->frameBuffer);
89efe119 » michux
2009-03-26 add max client option
384
9ad3a788 » michux
2009-03-25 I just wanted to commit the 1000st change to lcd4linux ;)
385 if (clientCount > 0) {
e3d860b9 » michux
2009-03-25 minor fixup
386 rfbMarkRectAsModified(server, 0, 0, xres, yres);
9ad3a788 » michux
2009-03-25 I just wanted to commit the 1000st change to lcd4linux ;)
387 }
eed0c5c3 » michux
2009-03-27 vnc driver: keypad works now
388 rfbProcessEvents(server, server->deferUpdateTime * 500);
c23b9745 » michux
2009-03-25 add vnc driver
389 }
390 }
391
392 /* start graphic display */
393 static int drv_vnc_start(const char *section)
394 {
395 char *s;
396
397 s = cfg_get(section, "Font", "6x8");
398 if (s == NULL || *s == '\0') {
399 error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
400 return -1;
401 }
402
403 XRES = -1;
404 YRES = -1;
405 if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
406 error("%s: bad Font '%s' from %s", Name, s, cfg_source());
407 return -1;
408 }
409
410 /* Fixme: provider other fonts someday... */
411 if (XRES != 6 && YRES != 8) {
412 error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
413 return -1;
414 }
415
416 /* open communication with the display */
417 if (drv_vnc_open(section) < 0) {
418 return -1;
419 }
420
421 /* you surely want to allocate a framebuffer or something... */
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
422 server = rfbGetScreen(0, NULL, xres, yres, 8, 3, BPP);
c23b9745 » michux
2009-03-25 add vnc driver
423 server->desktopName = "LCD4Linux VNC Driver";
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
424 server->frameBuffer = (char *) malloc(xres * yres * BPP);
425 server->alwaysShared = (1 == 1);
3c865cea » michux
2009-03-27 add server port as config option, rename options
426 server->port = port;
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
427 server->ptrAddEvent = hook_mouseaction;
428 server->newClientHook = hook_newclient;
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
429
a4601a3a » michux
2009-03-30 add UNSECURE password option to drv_vnc - SSH would be the better cho…
430 if (password != NULL) {
431 char **passwds = malloc(sizeof(char **) * 2);
432 passwds[0] = password;
433 passwds[1] = 0;
434 server->authPasswdData = (void *) passwds;
435 server->passwordCheck = rfbCheckPasswordByList;
436 }
27bba2d8 » michux
2009-03-31 drv_vnc: run as http daemon
437 if (javaClassFiles != NULL) {
438 server->httpDir = javaClassFiles;
439 server->httpEnableProxyConnect = TRUE;
3428f32c » michux
2009-03-31 drv_vnc: http port as option
440 server->httpPort = httpPort;
27bba2d8 » michux
2009-03-31 drv_vnc: run as http daemon
441 }
c23b9745 » michux
2009-03-25 add vnc driver
442 /* Initialize the server */
443 rfbInitServer(server);
ec8146e9 » michux
2009-03-25 more vnc driver stuff...
444
c23b9745 » michux
2009-03-25 add vnc driver
445 /* set width/height */
446 DROWS = yres;
447 DCOLS = xres;
448
48525314 » michux
2009-03-30 add fps limiter
449 /* set timestamp */
450 gettimeofday(&startDriver, NULL);
451
c23b9745 » michux
2009-03-25 add vnc driver
452 return 0;
453 }
454
455 /****************************************/
456 /*** widget callbacks ***/
457 /****************************************/
458
459
460 /* using drv_generic_text_draw(W) */
461 /* using drv_generic_text_icon_draw(W) */
462 /* using drv_generic_text_bar_draw(W) */
463 /* using drv_generic_gpio_draw(W) */
464
465
466 /****************************************/
467 /*** exported functions ***/
468 /****************************************/
469
470
471 /* list models */
472 int drv_vnc_list(void)
473 {
474 printf("vnc server");
475 return 0;
476 }
477
478
479 /* initialize driver & display */
480 int drv_vnc_init(const char *section, const int quiet)
481 {
482 int ret;
483
484 /* real worker functions */
485 drv_generic_graphic_real_blit = drv_vnc_blit;
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
486 drv_generic_keypad_real_press = drv_vnc_keypad;
c23b9745 » michux
2009-03-25 add vnc driver
487
488 /* start display */
489 if ((ret = drv_vnc_start(section)) != 0)
490 return ret;
491
492 /* initialize generic graphic driver */
493 if ((ret = drv_generic_graphic_init(section, Name)) != 0)
494 return ret;
495
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
496 /* initialize generic key pad driver */
497 if ((ret = drv_generic_keypad_init(section, Name)) != 0)
498 return ret;
499
c23b9745 » michux
2009-03-25 add vnc driver
500 if (!quiet) {
501 char buffer[40];
502 qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
503 if (drv_generic_graphic_greet(buffer, NULL)) {
504 sleep(3);
505 drv_generic_graphic_clear();
506 }
507 }
508
509 return 0;
510 }
511
512
513 /* close driver & display */
514 int drv_vnc_quit(const int quiet)
515 {
516 info("%s: shutting down.", Name);
517
518 /* clear display */
519 drv_generic_graphic_clear();
520
521 /* say goodbye... */
522 if (!quiet) {
523 drv_generic_graphic_greet("goodbye!", NULL);
524 }
525
526 drv_generic_graphic_quit();
4ce74802 » michux
2009-03-26 vnc driver: add beta keypad support
527 drv_generic_keypad_quit();
a4601a3a » michux
2009-03-30 add UNSECURE password option to drv_vnc - SSH would be the better cho…
528 if (password != NULL) {
529 free(password);
530 }
27bba2d8 » michux
2009-03-31 drv_vnc: run as http daemon
531 if (javaClassFiles != NULL) {
532 free(javaClassFiles);
533 }
c23b9745 » michux
2009-03-25 add vnc driver
534
535 debug("closing connection");
536 drv_vnc_close();
537
538 return (0);
539 }
540
541
542 DRIVER drv_vnc = {
543 .name = Name,
544 .list = drv_vnc_list,
545 .init = drv_vnc_init,
546 .quit = drv_vnc_quit,
547 };
Something went wrong with that request. Please try again.