~ubuntu-branches/ubuntu/karmic/g15daemon/karmic

« back to all changes in this revision

Viewing changes to plugins/g15_plugin_template.c

  • Committer: Bazaar Package Importer
  • Author(s): Giacomo Catenazzi
  • Date: 2008-04-28 08:47:07 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080428084707-vy58xr1xrb4ix3uf
Tags: 1.9.5.3-3
* Changing default in /etc/default/g15daemon: Use L1 key instead of MR
  as actual upstream default and allowing to use g15macro
  (Closes: #478069)
* Removed the X11 setup on man page, because it is not relevant
  to recent distributions and could confuse our users (Closes: #463078)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 /*
2
 
    This file is part of g15daemon.
3
 
 
4
 
    g15daemon is free software; you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    g15daemon is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with g15daemon; if not, write to the Free Software
16
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
    (c) 2006 Mike Lampard, Philip Lawatsch, and others
19
 
    
20
 
    $Revision: 129 $ -  $Date: 2006-11-13 03:02:49 +0100 (Mon, 13 Nov 2006) $ $Author: mlampard $
21
 
        
22
 
simple template plugin, replace the various functions with your own, and change the g15plugin_info struct below to suit,
23
 
   edit Makefile.am and compile.  Add salt and pepper to taste.  For a more advanced plugin that creates it's own lcd screens on-the-fly, 
24
 
   see the tcpserver plugin in this directory.
25
 
*/
26
 
#include <pthread.h>
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#include <signal.h>
30
 
#include <errno.h>
31
 
#include <string.h>
32
 
#include <sys/types.h>
33
 
#include <sys/stat.h>
34
 
#include <fcntl.h>
35
 
#include <unistd.h>
36
 
 
37
 
#include <config.h>
38
 
#include <g15daemon.h>
39
 
 
40
 
 
41
 
static int *lcdclock(lcd_t *lcd)
42
 
{
43
 
    unsigned int col = 0;
44
 
    unsigned int len=0;
45
 
    int narrows=0;
46
 
    int totalwidth=0;
47
 
    char buf[10];
48
 
    
49
 
    time_t currtime = time(NULL);
50
 
    
51
 
        memset(lcd->buf,0,1024);
52
 
        memset(buf,0,10);
53
 
        strftime(buf,6,"%H:%M",localtime(&currtime));
54
 
 
55
 
        if(buf[0]==49) 
56
 
            narrows=1;
57
 
 
58
 
        len = strlen(buf); 
59
 
 
60
 
        if(narrows)
61
 
            totalwidth=(len*20)+(15);
62
 
        else
63
 
            totalwidth=len*20;
64
 
 
65
 
        for (col=0;col<len;col++) 
66
 
        {
67
 
            draw_bignum (lcd, (80-(totalwidth)/2)+col*20, 1,(80-(totalwidth)/2)+(col+1)*20, LCD_HEIGHT, BLACK, buf[col]);
68
 
 
69
 
        }
70
 
        lcd->ident = currtime+100;
71
 
    
72
 
    return G15_PLUGIN_OK;
73
 
}
74
 
 
75
 
static int myeventhandler(plugin_event_t *myevent) {
76
 
//    lcd_t *lcd = (lcd_t*) myevent->lcd;
77
 
    
78
 
    switch (myevent->event)
79
 
    {
80
 
        case G15_EVENT_KEYPRESS:
81
 
        printf("template plugin received keypress event : %i\n",myevent->value);
82
 
          break;
83
 
        case G15_EVENT_VISIBILITY_CHANGED:
84
 
        printf("template received new visibility status (%i)\n",myevent->value);
85
 
          break;
86
 
        default:
87
 
          break;
88
 
    }
89
 
    return G15_PLUGIN_OK;
90
 
}
91
 
 
92
 
/* completely uncessary function called when plugin is exiting */
93
 
static void *callmewhenimdone(lcd_t *lcd){
94
 
}
95
 
 
96
 
/* completely unnecessary initialisation function which could just as easily have been set to NULL in the g15plugin_info struct */
97
 
static void *myinithandler(lcd_t *lcd){
98
 
}
99
 
 
100
 
/* if no exitfunc or eventhandler, member should be NULL */
101
 
plugin_info_t g15plugin_info[] = {
102
 
    /* TYPE, name, initfunc, updatefreq, exitfunc, eventhandler, initfunc */
103
 
    {G15_PLUGIN_LCD_CLIENT, "template plugin clock", (void*)lcdclock, 500, (void*)callmewhenimdone, (void*)myeventhandler, (void*)myinithandler},
104
 
    {G15_PLUGIN_NONE,               ""          , NULL,     0,   NULL,            NULL,           NULL}
105
 
};