Commit 96023974 authored by Giacomo Catenazzi's avatar Giacomo Catenazzi

Import Upstream version 1.9.1.0.svn346

parent 9404a616
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
(c) 2006 Mike Lampard, Philip Lawatsch, and others (c) 2006 Mike Lampard, Philip Lawatsch, and others
$Revision: 295 $ - $Date: 2007-09-09 06:37:50 +0200 (Sun, 09 Sep 2007) $ $Author: mlampard $ $Revision: 343 $ - $Date: 2007-12-18 06:26:28 +0100 (Tue, 18 Dec 2007) $ $Author: mlampard $
This daemon listens on localhost port 15550 for client connections, This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients. and arbitrates LCD display. Allows for multiple simultaneous clients.
...@@ -84,7 +84,7 @@ allow clients use of all 'L' keys. ...@@ -84,7 +84,7 @@ allow clients use of all 'L' keys.
1.2.5svn -> current 1.2.5svn -> current
- Add compiletime check for uinput version, should resolve compilation problems on some distro's - Add compiletime check for uinput version, should resolve compilation problems on some distro's
- Security improved - the daemon now sets its effective uid to nobody as soon as possible. - Security improved - the daemon now sets its effective uid to nobody as soon as possible.
1.9.0SVN 1.9.0
- Add plugin API - Add plugin API
- partially rewritten event core - partially rewritten event core
- updated g15daemon_xmms_spectrum plugin with new features, available in trunk/g15daemon_audio_plugins (SVN) - updated g15daemon_xmms_spectrum plugin with new features, available in trunk/g15daemon_audio_plugins (SVN)
...@@ -93,5 +93,26 @@ allow clients use of all 'L' keys. ...@@ -93,5 +93,26 @@ allow clients use of all 'L' keys.
- g15daemon is now dependant on libg15render. - g15daemon is now dependant on libg15render.
- Clock now includes analog clock thanks to Rasta Freak <igor.jusic@zg.t-com.hr> - Clock now includes analog clock thanks to Rasta Freak <igor.jusic@zg.t-com.hr>
- Moved g15daemon_xmms_spectrum plugin to separate package - Moved g15daemon_xmms_spectrum plugin to separate package
- Plugins are now installed in ${PREFIX}/lib/g15daemon/${VERSION}/plugins 1.9.1
- Plugins are now installed in ${PREFIX}/{${LIBDIR}/g15daemon/${VERSION}/plugins
- OS-X support thanks to Fabrizio Sestito. - OS-X support thanks to Fabrizio Sestito.
- Bugfix: libg15daemon_client: keypresses were being corrupted.
- Bugfix: libg15daemon_client: use g15_recv rather than recv.
- Bugfix: use default scheduling for all threads.
- Optimisation: minor optimisation of lcd_cycle() code.
- Security: repair some potential security holes.
- Bugfix: Backlight status was being mis-applied when cycling screens.
- Bugfix: Language bindings were not being distributed.
1.9.1->SVN
- Add exitfunc to net plugin for exit notification.
- Use pause() instead of sleeping
- create leaving var as volatile.
- Add NAME section to g15daemon_client manpages
- Tweak delay between successive keyboard reads. This reduces cpu load by
50% on my system.
- Bugfix: Ensure that all plugin exit functions are called on leaving.
- Bugfix: if keypress event is received (very early in the startup process,
the daemon would crash. Check that expected pointers are valid.
- Bugfix: Dont attempt compilation of uinput plugin if headers are
unavailable.
- Bugfix: Write a blank buffer to the LCD before exiting.
.TH "G15daemon Client Development" "" "1.0" "G15Daemon" "" .TH "G15daemon Client Development" "" "1.0" "G15Daemon" ""
.SH "NAME" g15daemon_client \- G15Daemon Server / Client communication for g15daemon.
.SH "SYNOPSIS" .SH "SYNOPSIS"
#include <libg15.h> #include <libg15.h>
.br .br
......
...@@ -23,7 +23,7 @@ dist-hook: ...@@ -23,7 +23,7 @@ dist-hook:
rm -rf `find $(distdir)/debian -name .svn` rm -rf `find $(distdir)/debian -name .svn`
rm -rf `find $(distdir)/contrib -name .svn` rm -rf `find $(distdir)/contrib -name .svn`
rm -rf `find $(distdir)/Documentation -name .svn` rm -rf `find $(distdir)/Documentation -name .svn`
rm -rf `find $(distdir)/lang_bindings -name .svn` rm -rf `find $(distdir)/lang-bindings -name .svn`
rm -rf `find $(distdir)/patches -name .svn` rm -rf `find $(distdir)/patches -name .svn`
rm -rf `find $(distdir)/rpm -name .svn` rm -rf `find $(distdir)/rpm -name .svn`
rm -rf `find $(distdir)/plugins -name .svn` rm -rf `find $(distdir)/plugins -name .svn`
......
# -*- Autoconf -*- # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
# $Revision: 295 $ - $Date: 2007-09-09 06:37:50 +0200 (Sun, 09 Sep 2007) $ $Author: mlampard $ # $Revision: 334 $ - $Date: 2007-12-07 15:08:03 +0100 (Fri, 07 Dec 2007) $ $Author: mlampard $
AC_PREREQ(2.59) AC_PREREQ(2.59)
AC_INIT(g15daemon, [1.9pre], [mlampard@users.sf.net]) AC_INIT(g15daemon, [1.9.1], [mlampard@users.sf.net])
AC_PREFIX_DEFAULT(/usr) AC_PREFIX_DEFAULT(/usr)
AC_CONFIG_AUX_DIR(config) AC_CONFIG_AUX_DIR(config)
AC_CANONICAL_TARGET() AC_CANONICAL_TARGET()
...@@ -32,6 +32,7 @@ AC_CHECK_HEADERS([ linux/uinput.h arpa/inet.h fcntl.h stdlib.h string.h sys/sock ...@@ -32,6 +32,7 @@ AC_CHECK_HEADERS([ linux/uinput.h arpa/inet.h fcntl.h stdlib.h string.h sys/sock
#include <linux/input.h> #include <linux/input.h>
#endif #endif
]) ])
#if HAVE_LINUX_UINPUT_H #if HAVE_LINUX_UINPUT_H
dnl check for uinput.h version 2.4 or 2.6 ? dnl check for uinput.h version 2.4 or 2.6 ?
AC_CHECK_MEMBER([struct uinput_user_dev.id], AC_CHECK_MEMBER([struct uinput_user_dev.id],
...@@ -42,9 +43,12 @@ AC_CHECK_HEADERS([ linux/uinput.h arpa/inet.h fcntl.h stdlib.h string.h sys/sock ...@@ -42,9 +43,12 @@ AC_CHECK_HEADERS([ linux/uinput.h arpa/inet.h fcntl.h stdlib.h string.h sys/sock
#include <linux/uinput.h> #include <linux/uinput.h>
] ]
) )
uinput=true
dnl end of uinput version checks dnl end of uinput version checks
#endif #endif
AM_CONDITIONAL(UINPUT_INTERFACE_PLUGIN, [test x$uinput = xtrue])
case $host_os in case $host_os in
*linux*) *linux*)
AC_DEFINE([OSTYPE_LINUX], [1],[Target OS is Linux]) AC_DEFINE([OSTYPE_LINUX], [1],[Target OS is Linux])
......
g15daemon for Debian
--------------------
<possible notes regarding this package - if none, delete this file>
-- Anthony J. Mirabella <mirabeaj@gmail.com>, Thu, 28 Sep 2006 04:46:06 -0400
g15daemon (1.2.1-1) breezy; urgency=low
* Initial release
-- Anthony J. Mirabella <mirabeaj@gmail.com> Thu, 28 Sep 2006 04:46:06 -0400
Source: g15daemon
Section: utils
Priority: optional
Maintainer: Anthony J. Mirabella <mirabeaj@gmail.com>
Build-Depends: debhelper (>= 4.0.0), autotools-dev, libg15-dev, libg15render-dev
Standards-Version: 3.6.2
Package: g15daemon
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libg15daemon-client (= ${Source-Version})
Description: Screen multiplexer for Logitech G15 Keyboard
G15daemon provides multiple virtual screens for the LCD on the Logitech
G15 Keyboard
Package: libg15daemon-client
Section: libs
Architecture: any
Depends: ${shlibs:Depends}
Description: Client library for communicating with g15daemon
Provides interface functions for clients that wish to communicate with
a running instance of g15daemon
Package: libg15daemon-client-dev
Section: libdevel
Architecture: any
Depends: libg15daemon-client (= ${Source-Version})
Description: Development packages for libg15daemon-client
Includes the files needed for developing g15daemon clients
This package was debianized by Anthony J. Mirabella <mirabeaj@gmail.com> on
Thu, 28 Sep 2006 04:46:06 -0400.
It was downloaded from <fill in ftp site>
Copyright Holder: <put author(s) name and email here>
License:
<Put the license of the package here>
NEWS
README
TODO
usr/include/*
usr/lib/lib*.a
usr/lib/lib*.so
usr/lib/pkgconfig/*
usr/lib/*.la
usr/share/pkgconfig/*
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif
config.status: configure
dh_testdir
# Add here commands to configure the package.
CFLAGS="$(CFLAGS) -Wl,-z,defs" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
build: build-stamp
build-stamp: config.status
dh_testdir
# Add here commands to compile the package.
$(MAKE)
#docbook-to-man debian/g15daemon.sgml > g15daemon.1
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp
# Add here commands to clean up after the build process.
-$(MAKE) distclean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
cp -f /usr/share/misc/config.guess config.guess
endif
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/g15daemon.
$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs ChangeLog
dh_installdocs
dh_installexamples
dh_install -a --sourcedir=debian/tmp
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman Documentation/g15daemon.1 Documentation/g15daemon_client_devel.3
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
(c) 2006 Mike Lampard, Philip Lawatsch, and others (c) 2006 Mike Lampard, Philip Lawatsch, and others
$Revision: 179 $ - $Date: 2006-11-19 09:33:12 +0100 (Sun, 19 Nov 2006) $ $Author: mlampard $ $Revision: 333 $ - $Date: 2007-12-02 04:50:57 +0100 (Sun, 02 Dec 2007) $ $Author: mlampard $
This daemon listens on localhost port 15550 for client connections, This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients. and arbitrates LCD display. Allows for multiple simultaneous clients.
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <libg15render.h> #include <libg15render.h>
extern int leaving; extern volatile int leaving;
void * g15daemon_dlopen_plugin(char *name,unsigned int library) { void * g15daemon_dlopen_plugin(char *name,unsigned int library) {
...@@ -129,7 +129,7 @@ void run_advanced_client(plugin_t *plugin_args) ...@@ -129,7 +129,7 @@ void run_advanced_client(plugin_t *plugin_args)
g15daemon_msleep(info->update_msecs); g15daemon_msleep(info->update_msecs);
} }
}else{ }else{
while(1){ while(!leaving){
g15daemon_msleep(500); g15daemon_msleep(500);
} }
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
(c) 2006 Mike Lampard, Philip Lawatsch, and others (c) 2006 Mike Lampard, Philip Lawatsch, and others
$Revision: 300 $ - $Date: 2007-09-10 09:52:01 +0200 (Mon, 10 Sep 2007) $ $Author: mlampard $ $Revision: 324 $ - $Date: 2007-11-29 02:45:27 +0100 (Thu, 29 Nov 2007) $ $Author: mlampard $
This daemon listens on localhost port 15550 for client connections, This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients. and arbitrates LCD display. Allows for multiple simultaneous clients.
...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) ...@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
// keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo); // keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
//while(1){ //while(1){
//recv(g15screen_fd, &keystate, 4, 0); recv(g15screen_fd, &keystate, 4, 0);
if(keystate) if(keystate)
printf("keystate = %i\n",keystate); printf("keystate = %i\n",keystate);
//} //}
...@@ -79,19 +79,19 @@ int main(int argc, char *argv[]) ...@@ -79,19 +79,19 @@ int main(int argc, char *argv[])
// break; // break;
/* G2,G3 & G4 change LCD backlight */ /* G2,G3 & G4 change LCD backlight */
// if(keystate & G15_KEY_G2){ if(keystate & G15_KEY_G2){
// retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK); retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK);
// } }
// if(keystate & G15_KEY_G3){ if(keystate & G15_KEY_G3){
// retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM); retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM);
unsigned char packet[2]; unsigned char packet[2];
packet[0] = G15DAEMON_BACKLIGHT|G15_BRIGHTNESS_MEDIUM; packet[0] = G15DAEMON_BACKLIGHT|G15_BRIGHTNESS_MEDIUM;
printf("sent %i bytes\n",send(g15screen_fd, packet, 1, MSG_OOB )); printf("sent %i bytes\n",send(g15screen_fd, packet, 1, MSG_OOB ));
// } }
// if(keystate & G15_KEY_G4){ if(keystate & G15_KEY_G4){
// retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT); retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT);
// } }
/* /*
retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo); retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
...@@ -115,7 +115,7 @@ int main(int argc, char *argv[]) ...@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
// } // }
*/ */
sleep(2); // sleep(2);
#ifdef TEST_KEYHANDLER #ifdef TEST_KEYHANDLER
/* ok.. request that all G&M keys are passed to us.. */ /* ok.. request that all G&M keys are passed to us.. */
retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo); retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
(c) 2006 Mike Lampard, Philip Lawatsch, and others (c) 2006 Mike Lampard, Philip Lawatsch, and others
$Revision: 177 $ - $Date: 2006-11-18 14:46:03 +0100 (Sat, 18 Nov 2006) $ $Author: mlampard $ $Revision: 321 $ - $Date: 2007-11-29 01:00:29 +0100 (Thu, 29 Nov 2007) $ $Author: mlampard $
This daemon listens on localhost port 15550 for client connections, This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients. and arbitrates LCD display. Allows for multiple simultaneous clients.
...@@ -119,6 +119,7 @@ void g15daemon_lcdnode_cycle(g15daemon_t *masterlist) ...@@ -119,6 +119,7 @@ void g15daemon_lcdnode_cycle(g15daemon_t *masterlist)
lcdnode_t *current_screen = masterlist->current; lcdnode_t *current_screen = masterlist->current;
g15daemon_send_event(current_screen->lcd, G15_EVENT_VISIBILITY_CHANGED, SCR_HIDDEN); g15daemon_send_event(current_screen->lcd, G15_EVENT_VISIBILITY_CHANGED, SCR_HIDDEN);
do do
{ {
pthread_mutex_lock(&lcdlist_mutex); pthread_mutex_lock(&lcdlist_mutex);
...@@ -132,19 +133,18 @@ void g15daemon_lcdnode_cycle(g15daemon_t *masterlist) ...@@ -132,19 +133,18 @@ void g15daemon_lcdnode_cycle(g15daemon_t *masterlist)
pthread_mutex_unlock(&lcdlist_mutex); pthread_mutex_unlock(&lcdlist_mutex);
} }
while (current_screen != masterlist->current); while (current_screen != masterlist->current);
pthread_mutex_lock(&lcdlist_mutex); pthread_mutex_lock(&lcdlist_mutex);
if(masterlist->tail == masterlist->current) { if(masterlist->tail == masterlist->current) {
masterlist->current = masterlist->head; masterlist->current = masterlist->head;
} else { } else {
masterlist->current = masterlist->current->prev; masterlist->current = masterlist->current->prev;
} }
pthread_mutex_unlock(&lcdlist_mutex);
g15daemon_send_event(masterlist->current->lcd, G15_EVENT_VISIBILITY_CHANGED, SCR_VISIBLE);
g15daemon_send_event(current_screen->lcd, G15_EVENT_USER_FOREGROUND, 1);
pthread_mutex_lock(&lcdlist_mutex);
masterlist->current->lcd->state_changed = 1;
masterlist->current->last_priority = masterlist->current; masterlist->current->last_priority = masterlist->current;
pthread_mutex_unlock(&lcdlist_mutex); pthread_mutex_unlock(&lcdlist_mutex);
g15daemon_send_event(current_screen->lcd, G15_EVENT_USER_FOREGROUND, 1);
g15daemon_send_event(masterlist->current->lcd, G15_EVENT_VISIBILITY_CHANGED, SCR_VISIBLE);
} }
void g15daemon_lcdnode_remove (lcdnode_t *oldnode) { void g15daemon_lcdnode_remove (lcdnode_t *oldnode) {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
(c) 2006 Mike Lampard, Philip Lawatsch, and others (c) 2006 Mike Lampard, Philip Lawatsch, and others
$Revision: 302 $ - $Date: 2007-09-10 09:57:53 +0200 (Mon, 10 Sep 2007) $ $Author: mlampard $ $Revision: 346 $ - $Date: 2007-12-18 06:44:36 +0100 (Tue, 18 Dec 2007) $ $Author: mlampard $
This daemon listens on localhost port 15550 for client connections, This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients. and arbitrates LCD display. Allows for multiple simultaneous clients.
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#endif #endif
/* all threads will exit if leaving >0 */ /* all threads will exit if leaving >0 */
int leaving = 0; volatile int leaving = 0;
int keyboard_backlight_off_onexit = 0; int keyboard_backlight_off_onexit = 0;
unsigned int g15daemon_debug = 0; unsigned int g15daemon_debug = 0;
unsigned int cycle_key; unsigned int cycle_key;
...@@ -64,6 +64,10 @@ int g15daemon_send_event(void *caller, unsigned int event, unsigned long value) ...@@ -64,6 +64,10 @@ int g15daemon_send_event(void *caller, unsigned int event, unsigned long value)
static unsigned long lastkeys; static unsigned long lastkeys;
if(!(value & cycle_key) && !(lastkeys & cycle_key)){ if(!(value & cycle_key) && !(lastkeys & cycle_key)){
lcd_t *lcd = (lcd_t*)caller; lcd_t *lcd = (lcd_t*)caller;
if(!lcd->g15plugin->info)
break;
int *(*plugin_listener)(plugin_event_t *newevent) = (void*)lcd->g15plugin->info->event_handler; int *(*plugin_listener)(plugin_event_t *newevent) = (void*)lcd->g15plugin->info->event_handler;
plugin_event_t *newevent=g15daemon_xmalloc(sizeof(plugin_event_t)); plugin_event_t *newevent=g15daemon_xmalloc(sizeof(plugin_event_t));
newevent->event = event; newevent->event = event;
...@@ -82,9 +86,12 @@ int g15daemon_send_event(void *caller, unsigned int event, unsigned long value) ...@@ -82,9 +86,12 @@ int g15daemon_send_event(void *caller, unsigned int event, unsigned long value)
g15daemon_log(LOG_WARNING,"Error in send: %s\n",strerror(errno)); g15daemon_log(LOG_WARNING,"Error in send: %s\n",strerror(errno));
} }
if(value & G15_KEY_LIGHT){ // the backlight key was pressed - maintain user-selected state if(value & G15_KEY_LIGHT){ // the backlight key was pressed - maintain user-selected state
lcd_t *displaying = lcd->masterlist->tail->lcd;
lcd->masterlist->kb_backlight_state++; lcd->masterlist->kb_backlight_state++;
if(lcd->masterlist->kb_backlight_state>2) if(lcd->masterlist->kb_backlight_state>2)
lcd->masterlist->kb_backlight_state=0; lcd->masterlist->kb_backlight_state=0;
displaying->backlight_state++;
displaying->backlight_state %= 3; // limit to 0-2 inclusive
} }
free(newevent); free(newevent);
}else{ }else{
...@@ -168,33 +175,38 @@ static void *keyboard_watch_thread(void *lcdlist){ ...@@ -168,33 +175,38 @@ static void *keyboard_watch_thread(void *lcdlist){
unsigned int keypresses = 0; unsigned int keypresses = 0;
int retval = 0; int retval = 0;
static int lastkeys = 0;
while (!leaving) { while (!leaving) {
pthread_mutex_lock(&g15lib_mutex); pthread_mutex_lock(&g15lib_mutex);
retval = getPressedKeys(&keypresses, 40); retval = getPressedKeys(&keypresses, 2);
pthread_mutex_unlock(&g15lib_mutex); pthread_mutex_unlock(&g15lib_mutex);
/* every 2nd packet contains the codes we want.. immediately try again */ /* every 2nd packet contains the codes we want.. immediately try again */
while (retval == G15_ERROR_TRY_AGAIN){ while (retval == G15_ERROR_TRY_AGAIN){
pthread_mutex_lock(&g15lib_mutex); pthread_mutex_lock(&g15lib_mutex);
retval = getPressedKeys(&keypresses, 40); retval = getPressedKeys(&keypresses, 2);
pthread_mutex_unlock(&g15lib_mutex); pthread_mutex_unlock(&g15lib_mutex);
} }
if(retval == G15_NO_ERROR){ if(retval == G15_NO_ERROR && lastkeys != keypresses) {
g15daemon_send_event(masterlist->current->lcd, g15daemon_send_event(masterlist->current->lcd,
G15_EVENT_KEYPRESS, keypresses); G15_EVENT_KEYPRESS, keypresses);
} lastkeys = keypresses;
if(retval == -ENODEV && LIBG15_VERSION>=1200) {
}else if(retval == -ENODEV && LIBG15_VERSION>=1200) {
pthread_mutex_lock(&g15lib_mutex); pthread_mutex_lock(&g15lib_mutex);
while((retval=re_initLibG15() != G15_NO_ERROR) && !leaving){ while((retval=re_initLibG15() != G15_NO_ERROR) && !leaving){
sleep(1); sleep(1);
} }
if(!leaving) { masterlist->current->lcd->state_changed=1; masterlist->current->lcd->ident=random();} if(!leaving) {
masterlist->current->lcd->state_changed=1;
masterlist->current->lcd->ident=random();
}
pthread_mutex_unlock(&g15lib_mutex); pthread_mutex_unlock(&g15lib_mutex);
} }
g15daemon_msleep(10); g15daemon_msleep(40);
} }
return NULL; return NULL;
...@@ -257,6 +269,7 @@ void g15daemon_sighandler(int sig) { ...@@ -257,6 +269,7 @@ void g15daemon_sighandler(int sig) {
case SIGUSR1: case SIGUSR1:
keyboard_backlight_off_onexit = 1; keyboard_backlight_off_onexit = 1;
case SIGINT: case SIGINT:
case SIGTERM:
case SIGQUIT: case SIGQUIT:
leaving = 1; leaving = 1;
break; break;
...@@ -275,7 +288,8 @@ int main (int argc, char *argv[]) ...@@ -275,7 +288,8 @@ int main (int argc, char *argv[])
struct sigaction new_action; struct sigaction new_action;
cycle_key = G15_KEY_L1; cycle_key = G15_KEY_L1;
unsigned char user[256]; unsigned char user[256];
unsigned int lcdlevel = 1;
pthread_t keyboard_thread; pthread_t keyboard_thread;
pthread_t lcd_thread; pthread_t lcd_thread;
memset(user,0,256); memset(user,0,256);
...@@ -309,13 +323,13 @@ int main (int argc, char *argv[]) ...@@ -309,13 +323,13 @@ int main (int argc, char *argv[])
if (!strncmp(daemonargs, "-h",2) || !strncmp(daemonargs, "--help",6)) { if (!strncmp(daemonargs, "-h",2) || !strncmp(daemonargs, "--help",6)) {
printf("G15Daemon version %s - %s\n",VERSION,uf_return_running() >= 0 ?"Loaded & Running":"Not Running"); printf("G15Daemon version %s - %s\n",VERSION,uf_return_running() >= 0 ?"Loaded & Running":"Not Running");
printf("%s -h (--help) or -k (--kill) or -s (--switch) or -d (--debug) or -v (--version)\n\n -k will kill a previous incarnation",argv[0]); printf("%s -h (--help) or -k (--kill) or -s (--switch) or -d (--debug) [level] or -v (--version) or -l (--lcdlevel) [0-2] \n\n -k will kill a previous incarnation",argv[0]);
#ifdef LIBG15_VERSION #ifdef LIBG15_VERSION
#if LIBG15_VERSION >= 1200 #if LIBG15_VERSION >= 1200
printf(", if uppercase -K or -KILL turn off the keyboard backlight on the way out."); printf(", if uppercase -K or -KILL turn off the keyboard backlight on the way out.");
#endif #endif
#endif #endif
printf("\n -h shows this help\n -s changes the screen-switch key from MR to L1\n -d debug mode - stay in foreground and output all debug messages to STDERR\n -v show version\n"); printf("\n -h shows this help\n -s changes the screen-switch key from MR to L1\n -d debug mode - stay in foreground and output all debug messages to STDERR\n -v show version\n -l set default LCD backlight level\n");
exit(0); exit(0);
} }
...@@ -340,6 +354,13 @@ int main (int argc, char *argv[]) ...@@ -340,6 +354,13 @@ int main (int argc, char *argv[])
} }
} }
if (!strncmp(daemonargs, "-l",2) || !strncmp(daemonargs, "--lcdlevel",7)) {
if((argv[i+1])!=NULL)
if(isdigit(argv[i+1][0])){
lcdlevel = atoi(argv[i+1]);
}
}
} }
if(uf_return_running()>=0) { if(uf_return_running()>=0) {
g15daemon_log(LOG_ERR,"G15Daemon already running.. Exiting"); g15daemon_log(LOG_ERR,"G15Daemon already running.. Exiting");
...@@ -401,7 +422,8 @@ int main (int argc, char *argv[]) ...@@ -401,7 +422,8 @@ int main (int argc, char *argv[])
setLCDContrast(1); setLCDContrast(1);
setLEDs(0); setLEDs(0);
lcdlist->kb_backlight_state=1; lcdlist->kb_backlight_state=1;
setLCDBrightness(lcdlist->kb_backlight_state); lcdlist->current->lcd->backlight_state=lcdlevel;
setLCDBrightness(lcdlevel);
#ifdef LIBG15_VERSION #ifdef LIBG15_VERSION
#if LIBG15_VERSION >= 1200 #if LIBG15_VERSION >= 1200
...@@ -422,19 +444,12 @@ int main (int argc, char *argv[]) ...@@ -422,19 +444,12 @@ int main (int argc, char *argv[])
pthread_mutex_init(&g15lib_mutex, NULL); pthread_mutex_init(&g15lib_mutex, NULL);
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr,512*1024); /* set stack to 512k - dont need 8Mb !! */ pthread_attr_setstacksize(&attr,512*1024); /* set stack to 512k - dont need 8Mb !! */
pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM);
int thread_policy=SCHED_RR;
pthread_attr_setschedpolicy(&attr,thread_policy);
if (pthread_create(&keyboard_thread, &attr, keyboard_watch_thread, lcdlist) != 0) { if (pthread_create(&keyboard_thread, &attr, keyboard_watch_thread, lcdlist) != 0) {
g15daemon_log(LOG_ERR,"Unable to create keyboard listener thread. Exiting"); g15daemon_log(LOG_ERR,"Unable to create keyboard listener thread. Exiting");
goto exitnow; goto exitnow;
} }
pthread_attr_setstacksize(&attr,128*1024); pthread_attr_setstacksize(&attr,128*1024);
/* all other threads have a lower priority... maybe */
pthread_attr_setscope(&attr,PTHREAD_SCOPE_PROCESS);
thread_policy=SCHED_OTHER;
pthread_attr_setschedpolicy(&attr,thread_policy);
if (pthread_create(&lcd_thread, &attr, lcd_draw_thread, lcdlist) != 0) { if (pthread_create(&lcd_thread, &attr, lcd_draw_thread, lcdlist) != 0) {
g15daemon_log(LOG_ERR,"Unable to create display thread. Exiting"); g15daemon_log(LOG_ERR,"Unable to create display thread. Exiting");
...@@ -461,11 +476,11 @@ int main (int argc, char *argv[]) ...@@ -461,11 +476,11 @@ int main (int argc, char *argv[])
new_action.sa_flags = 0; new_action.sa_flags = 0;
sigaction(SIGINT, &new_action, NULL); sigaction(SIGINT, &new_action, NULL);
sigaction(SIGQUIT, &new_action, NULL); sigaction(SIGQUIT, &new_action, NULL);
sigaction(SIGTERM, &new_action, NULL);
sigaction(SIGUSR1, &new_action, NULL); sigaction(SIGUSR1, &new_action, NULL);
do { do {
sleep(1); pause();
} while( leaving == 0); } while( leaving == 0);
g15daemon_log(LOG_INFO,"Leaving by request"); g15daemon_log(LOG_INFO,"Leaving by request");
...@@ -473,6 +488,10 @@ int main (int argc, char *argv[]) ...@@ -473,6 +488,10 @@ int main (int argc, char *argv[])
pthread_join(lcd_thread,NULL); pthread_join(lcd_thread,NULL);
pthread_join(keyboard_thread,NULL); pthread_join(keyboard_thread,NULL);
/* switch off the lcd backlight */ /* switch off the lcd backlight */
char *blank=malloc(G15_BUFFER_LEN);
memset(blank,0,G15_BUFFER_LEN);