2
* ----------------------------------------------------------------------------
3
* fblevel - sets the fb device brightness level on Apple Powerbooks
5
* Copyright 2000 Stephan Leemburg <stephan@jvc.nl>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version
10
* 2 of the License, or (at your option) any later version.
11
* ----------------------------------------------------------------------------
13
* Revision 1.1.1.1 2001/12/07 11:31:50 sleemburg
14
* Initial CVS import of the unreleased pmud-0.8 to apmud (new project name
15
* because of a name clash at sourceforge.net).
17
* Revision 1.3 2001/11/09 10:55:29 stephan
20
* Revision 1.2 2000/10/09 14:16:33 stephan
21
* use /dev/fb0 in stead of /dev/fb
23
* Revision 1.1 2000/05/11 14:48:46 stephan
26
* ----------------------------------------------------------------------------
28
static char *rcsid = "@(#)$Id: fblevel.c,v 1.1.1.1 2001/12/07 11:31:50 sleemburg Exp $";
35
#include <sys/ioctl.h>
36
#include <sys/types.h>
42
#include <linux/pmu.h>
45
#define FBIOBLANK 0x4611 /* 0 or vesa-level+1 */
48
static void fbon(int on);
49
static int set_fblevel(int level);
50
static int get_fblevel();
51
static void usage(char *program);
53
int main(int argc, char **argv)
55
char *program = strrchr(*argv, '/');
57
program = program ? program + 1 : *argv;
62
printf("%d\n", get_fblevel());
65
if(!strcasecmp(*++argv, "on")
66
|| !strcasecmp(*argv, "off"))
67
fbon(strcasecmp(*argv, "off"));
72
for(p = *argv; *p && isdigit(*p); p++)
79
if(!set_fblevel(atoi(*argv)))
91
static void fbon(int on)
96
fd = open("/dev/fb0", O_RDONLY);
103
(void)ioctl(fd, FBIOBLANK, !on);
106
static int set_fblevel(int level)
109
if ( (fd = open("/dev/pmu", O_RDONLY)) < 0 ) {
113
if(ioctl(fd, PMU_IOC_SET_BACKLIGHT, &level) == -1) {
114
perror("ioctl PMU_IOC_SET_BACKLIGHT");
117
ret = 1; /* success */
123
static int get_fblevel()
126
if ( (fd = open("/dev/pmu", O_RDONLY)) < 0 ) {
130
if(ioctl(fd, PMU_IOC_GET_BACKLIGHT, &level) == -1) {
131
perror("ioctl PMU_IOC_GET_BACKLIGHT");
139
static void usage(char *program)
142
"usage: %s [on|off|<level>]\n"
143
" on : powers display on\n"
144
" off : powers display off\n"
145
" <level>: set display brightness to <level>\n"
146
" (level is an integer)\n"
147
"no argument prints the current brightness level\n",