« previous: Marketing | next: Thoughts »
Musicbox got Smarter
My musicbox now detects when the key is removed from the ignition, and when that happens, it fades the music out and shuts itself down automatically, saving the current playlist and the current song’s elapsed time. With this feature, my system is now just like a normal car stereo in terms of on/off: it turns on and off automatically with the car, so the only time you have to touch it is to select the music. (Previously, I had to press a key to make it shut down, before turning the car off.)
This was actually really simple to accomplish. When a car is shut off, its accessory signal goes low (goes to zero volts). So I just send the car’s accessory signal from the ignition into pin 6 on the computer’s serial port (the DSR pin). It just takes a few lines of C code to detect the state of that pin:
int i = TIOCM_DTR;
ioctl(fd, TIOCMSET, &i);
int dsr_state=0, dsr_prev_state=0;while(1)
{
ioctl(fd, TIOCMGET, &i);
dsr_state = i & TIOCM_DSR;if((dsr_state==0) && (dsr_prev_state==256))
{
printf("The DSR pin went from high (256) to low (0).\n");
exit(1);
}dsr_prev_state = dsr_state;
sleep(1);
}
My musicbox script forks that C program at startup, and when it exits, the script shuts the computer down nicely. I have an RC timer circuit that keeps the computer powered for about 11 seconds after the car is shut off, and the computer’s shutdown process takes about 5 seconds.
Here’s the diagram:
[img src="00515--full_diagram--20040327-1654.png" width=622 height=272 align=left clear=all]
You can read more about it here.
Comments:
Reply to this message here:
[ Home – Create Post – Archives – Login – CMS by Encodable ]