summaryrefslogtreecommitdiff
path: root/glcddrivers
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2013-04-19 00:39:40 +0200
committermrwastl <mrwastl@users.sourceforge.net>2013-04-19 00:39:40 +0200
commitc45745ea462ea3758daffc6302552993ba4c3be0 (patch)
treed0b1896966e7a6c944e448238be6c64ef53591a6 /glcddrivers
parent54d0651c970394d391f487afbb42a2592b033d1f (diff)
downloadgraphlcd-base-c45745ea462ea3758daffc6302552993ba4c3be0.tar.gz
graphlcd-base-c45745ea462ea3758daffc6302552993ba4c3be0.tar.bz2
added new driver 'vncserver' (contrib. by Michael Heyer); ax206dpf: type change of an array to make new GCC versions happy
Diffstat (limited to 'glcddrivers')
-rw-r--r--glcddrivers/Makefile7
-rw-r--r--glcddrivers/ax206dpf.c4
-rw-r--r--glcddrivers/drivers.c10
-rw-r--r--glcddrivers/drivers.h3
-rw-r--r--glcddrivers/vncserver.c211
-rw-r--r--glcddrivers/vncserver.h51
6 files changed, 284 insertions, 2 deletions
diff --git a/glcddrivers/Makefile b/glcddrivers/Makefile
index a5c7481..8287bb2 100644
--- a/glcddrivers/Makefile
+++ b/glcddrivers/Makefile
@@ -42,6 +42,13 @@ ifeq ($(shell pkg-config --exists libusb && echo 1), 1)
endif
endif
+ifeq ($(shell libvncserver-config --version >/dev/null && echo 1), 1)
+ DEFINES += -DHAVE_LIBVNCSERVER
+ OBJS += vncserver.o
+ INCLUDES += $(shell libvncserver-config --cflags)
+ LIBS += $(shell libvncserver-config --libs)
+endif
+
### Implicit rules:
%.o: %.c
diff --git a/glcddrivers/ax206dpf.c b/glcddrivers/ax206dpf.c
index f715585..acae61d 100644
--- a/glcddrivers/ax206dpf.c
+++ b/glcddrivers/ax206dpf.c
@@ -890,7 +890,7 @@ static struct usb_device *find_dev(int index)
return NULL;
}
-char g_buf[] = {
+unsigned char g_buf[] = {
0x55, 0x53, 0x42, 0x43, // dCBWSignature
0xde, 0xad, 0xbe, 0xef, // dCBWTag
0x00, 0x80, 0x00, 0x00, // dCBWLength
@@ -920,7 +920,7 @@ int emulate_scsi(usb_dev_handle *dev, unsigned char *cmd, int cmdlen, char out,
g_buf[10] = block_len >> 16;
g_buf[11] = block_len >> 24;
- ret = usb_bulk_write(dev, ENDPT_OUT, g_buf, sizeof(g_buf), 1000);
+ ret = usb_bulk_write(dev, ENDPT_OUT, (char*)g_buf, sizeof(g_buf), 1000);
if (ret < 0) return ret;
if (out == DIR_OUT) {
diff --git a/glcddrivers/drivers.c b/glcddrivers/drivers.c
index 62ad57f..9aa70ac 100644
--- a/glcddrivers/drivers.c
+++ b/glcddrivers/drivers.c
@@ -36,6 +36,9 @@
#ifdef HAVE_picoLCD_256x64_EXPERIMENTAL
#include "picoLCD_256x64.h"
#endif
+#ifdef HAVE_LIBVNCSERVER
+#include "vncserver.h"
+#endif
namespace GLCD
{
@@ -66,6 +69,9 @@ tDriver drivers[] =
#ifdef HAVE_picoLCD_256x64_EXPERIMENTAL
{"picolcd256x64", kDriverPicoLCD_256x64},
#endif
+#ifdef HAVE_LIBVNCSERVER
+ {"vncserver", kDriverVncServer},
+#endif
{"", kDriverUnknown}
};
@@ -132,6 +138,10 @@ cDriver * CreateDriver(int driverID, cDriverConfig * config)
case kDriverPicoLCD_256x64:
return new cDriverPicoLCD_256x64(config);
#endif
+#ifdef HAVE_LIBVNCSERVER
+ case kDriverVncServer:
+ return new cDriverVncServer(config);
+#endif
case kDriverUnknown:
default:
return NULL;
diff --git a/glcddrivers/drivers.h b/glcddrivers/drivers.h
index 1c1ee8e..c7bbdf8 100644
--- a/glcddrivers/drivers.h
+++ b/glcddrivers/drivers.h
@@ -46,6 +46,9 @@ enum eDriver
#ifdef HAVE_picoLCD_256x64_EXPERIMENTAL
kDriverPicoLCD_256x64 = 18,
#endif
+#ifdef HAVE_LIBVNCSERVER
+ kDriverVncServer = 19,
+#endif
kDriverSerDisp = 100,
kDriverG15daemon = 200
};
diff --git a/glcddrivers/vncserver.c b/glcddrivers/vncserver.c
new file mode 100644
index 0000000..8461548
--- /dev/null
+++ b/glcddrivers/vncserver.c
@@ -0,0 +1,211 @@
+/*
+ * GraphLCD driver library
+ *
+ * vncserver.h - vncserver device
+ * Output goes to a vncserver device
+ *
+ * This file is released under the GNU General Public License. Refer
+ * to the COPYING file distributed with this package.
+ *
+ * (c) 2013 Michael Heyer
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+
+#include "common.h"
+#include "config.h"
+#include "vncserver.h"
+
+
+namespace GLCD
+{
+
+cDriverVncServer::cDriverVncServer(cDriverConfig * config)
+: cDriver(config),
+ offbuff(0)
+{
+}
+
+int cDriverVncServer::Init()
+{
+ printf(" init.\n");
+
+ width = config->width;
+ height = config->height;
+
+ // Figure out the size of the screen in bytes
+ screensize = width * height * 4;
+ depth = 24;
+ server = rfbGetScreen(NULL,NULL,width,height,8,3,4);
+ if (!server)
+ {
+ syslog(LOG_ERR, "failed to creat vncserver device.\n");
+ return -1;
+ }
+
+ for (unsigned int i = 0; i < config->options.size(); i++)
+ {
+ if (config->options[i].name == "HttpDir")
+ {
+ server->httpDir = (char *)config->options[i].value.c_str();
+ }
+ }
+
+ // init bounding box
+ bbox[0] = width - 1; // x top
+ bbox[1] = height - 1; // y top
+ bbox[2] = 0; // x bottom
+ bbox[3] = 0; // y bottom
+
+ // reserve another memory to draw into
+ offbuff = new char[screensize];
+ if (!offbuff)
+ {
+ syslog(LOG_ERR, "%s: failed to alloc memory for vncserver device.\n", config->name.c_str());
+ return -1;
+ }
+
+ server->frameBuffer=offbuff;
+ rfbInitServer(server);
+
+ *oldConfig = *config;
+
+ // clear display
+ Refresh(true);
+
+ rfbRunEventLoop(server, 5000, true);
+
+ syslog(LOG_INFO, "%s: VncServer initialized.\n", config->name.c_str());
+ return 0;
+}
+
+int cDriverVncServer::DeInit()
+{
+ if (offbuff)
+ delete[] offbuff;
+ return 0;
+}
+
+int cDriverVncServer::CheckSetup()
+{
+ if (config->device != oldConfig->device ||
+ config->port != oldConfig->port ||
+ 32 != 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 cDriverVncServer::SetPixel(int x, int y, uint32_t data)
+{
+ int location;
+
+ if (x >= width || y >= height)
+ return;
+
+ if (config->upsideDown)
+ {
+ x = width - 1 - x;
+ y = height - 1 - y;
+ }
+
+ location = (x + y * width) * 4;
+ unsigned char r,g,b;
+ r = (data & 0x00FF0000) >> 16;
+ g = (data & 0x0000FF00) >> 8;
+ b = (data & 0x000000FF) >> 0;
+ if (config->invert) {
+ r = 255 - r;
+ g = 255 - g;
+ b = 255 - b;
+ }
+ *(offbuff + location + 0) = r;
+ *(offbuff + location + 1) = g;
+ *(offbuff + location + 2) = b;
+
+ if (x < bbox[0]) bbox[0] = x;
+ if (y < bbox[1]) bbox[1] = y;
+ if (x > bbox[2]) bbox[2] = x;
+ if (y > bbox[3]) bbox[3] = y;
+}
+
+void cDriverVncServer::Clear()
+{
+ memset(offbuff, 0, screensize);
+ processDamage();
+}
+
+void cDriverVncServer::Refresh(bool refreshAll)
+{
+ if (refreshAll) {
+ bbox[0] = 0;
+ bbox[1] = 0;
+ bbox[2] = width - 1;
+ bbox[3] = height - 1;
+ }
+ processDamage();
+}
+
+bool cDriverVncServer::GetDriverFeature (const std::string & Feature, int & value) {
+ if (offbuff) {
+ if (strcasecmp(Feature.c_str(), "depth") == 0) {
+ value = depth;
+ return true;
+ } else if (strcasecmp(Feature.c_str(), "ismonochrome") == 0) {
+ value = 0;
+ return true;
+ } else if (strcasecmp(Feature.c_str(), "isgreyscale") == 0 || strcasecmp(Feature.c_str(), "isgrayscale") == 0) {
+ value = 0;
+ return true;
+ } else if (strcasecmp(Feature.c_str(), "iscolour") == 0 || strcasecmp(Feature.c_str(), "iscolor") == 0) {
+ value = 1;
+ return true;
+#if 0
+ } else if (strcasecmp(Feature.c_str(), "touch") == 0 || strcasecmp(Feature.c_str(), "touchscreen") == 0) {
+ if (...) {
+ value = (...) ? 1 : 0;
+ }
+ return true;
+#endif
+ }
+ }
+ value = 0;
+ return false;
+}
+
+
+/* defines for different damage processing calls needed by _update() */
+void cDriverVncServer::processDamage (void) {
+
+ if (!((bbox[0] == (width - 1)) && (bbox[1] == (height - 1)) && (bbox[2] == 0) && (bbox[3] == 0))) {
+ rfbMarkRectAsModified(server,bbox[0],bbox[1],bbox[2],bbox[3]);
+ }
+
+ /* reset bounding box */
+ bbox[0] = width - 1;
+ bbox[1] = height - 1;
+ bbox[2] = 0;
+ bbox[3] = 0;
+}
+
+} // end of namespace
diff --git a/glcddrivers/vncserver.h b/glcddrivers/vncserver.h
new file mode 100644
index 0000000..2cb055f
--- /dev/null
+++ b/glcddrivers/vncserver.h
@@ -0,0 +1,51 @@
+/*
+ * GraphLCD driver library
+ *
+ * vncserver.h - vncserver device
+ * Output goes to a vncserver device
+ *
+ * This file is released under the GNU General Public License. Refer
+ * to the COPYING file distributed with this package.
+ *
+ * (c) 2013 Michael Heyer
+ */
+
+#ifndef _GLCDDRIVERS_VNCSERVER_H_
+#define _GLCDDRIVERS_VNCSERVER_H_
+
+#include "driver.h"
+#include <rfb/rfb.h>
+
+namespace GLCD
+{
+
+class cDriverConfig;
+
+class cDriverVncServer : public cDriver
+{
+private:
+ unsigned char ** LCD;
+ char *offbuff;
+ rfbScreenInfoPtr server;
+ long int screensize;
+ int bbox[4];
+ int depth;
+
+ int CheckSetup();
+ void processDamage (void);
+protected:
+ virtual bool GetDriverFeature (const std::string & Feature, int & value);
+public:
+ cDriverVncServer(cDriverConfig * config);
+
+ virtual int Init();
+ virtual int DeInit();
+
+ virtual void Clear();
+ virtual void SetPixel(int x, int y, uint32_t data);
+ virtual void Refresh(bool refreshAll = false);
+};
+
+} // end of namespace
+
+#endif