]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/slutils/slutils-0.1.0/slbl/slbl.c
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / slutils / slutils-0.1.0 / slbl / slbl.c
1 /*
2    slbl backlight utility for Sharp Zaurus
3    version 1.0
4    Copyright 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <time.h>
25 #include <string.h>
26
27 #define SHARP_FL_IOCTL_DEVICE   "/dev/sharp_fl"
28 #define SHARP_FL_IOCTL_ON                  1
29 #define SHARP_FL_IOCTL_OFF                 2
30 #define SHARP_FL_IOCTL_STEP_CONTRAST     100
31 #define SHARP_FL_IOCTL_GET_STEP_CONTRAST 101
32 #define SHARP_FL_IOCTL_GET_STEP          102
33
34 int main(int argc, char *argv[])
35 {
36         int fd;
37         int steps;
38         int current;
39         int new;
40
41         fd = open( SHARP_FL_IOCTL_DEVICE, O_RDWR );
42         steps = ioctl( fd, SHARP_FL_IOCTL_GET_STEP, 0 );
43         
44         if ( steps < 1 )
45         {
46                 perror( "SHARP_FL_IOCTL_GET_STEP: ");
47                 close( fd );
48                 exit( 1 );
49         }
50         current = ioctl( fd, SHARP_FL_IOCTL_GET_STEP_CONTRAST, 0 );
51
52         if (argc < 2)
53         {
54                 printf( "Current backlight setting = %d / %d\n", current, steps-1 );
55         }
56         else if (strcmp(argv[1], "on") == 0)
57         {
58                 ioctl( fd, SHARP_FL_IOCTL_ON, 0 );
59         }
60         else if (strcmp(argv[1], "off") == 0)
61         {
62                 ioctl( fd, SHARP_FL_IOCTL_OFF, 0 );
63         }
64         else if (sscanf(argv[1], "%d", &new) == 1)
65         {
66                 printf( "Setting backlight to %d\n", new );
67                 ioctl( fd, SHARP_FL_IOCTL_STEP_CONTRAST, new );
68         }
69         else
70         {
71                 printf( "Usage:\n%s [on|off|<num>]\n", argv[0]);
72                 exit(1);
73         }
74         close( fd );
75         return 0;
76 }
77