[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 2.4.19 crashes, 16 bpp framebuffer



On Mon, 2003-02-03 at 21:31, Ralph Siemsen wrote:
> How about the next best thing: a silent machine that turns on its fan
> if it is about to overheat?  I can make my binary available if wanted.
> ftp://ftp.netwinder.org/users/g/guinan/fand.c

I had some problems with the original fand.c so I rewrote it. I've
attached my version to this message.

-- 
------------ Alex Holden - http://www.linuxhacker.org ------------
If it doesn't work, you're not hitting it with a big enough hammer


/*
 * Jamie Guinan, December 1998
 * Tidied up somewhat by Alex Holden, January 2001.
 *
 * Turns the fan off when the temperature gets down to two degrees below the
 * low thermostat setting, and turns it back on again when it reaches the
 * low setting. This gives a two degree hysteresis band, which seems to give
 * good results for me. Changes to the thermostat settings are automatically
 * detected, and the fan is always turned back on again on exit except when
 * kill -9'ed.
 *
 * Copyright:  Free for redistribution, modifications welcome, as 
 *    long as credits maintained.
 *
 * Warranty: None whatsoever.
 */

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <asm/therm.h>

#define THERMDEV "/dev/temperature"

int therm_fd;

void set_fan(int i) { ioctl(therm_fd, CMD_SET_FAN, &i); }

/* On exit, turn the fan on first. */
void exit_handler(void) { set_fan(1); }

void daemonise()
{
	switch(fork()) {
		case 0: /* Child. */
			break;
		case -1: /* Error. */
			exit(1);
			break;
		default: /* Parent. */
			exit(0);
	}
	/* No controlling terminal. */
	setsid();
}

void initialise(void)
{
	/* Go into background */
	daemonise();

	/* Open the thermostat device. */
	if((therm_fd = open(THERMDEV, O_RDONLY)) == -1) exit(1);

	/* Make sure we turn the fan back on on exit. */
	atexit(exit_handler);
}

int main(int argc, char *argv[])
{
	struct therm ts;
	int temp;

	/* Initialise the program */
	initialise();

	/* Main loop */
	while(1) {
		/* Get the current temperature */
		ioctl(therm_fd, CMD_GET_TEMPERATURE, &temp);
		/* Get the current thermostat settings */
		ioctl(therm_fd, CMD_GET_THERMOSTATE2, &ts);

		/* Turn the fan off if we are 2 degrees below the low setting */
		if(temp <= (ts.lo - 2)) set_fan(0);
		/* Turn the fan on if we are at or above the low setting */
		else if(temp >= ts.lo) set_fan(1);

		/* Wait a second between each reading */
		sleep(1);
	}

	return 0;
}

Reply to: