This is adim.c in view mode; [Download] [Up]
/*
* adim.c play with autodim parameters
*
* NeXT Monochrome Monitors last about 2 years if left on all the time, NOT
* real good. This may be do to burn in? If it is one would think that a
* screen saver would help. Backspace is one of the nicest i have seen!
* Backspace and all other screen savers that i have seen have one major
* flaw, they can not dim the login screen! For some reason known only to
* NeXT you can not set the time to dim or the brightness value for a dimmed
* screen from the Preferences app.
*
* So i wrote adim. All adim does is set the time to delay before dimming the
* screen and the brightness of the dimmed screen. This works great while
* one is logged in. When you log out something resets both brightness and
* time. Solution, run adim from cron every few minutes or use the -s
* option and background adim. If you use the -s option a adim's process id
* and a new line will be written to a file. /tmp/adim.pid is the default,
* use the -f option to change.
*
* I think the NeXT is a good machine, something is very wrong with the design
* of the monitor!!! A two year life expectancy sucks, my old AT&T 6300
* monitor lasted 6.5 years.
*/
/*
1992.02.16 0.1 Original coding harold barker, barker@wri.com
Documentation: Ha, see the usage function at
the end of this file.
1992.02.19 1.0 First release, barker@wri.com
*/
#include <stdio.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <nextdev/evsio.h>
static void get_autodim_brightness(int *);
static void set_autodim_brightness(int);
static void get_autodim_time(int *);
static void set_autodim_time(int);
static void get_autodim_status(int *);
void usage(void);
int adb = -1; /* current brightness */
int adt = -1; /* current time interval */
int ads = -1; /* current status of screen dim */
int new_adb = -1; /* */
int new_adt = -1; /* */
int verbose = 0; /* verbosity flag */
int pid = 0; /* our process id */
int sleep_time = 0; /* time to sleep between writes */
FILE *pid_fh = NULL; /* file handle for pid file */
char progname[512]; /* local copy of the name of this
* program */
char pid_file[512]; /* file to dump pid into */
char version[16] = "V1.0"; /* version number string */
int
main(argc, argv)
int argc;
char **argv;
{
int c;
extern char *optarg;
extern int optind;
strcpy(progname, argv[0]); /* save the name of program */
strcpy(pid_file, "/tmp/adim.pid"); /* default process id file */
pid = getpid(); /* get our pid */
get_autodim_status(&ads); /* gat current status */
get_autodim_brightness(&adb); /* get old brightness value */
get_autodim_time(&adt); /* get current dim interval */
/*
* process command line args
*/
while ((c = getopt(argc, argv, "b:f:hs:t:v")) != EOF) {
switch (c) {
case 'b': /* new brightness value */
new_adb = atoi(optarg);
if ((new_adb > 61) || (new_adb < 0)) {
fprintf(stderr, "%s: Invalid value given for brightness, 0 <= b <=61\n", progname);
}
break; /* end of case b (set brightness) */
case 'f': /* pid_file name */
strcpy(pid_file, optarg);
break;
case 's': /* seconds to wait between poking */
sleep_time = atoi(optarg);
break; /* end of case s (set sleep_time ) */
case 't': /* time to wait between last activity
* and dim */
new_adt = 68 * atoi(optarg);
break; /* end of case t (set time ) */
case 'v': /* turn on verbose mode */
verbose++;
break; /* end of case v ( set verbosity) */
case 'h': /* print usage message */
case '?':
default:
usage();
break;
} /* end of switch */
} /* end of while getopt */
/*
* dump some info to stdout
*/
if (verbose > 0) {
printf("Autodim brightness [%d]\n", adb);
printf("Autodim status [%d]\n", ads);
printf("Autodim sleep_time [%d]\n", sleep_time);
printf("Autodim time [%d] or about %d seconds.\n", adt, adt / 68);
printf("Autodim pid [%d]\n", pid);
printf("Autodim pid_file [%s]\n", pid_file);
} /* end od if verbose */
if (sleep_time > 0) { /* if this is not a one time shot */
pid_fh = fopen(pid_file, "w"); /* try to open process id file */
if (pid_fh == NULL) { /* if error opening pid file */
fprintf(stderr, "%s: Error opening pid_file %s\n", progname, pid_file);
} else { /* file opened ok */
fprintf(pid_fh, "%d\n", pid); /* write our process id to
* file */
fclose(pid_fh);
} /* end else pid file opened ok */
} /* end of if sleep_time > 0 */
/*
* If sleep time was not given this will be done once. If sleep time was
* given it will repeat until killed( see pid_file for pid )
*/
do {
if (new_adb != -1) /* if we have something to set */
set_autodim_brightness(new_adb); /* poke our brightness value */
if (new_adt != -1) /* if we have something to poke */
set_autodim_time(new_adt); /* set our delay before auto dim */
if (sleep_time > 0) /* if we want to sleep */
sleep(sleep_time); /* night night */
} while (sleep_time > 0);
exit(0); /* exit with normal errorlevel */
} /* end of main */
/*
* Return the current setting of the auto dim brightness
*/
static void
get_autodim_brightness(int *level)
{
int evs_fd;
evs_fd = open("/dev/evs0", O_WRONLY);
if (evs_fd < 0) {
perror(progname);
fprintf(stderr, "%s: Error opening /dev/evs0; cannot get brightness.", progname);
exit(1);
}
ioctl(evs_fd, EVSIOCADB, level);
close(evs_fd);
}
/*
* Set the current setting of the auto dim brightness
*/
static void
set_autodim_brightness(int level)
{
int evs_fd;
evs_fd = open("/dev/evs0", O_WRONLY);
if (evs_fd < 0) {
perror(progname);
fprintf(stderr, "%s: Error opening /dev/evs0; cannot set brightness.", progname);
exit(1);
}
ioctl(evs_fd, EVSIOSADB, &level);
close(evs_fd);
}
/*
* Return the current setting of the time till auto dim
*/
static void
get_autodim_time(int *level)
{
int evs_fd;
evs_fd = open("/dev/evs0", O_WRONLY);
if (evs_fd < 0) {
perror(progname);
fprintf(stderr, "%s: Error opening /dev/evs0; cannot get time.", progname);
exit(1);
}
ioctl(evs_fd, EVSIOCADT, level);
close(evs_fd);
}
/*
* Set the current setting of the time till auto dim
*/
static void
set_autodim_time(int level)
{
int evs_fd;
evs_fd = open("/dev/evs0", O_WRONLY);
if (evs_fd < 0) {
perror(progname);
fprintf(stderr, "%s: Error opening /dev/evs0; cannot set time.", progname);
exit(1);
}
ioctl(evs_fd, EVSIOSADT, &level);
close(evs_fd);
}
/*
* Return the current dim state
*/
static void
get_autodim_status(int *level)
{
int evs_fd;
evs_fd = open("/dev/evs0", O_WRONLY);
if (evs_fd < 0) {
perror(progname);
fprintf(stderr, "%s: Error opening /dev/evs0; cannot get status.", progname);
exit(1);
}
ioctl(evs_fd, EVSIOCADS, level);
close(evs_fd);
}
/*
boiler plate */
void
usage(void)
{
fprintf(stderr, "\n%s version %s compiled at %s on %s\n", progname, version,__TIME__,__DATE__);
fprintf(stderr, " usage: %s [-bn] [-ffilename] [-h] [-sn] [-tn] [-v]\n", progname);
fprintf(stderr, " -b n \n");
fprintf(stderr, " Set the brightness of the screen to n when dimmed.\n");
fprintf(stderr, " n is a number between 0 and 61, 0 = darkest.\n");
fprintf(stderr, " default = What ever NeXT has set.\n\n");
fprintf(stderr, " -f filename \n");
fprintf(stderr, " Set the name of the file used to record process id.\n");
fprintf(stderr, " default = /tmp/adim.pid. Only if -s is given.\n\n");
fprintf(stderr, " -h \n");
fprintf(stderr, " Print this help message.\n\n");
fprintf(stderr, " -s n \n");
fprintf(stderr, " Set the time in seconds to wait between writing brightness.\n");
fprintf(stderr, " and time values to evs0. Process id is written to a file (see -f).\n");
fprintf(stderr, " There is no default for n.\n\n");
fprintf(stderr, " -t n \n");
fprintf(stderr, " Set the time in seconds between last key press or mouse event and\n");
fprintf(stderr, " screen dimming.\n");
fprintf(stderr, " default = What ever NeXT has set.\n\n");
fprintf(stderr, "Example from my /etc/rc.local\n");
fprintf(stderr, "/usr/local/bin/adim -b0 -t300 -s60 &\n");
return;
} /* end of usage */
/*
* End of File adim.c
*/
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.