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.

Posted by Anthony on 4 replies

Comments:

01. Mar 28, 2004 at 03:37pm by kaiser:

I want one.

02. Mar 28, 2004 at 04:24pm by Anthony:

If you buy the parts, I’ll build it...

03. Mar 29, 2004 at 01:00pm by Rolly:

Your description of a "normal" car stereo made me laugh.  My "normal" car stereo/cd changer does not remember the elapsed time of the current cd track when the car is turned off.  So every time I turn on the car, the current track starts playing....at the beginning!!  You can imagine how annoying this is, especially when I’m running around to different places that are close to each other.  I can’t fathom the benefit of a set-up like this, and cannot identify a setting to change to alleviate this annoyance.

04. Mar 30, 2004 at 02:55pm by Anthony:

Man, that is insanity!  My head unit is 6 years old now, and it starts where it left off.  Is yours made out of Lincoln Logs?

Anyway... if you didn’t live in the city, I’d say you have no choice but to get a musicbox asap.

Reply to this message here:

Your name
Email
Website (optional)
Subject

HomeCreate PostArchivesLoginCMS by Encodable ]