Import Upstream version 1.9.5.2
This commit is contained in:
1 parent
9602397440
commit
18176a4efe
51 files changed
+46043
-361
No files matched your search
+107
-9
@@ -15,9 +15,9 @@
|
||||
along with g15daemon; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
(c) 2006 Mike Lampard, Philip Lawatsch, and others
|
||||
(c) 2006-2008 Mike Lampard, Philip Lawatsch, and others
|
||||
|
||||
$Revision: 339 $ - $Date: 2007-12-15 07:10:26 +0100 (Sat, 15 Dec 2007) $ $Author: mlampard $
|
||||
$Revision: 449 $ - $Date: 2008-01-24 17:42:07 +1030 (Thu, 24 Jan 2008) $ $Author: mlampard $
|
||||
|
||||
This daemon listens on localhost port 15550 for client connections,
|
||||
and arbitrates LCD display. Allows for multiple simultaneous clients.
|
||||
@@ -44,10 +44,14 @@
|
||||
#include "g15daemon.h"
|
||||
#include <libg15.h>
|
||||
#include <stdarg.h>
|
||||
#include <libg15render.h>
|
||||
|
||||
extern unsigned int g15daemon_debug;
|
||||
extern volatile int leaving;
|
||||
#define G15DAEMON_PIDFILE "/var/run/g15daemon.pid"
|
||||
|
||||
pthread_cond_t lcd_refresh = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
|
||||
/* if no exitfunc or eventhandler, member should be NULL */
|
||||
const plugin_info_t generic_info[] = {
|
||||
@@ -71,6 +75,45 @@ void *g15daemon_xmalloc(size_t size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static int refresh_pending=0;
|
||||
void g15daemon_init_refresh() {
|
||||
pthread_condattr_t attr;
|
||||
pthread_cond_init(&lcd_refresh, &attr);
|
||||
}
|
||||
|
||||
void g15daemon_send_refresh(lcd_t *lcd) {
|
||||
if(lcd==lcd->masterlist->current->lcd||lcd->state_changed) {
|
||||
pthread_cond_broadcast(&lcd_refresh);
|
||||
refresh_pending++;
|
||||
}
|
||||
}
|
||||
|
||||
void g15daemon_wait_refresh() {
|
||||
pthread_mutex_t dummy_mutex;
|
||||
struct timespec timeout;
|
||||
int retval;
|
||||
if(refresh_pending<1) {
|
||||
/* Create a dummy mutex which doesn't unlock for sure while waiting. */
|
||||
pthread_mutex_init(&dummy_mutex, NULL);
|
||||
pthread_mutex_lock(&dummy_mutex);
|
||||
start:
|
||||
time(&timeout.tv_sec);
|
||||
timeout.tv_sec += 1;
|
||||
timeout.tv_nsec = 0L;
|
||||
|
||||
retval=pthread_cond_timedwait(&lcd_refresh, &dummy_mutex, &timeout);
|
||||
if(!leaving && retval == ETIMEDOUT)
|
||||
goto start;
|
||||
pthread_mutex_unlock(&dummy_mutex);
|
||||
pthread_mutex_destroy(&dummy_mutex);
|
||||
}
|
||||
refresh_pending--;
|
||||
}
|
||||
|
||||
void g15daemon_quit_refresh() {
|
||||
pthread_cond_destroy(&lcd_refresh);
|
||||
}
|
||||
|
||||
int uf_return_running(){
|
||||
int fd;
|
||||
char pidtxt[128];
|
||||
@@ -133,20 +176,36 @@ int uf_create_pidfile() {
|
||||
|
||||
/* syslog wrapper */
|
||||
int g15daemon_log (int priority, const char *fmt, ...) {
|
||||
|
||||
va_list argp;
|
||||
va_start (argp, fmt);
|
||||
if(g15daemon_debug == 0)
|
||||
int real_prio=0;
|
||||
|
||||
switch(g15daemon_debug) {
|
||||
case 0:
|
||||
case 1:
|
||||
real_prio = LOG_WARNING;
|
||||
break;
|
||||
case 2:
|
||||
real_prio = LOG_INFO;
|
||||
break;
|
||||
default:
|
||||
real_prio = LOG_DEBUG;
|
||||
}
|
||||
|
||||
if(real_prio>=priority) {
|
||||
if(g15daemon_debug == 0) {
|
||||
vsyslog(priority, fmt, argp);
|
||||
else {
|
||||
} else {
|
||||
vfprintf(stderr,fmt,argp);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
}
|
||||
va_end (argp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* takes a 6880 byte (1byte==1pixel) buffer and packs it into libg15 format. */
|
||||
void g15daemon_convert_buf(lcd_t *lcd, unsigned char * orig_buf)
|
||||
{
|
||||
unsigned int x,y,val;
|
||||
@@ -166,13 +225,31 @@ void g15daemon_convert_buf(lcd_t *lcd, unsigned char * orig_buf)
|
||||
}
|
||||
}
|
||||
|
||||
/* wrap the libg15 function */
|
||||
void uf_write_buf_to_g15(lcd_t *lcd)
|
||||
/* wrap the libg15 functions */
|
||||
int uf_write_buf_to_g15(lcd_t *lcd)
|
||||
{
|
||||
int retval = 0;
|
||||
#ifdef LIBUSB_BLOCKS
|
||||
retval = writePixmapToLCD(lcd->buf);
|
||||
#else
|
||||
pthread_mutex_lock(&g15lib_mutex);
|
||||
writePixmapToLCD(lcd->buf);
|
||||
retval = writePixmapToLCD(lcd->buf);
|
||||
pthread_mutex_unlock(&g15lib_mutex);
|
||||
return;
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
int uf_read_keypresses(unsigned int *keypresses, unsigned int timeout)
|
||||
{
|
||||
int retval=0;
|
||||
#ifdef LIBUSB_BLOCKS
|
||||
retval = getPressedKeys(keypresses, timeout);
|
||||
#else
|
||||
pthread_mutex_lock(&g15lib_mutex);
|
||||
retval = getPressedKeys(keypresses, timeout);
|
||||
pthread_mutex_unlock(&g15lib_mutex);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Sleep routine (hackish). */
|
||||
@@ -588,3 +665,24 @@ int uf_conf_open(g15daemon_t *list, char *filename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uf_screendump_pbm(unsigned char *buffer,char *filename) {
|
||||
FILE *f;
|
||||
int x,y;
|
||||
#define WIDTH 40
|
||||
g15canvas *canvas=g15daemon_xmalloc(sizeof(g15canvas));
|
||||
memcpy(canvas->buffer,buffer,LCD_BUFSIZE);
|
||||
f = fopen(filename,"w+");
|
||||
fprintf(f,"P1\n160 43\n");
|
||||
fprintf(f,"# G15 screendump - %s\n\n",filename);
|
||||
for(y=0;y<43;y++)
|
||||
for(x=0;x<160;x++) {
|
||||
fprintf(f,"%i",g15r_getPixel(canvas,x,y));
|
||||
if(x%WIDTH==WIDTH-1)
|
||||
fprintf(f,"\n");
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
free(canvas);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user