link with
-lg15daemon_client
int new_g15_screen(int screentype);
int g15_close_screen(int sock);
int g15_send(int sock, char *buf, unsigned int len);
int g15_recv(int sock, char *buf, unsigned int len);
int g15_send_cmd (int sock, unsigned char command, unsigned char value);
Clients wishing to display on the LCD must send entire screens in the format of their choice. Currently partial screen updates (icons etc) are not supported.
G15Daemon commands are sent to the daemon via the OOB (out-of-band) messagetype, replies are sent inband back to the client.
G15_PIXELBUF: this buffer must be exactly 6880 bytes, and uses 1 byte per pixel.
G15_TEXTBUF: currently ignored by the daemon.
G15_WBMPBUF: this is a packed pixel buffer in WBMP format with 8 pixels per byte. Useful for perl programmers using the GD:: and G15Daemon.pm (see lang_bindings directory) perl modules.
G15_G15RBUF: another packed pixel buffer type, also with 8 pixels/byte, and is the native libg15render format.
Example of use:
int screen_fd = new_g15_screen( G15_WBMPBUF );
Returns 0 if successful, or errno if there was an error.
Example:
int retval = 0; int screen_fd = new_g15_screen( G15_WBMPBUF );
... do processing and display here ...
retval = g15_close_screen( screen_fd );
Returns 0 on success, -1 if the send failed due to timeout or socket error.
Returns 0 on success, -1 if the recv failed due to timeout or socket error.
See examples for usage.
Commands and requests to the daemon are sent via OOB data packets. Changes to the backlight and mkey state will only affect the calling client. The following commands are supported as defined in g15daemon_client.h:
--- Cut here ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <poll.h>
#include <g15daemon_client.h>
#include <libg15.h>
/* #define TEST_KEYHANDLER */
int main(int argc, char *argv[])
{
int g15screen_fd, retval;
char lcdbuffer[6880];
unsigned int keystate;
char msgbuf[256];
int foo = 0;
if((g15screen_fd = new_g15_screen(G15_PIXELBUF))<0){
printf("Sorry, cant connect to the G15daemon);
return 5;
}else
printf("Connected to g15daemon. sending image);
if(argc<2)
retval = g15_send(g15screen_fd,(char*)logo_data,6880);
else {
memset(lcdbuffer,0,6880);
memset(lcdbuffer,1,6880/2);
retval = g15_send(g15screen_fd,(char*)lcdbuffer,6880);
}
printf("checking key status - press G1 to exit,retval);
while(1){
keystate = 0;
int foo;
keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
if(keystate)
printf("keystate = %i,keystate);
if(keystate & G15_KEY_G1) //G1 key. See libg15.h for details on key values.
break;
/* G2,G3 & G4 change LCD backlight */
if(keystate & G15_KEY_G2){
retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_DARK);
}
if(keystate & G15_KEY_G3){
retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_MEDIUM);
}
if(keystate & G15_KEY_G4){
retval = g15_send_cmd (g15screen_fd, G15DAEMON_BACKLIGHT, G15_BRIGHTNESS_BRIGHT);
}
/* is this client in the foreground?? */
retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
if(retval)
printf("Hey, we are in the foreground, Doc);
else
printf("What dastardly wabbit put me in the background?);
retval = g15_send_cmd (g15screen_fd, G15DAEMON_IS_USER_SELECTED, foo);
if(retval)
printf("You wanted me in the foreground, right Doc?);
else
printf("You dastardly wabbit !);
if(retval){ /* we've been backgrounded! */
sleep(2); /* remain in the background for a bit */
retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
sleep(2); /* switch to foreground */
retval = g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
}
usleep(500);
#ifdef TEST_KEYHANDLER
/* ok.. request that all G&M keys are passed to us.. */
retval = g15_send_cmd (g15screen_fd, G15DAEMON_KEY_HANDLER, foo);
while(1){
printf("waiting on keystate);
keystate=0;
retval = recv(g15screen_fd, &keystate , sizeof(keystate),0);
if(keystate)
printf("Recieved %i as keystate",keystate);
}
#endif
}
g15_close_screen(g15screen_fd);
return 0;
}
-- end cutting --