Here is the free hand wiring digram of the circuit I'm going to use.
Oh yeah, giving xkcd a run for his stick figure money. Honestly, I love xkcd.
So this might not be the best way to do what I want to do but here is my resoning for each part. (and by part I mean the 5 freaking relays)
The Main Relay is taking the key power to switch a relay and power the screen, the Timer Relay and the Detection Relay. This means the key only has to power that relay coil and it never has the chance of meeting up with the battery power. It is rare but a car can sometimes have a difference of voltage or sometimes impedance between those two power sources. I don't want to have to replace seemingly random parts at seemingly random intervals.
The Timer Relay is there because I've found that the HDMI connection does not start up correctly if the monitor isn't turned on a second or so be for the computer is powered. I bought this one for a illegal mod to a in dash DVD player that wouldn't show video without a ground meant for the E-brake. Well, that DVD player is gone so I might as well use the relay for an even more illegal distraction for my driving.
The Detection Relay isolates the car's 12v from the GPIO's 3.3v input. I'm using an external pull-up resistor just to be sure if I mess up the programing I won't hurt the board.
The last two relays are on a computer controlled relay board (this is the one I bought, I hope it works). One of the relays will keep the power on while the key is off and computer has not finish turning off. The other was an additional dollar so I'll figure something to do with it at some point. maybe I'll come across a cool 12v light I just can't live without, I don't know.
There are a few other odds and ends. I've already mentioned the pull-up resistor but you may have noticed a diode on the timer circuit. This is so the power running through the computer controlled relays don't keep the screen powered on and more importantly they don't keep the detection relay closed.
Then there is a Bypass switch I plan on mounting in the glove box with the radio (I'm using something just like this). It will let me keep the computer on if I want to go inside my loft and update stuff over the wifi connection. This will let me add music and update software. I placed it in the circuit where I did so it would keep the detection relay on. I would like the screen to still turn off but the switch I have is not dpdt and I'm not adding another relay.
So I have a script that I tested with some jumper wire and an LED instead of the relay. I am not a programmer. I'm hardly a script kitty. So I got some help from a friend who is a programmer. Many props to Martin! He helped me sort out a few things that I did horribly wrong. Here is what I'm using.
#! /bin/bash
#This part turns on the relay to hold power on during shutdown
echo "17" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio17/direction
echo "1" > /sys/class/gpio/gpio17/value
#this sets up the input pin for the shutdown signal
echo "22" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio22/direction
#this part look at the power signal relay for shutdown
while [ true ]; do
sleep 1s
CONTENTS=`cat /sys/class/gpio/gpio22/value`
if [ "$CONTENTS" = "1" ]; then
shutdown -h 0
fi
done
This is in a file I have named gpio_relay.sh. So far I have only started it manually. I plan on using rc.local to start it on boot up. This was all done with Raspbian. The dependacys and hooks will have to be figured out for the Raspbmc and I plan on doing that as part of the figuring out the touch screen in stuff on Raspbmc.
I plan on updating this tomorrow night with a link to something for Martin and after my wife weeds out all my stupid in the writing.