The MP3car.com Store  

Welcome to the MP3Car.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   MP3Car.com > Mp3Car Technical > MacCar

Reply
 
Thread Tools Display Modes
Old 03-13-2007, 02:15 AM   #1
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
Sleep &*Wake up control

I always wanted to be able to use regular sleep of the Mac, but some of the issues were holding me back and making me stick to the deep sleep. The main problem was the risk of waking the Mac up at wrong moment. It is quite easy to bump into the controller when putting my stuff into the car. And if the ignition is not on at that moment (which is pretty likely), the P1900 detects high current and kills the mini.

Another issue we had to solve was the connection of the power button for the dock. Carnetix supplies an "Y" cable which allows the power button to be controlled by the P1900. Unfortunately, this connection is very difficult to impossible to incorporate into a dock. We did not want to install additional connectors to the mini's back side. So we had to find another solution. And well, we did find it.

It is well known, that any activity on the USB wakes Mac up if it is in the normal sleep mode. Pressing a button on a keyboard or a mouse, adding or removing a device. We can use this behaviour to both wake the mini up at the right time and prevent it from waking up when not appropriate.

The key is in the way the USB devices are powered. They can be either powered from the bus itself, or they can use an external power supply. Most of the hubs are bus-powered, but also allow connection of external power supply. Some of them use this power supply to completely power the hub, some only use the external power supply to distribute power to the connected devices, while the hub's own logical circuits are always powered from the bus.

If a USB hub can be completely powered by an external power supply (such as P5V or secondary output of P1900), it is possible to cut the power that the hub gets over the USB cable either by cutting the red wire in the cable or by insulating the pin 1 on the USB connector by piece of adhesive tape or similar material. When this is done, the hub's power state can be controlled simply by turning the external power on and off. If the power is on, the hub operates normall. If the power is off, the hub is also off and is not visible on the USB. This is also true for any devices connected to the hub. So if the Mac is asleep and a keyboard is connected to hub, which is turned off, the press of a key on this keyboard will not wake up the Mac.

And it get even better. When the hub is powered up, it becomes visible to the Mac over the USB. If the Mac is sleeping at the time, this will trigger wake-up. Therefore if the power to the hub is supplied by a source, that follows the state of the ignition/acc line, the Mac will never wake up when the ignition is off and will always wake up when the ignition is turned on. This leaves us with the last problem - how to put the computer to sleep?

The solution is again pretty simple. When the ignition is turned off, the USB devices are powered down and become invisible to the computer. The solution is to run a simple application on the Mac, that controls the presence of certain device(s). When the devices are not accessible, it means the hub has been powered down because the ignition is down. So when the application detects the device it watches is missing, it puts the computer to sleep.

The "USB watchdog" module for QCar is just being tested. I will post more details about the wiring and the relevant pieces of code probably over the next weekend. It should be easy to use this principle in other applications as well.
Jirka Jirout is offline   Reply With Quote
Sponsored Links
Old 03-13-2007, 09:53 AM   #2
CarFrontEnd Creator
iamgnat's CarPC Specs
 
iamgnat's Avatar
 
Join Date: Jul 2004
Location: NoVA
Vehicle: 04 Ford Escape
Posts: 847
My Photos: (0)
Quote: Originally Posted by Jirka Jirout View Post
The solution is to run a simple application on the Mac, that controls the presence of certain device(s). When the devices are not accessible, it means the hub has been powered down because the ignition is down. So when the application detects the device it watches is missing, it puts the computer to sleep.

Jirka,
Unless there is something else you are doing with USB Watchdog, you could have it watch the Hub itself. The main benefits are that A) if they just disconnect the watched device (say a HDD, GPS, etc...) to do something else with it, down goes the Mac. Also if they they plug it into the Mac directly to it's USB power supply without changing their configuration, then the Mac doesn't sleep.

It's been awhile since I looked, but I believe that there was USB browser example in the XCode examples or on the Apple Developer site in the IOKit section.

-dave
__________________
My pathetic worklog.
CarFrontEnd (now it's own sub-forum!!!!)
iamgnat is offline   Reply With Quote
Old 03-13-2007, 10:06 AM   #3
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
Quote: Originally Posted by iamgnat View Post
Unless there is something else you are doing with USB Watchdog, you could have it watch the Hub itself.

that's what I did in the end, because I was too lazy to play around with the IOKit :-)

So I wrote a simple script:

Code:
#!/bin/sh while [ 1 ] do ioreg | grep -c USBHub sleep 1 done

which runs in the background and every second reports the number of connected USB hubs. The "correct" number is set in the preferences of the watchdog and the sleep action is triggered whenever the watchdog detects hub removal.
Jirka Jirout is offline   Reply With Quote
Old 03-13-2007, 11:25 AM   #4
CarFrontEnd Creator
iamgnat's CarPC Specs
 
iamgnat's Avatar
 
Join Date: Jul 2004
Location: NoVA
Vehicle: 04 Ford Escape
Posts: 847
My Photos: (0)
Quote: Originally Posted by Jirka Jirout View Post
that's what I did in the end, because I was too lazy to play around with the IOKit :-)

Why do you think I don't mess around with IOKit and prefer to use USB -> Serial

You still run some risks that way (say a keyboard with a hub (like the Apple keyboard) gets plugged directly into the Mac and left plugged in for some reason). I'm just anal retentive about things like that though, so you can ignore me

-dave
__________________
My pathetic worklog.
CarFrontEnd (now it's own sub-forum!!!!)
iamgnat is offline   Reply With Quote
Old 03-13-2007, 11:32 AM   #5
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
Quote: Originally Posted by iamgnat View Post
You still run some risks that way (say a keyboard with a hub (like the Apple keyboard) gets plugged directly into the Mac and left plugged in for some reason).

Yes, that is a risk and this situation must be prevented by appropriate installation planning. In my case, only the CDMA modem is plugged directly into the Mac, everything else goes thru a hub (including the connectors in the dashboard).
Quote:
I'm just anal retentive about things like that though, so you can ignore me

No problem. An advocatus diaboli is a very useful person :-)
Jirka Jirout is offline   Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Climate Control..... map_auto General Hardware Discussion 1 06-07-2006 05:07 AM
How to control the wave output in ME d.a.one Media Engine 3 05-06-2006 11:41 AM
Feature Request: Advanced Volume Control skeeter007 Road Runner 6 03-20-2006 05:23 PM
no sound control with emulators selmerguy Mobile Impact 2 02-04-2006 07:58 PM
USB FM/AM tuner with RDS/RBDS Seth General Hardware Discussion 333 08-29-2004 06:02 PM


All times are GMT -5. The time now is 08:19 AM.


Sponsored Links
The MP3car.com Store

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Copyright © 1999 - 2008 Mp3Car.com Inc.
Ad Management by RedTyger
Message Board Statistics