[comp.sys.next] Display Brightness Command

lane@sumex-aim.stanford.edu (Christopher Lane) (02/09/89)

For those interested in saving finger strain (and accidental pushes of the
power key), the code defines a program to manipulate the screen brightness
until better facilities are provided in 0.9 (or whenever).

Once you 'cc' and 'mv' the a.out to 'bright' then 'bright' with no argument
prints out the current brightness value; 'bright max' & 'bright min' will set
the brightness to the limits and 'bright def' will set it to the default
(arbitrary and can be set below).  If a numeric argument is given, the
brightness is set to that value which should range between 'bright min;bright'
and 'bright max;bright'.  The command can be added to .login & .logout files.

I tried to make a 'slider' version of this program but the 'open' failed with
a 'Device busy' when run under the IB generated code.  If someone gets this to
work, I'd be interested in hearing about it (my machine crashed several times
trying--the 'shell' version of the code below hasn't caused any problems).

- Christopher 


#include <sys/file.h>
#include <sys/ioctl.h>
#include <nextdev/video.h>

#define BRIGHT_MAX    0x3d    /* MIN & MAX from <next/scr.h> */
#define BRIGHT_DEF    0x1f
#define BRIGHT_MIN    0x00

main(argc, argv)
int argc;
char *argv[];
{
    int b = 0, c, d;
        
    if((d = open("/dev/vid0", O_RDWR, 0)) != -1){
        if(ioctl(d, DKIOCBRIGHT, &b) == -1) perror("ioctl");
        else if(argc > 1){
            if(strncmp(argv[1], "max", 3) == 0) c = BRIGHT_MAX;
            else if(strncmp(argv[1], "min", 3) == 0) c = BRIGHT_MIN;
            else if(strncmp(argv[1], "def", 3) == 0) c = BRIGHT_DEF;
            else c = atoi(argv[1]);
            c -= b;
            if(c && (ioctl(d, DKIOCBRIGHT, &c) == -1)) perror("ioctl"); 
            }
        else printf("%d\n", b);
        close(d);
        }
    else perror("open");
}