It’s BedTime!

June 5, 2007

So, the other day I opened my laptop bag and whipped it out only to realize that my laptop had been left on, again, and was now totally hot and mostly drained.

I’m the proud owner of a newer Vista laptop (a tricked out Lenovo T60p). I get 3 hours and 30 minutes out of every charge running at High Performance (instead of that limited Power Saver mode most people use). …And yet somehow I only get to enjoy 2 hours of that because I leave the laptop on in my bag for the majority of the day. I know I just have to hit that sleep button but I have thousands of other things on my mind. That’s when I realized something had to be done. This needed to be automated. I sat down and started coding. A few hours later I ran BedTime for the first time.

BedTime, the program I wrote, monitors the laptop accelerometer. Accelerometers are commonly used to automatically shutdown the hard drive when a laptop moves suddenly. They’re very precise and easy to work with thanks to some great DLL APIs. The DLL reports the pitch, roll and hard drive status. My program monitors this data and automatically triggers sleep mode when it suspects the laptop is being moved, and not being used. …Like when I leave my laptop in my bag and walk around for a few hours.

It works EXACTLY how I wanted it to. Now I can forget the Sleep button forever, my laptop will automatically go to sleep for me. There is a 10MB overhead (caused by some .NET 2.0 overhead I should get rid of) but I have 3GB, and I think most owners of new laptops boast about the same amount of memory, so this shouldn’t be a problem.

I already know this program will only run on newer laptops because older systems don’t have accelerometers. …That’s part of why their hard drives blow up. (…That reminds me; If you own an older system please backup regularly. I’ve been there before, with a crashed drive, just once. I never happened again because it was horrible and now I do my best to warn others. PS: If you buy a new laptop with an accelerometer Vista makes backups a cinch. …And yes, Bill made me say that, but Gates rocks and I would never leave Vista for XP, a filthy penguin or some fruity OS).

I’m currently testing this application on a daily basis and working on a patent for the concept and copyright for the code. I hope to be looking for beta users soon, so please let me know if you have a newer laptop with an accelerometer (like a Lenovo, Apple, etc.) and are interested. Even if you have an off-brand you have an accelerometer if your laptop advertises having an “Airbag” or “Active Protection System” for hard drive.

Here’s some screenshots…

This dialog appears when you double-click the BedTime icon…

This is the Settings dialog. It allows the user to configure the amount of movement to allow, etc…

This is the dialog that appears before the laptop automatically goes to sleep…

…Of course, all laptops have those settings to automatically launch Sleep mode after a specific amount of time with no user activity. My problem with that feature had always been that if I set the feature for 15 minutes it would launch while I was distracted and become annoying. I’m still using that feature now in tandem with BedTime. I have it set to 30 minutes. I use that more like a failsafe.

My laptop, and many others, also support automatically launching Sleep mode when the laptop lid closes. I disabled that because I close the lid when I move from one seat to the next, e.g. when I’m going from the office desk to the kitchen counter. I didn’t *always* want it to go to sleep. Now BedTime automatically launches in those situations and I have a chance to abort Sleep mode by the time I get to my destination.

Future versions of BedTime will likely only operate when the lid is closed, or at least support that option. Now that I’ve been paying attention to how I move my laptop I realize it’s usually closed when I want BedTime to go into effect. …BedTime does this perfectly, but it also triggers sometimes when I pick up the laptop, or move it to plug in devices, insert a DVD, etc.

What do you think of the idea and design? I was going for a sexy-but-all-business look. This interface was probably inspired by the way Vista launches the security authorization dialogs. I think it deserves the whole screen because it is only on your screen just before it puts your laptop to bed (Sleep mode). And, if you can see it you probably want to hit abort. It runs as an “Always-on-top” Windows Form so it blocks the user from interacting with anything else. …How do you feel about that? But if BedTime is on your screen you want to click Abort and get rid of it, not hide it. Pressing Alt+F4, Escape, Alt+A, Enter or clicking on the button will all abort Sleep mode. …Do you think it would be overkill to abort on any keystroke? …So far, based on my user experience, I think that makes sense.

Well, I think this little project will be a work-in-process for more than a minute. The idea is a little ahead of its time since most laptops don’t have the required hardware. …But that WILL change. Every new laptop will have more and more accelerometers. That is happening as we speak because they are proving to be more and more useful (my program for example).

I think other factors will also increase their popularity (and lower their price by increasing manufacturing volumes). ….Did you know most new digital cameras have one, even the new iPhone has one! That’s why the iPhone can change the display from landscape to portrait when the user rotates the phone. …Why don’t ALL Windows Mobile phones have them? …? …? Bill?

Well who knows what will happen. Either way this was fun to write and has improved my battery life and user experience. Here’s a video of me using the software…

Hack the Planet,
-8r13n

Advertisements

Share this:

Like this:

Related

82 Responses to “It’s BedTime!”

[…] to park the hard drive heads in case the laptop is falling (it’s also used for hilarity). If BedTime detects that the laptop is in motion, but is not being used it starts a countdown and eventually […]

I have a newer Lenovo T43 with the active protection system built in, im also running Xp, not Vista. I would be willing to try this out for you, seems like a sound idea. Email me if you want me to test it out.

This is good stuff. I’ve gotten annoyed about this exact same problem lots of times, too, especially when logging the laptop from to and from lectures, just like you. I wondered why nobody’d done anything about it yet. This sounds like an optimal solution. Will play with your alpha right away.
I’m interested in testing this, expect an email soon.
Cheers.

[…] to park the hard drive heads in case the laptop is falling (it’s also used for hilarity). If BedTime detects that the laptop is in motion, but is not being used it starts a countdown and eventually […]

forgive my stupidity, but the application calls for a “BedTime.exe.manifest” from subdirectory \BedTime_1_0_1_16. Is this a result of not having needed hardware or am I just too simple to use this software?

“There is a 10MB overhead (caused by some .NET 2.0 overhead I should get rid of) but I have 3GB, and I think most owners of new laptops boast about the same amount of memory, so this shouldn’t be a problem.”

This is a neat idea but it’s really an unnecessary workaround for what amounts to a very bad hardware design decision. Even worse is that this bad design is a result of bad software design. Here’s what I’m talking about:

If you close the lid your laptop should go to sleep — and it should do this absolutely without fail. Apple, for instance, really understands this and it is the primary reason that using their portables is so absolutely pleasurable. When closed, however, most PC laptops power off the screen but keep running which brings me to my next point:

If you open the lid your laptop should be ready to work; instantly. Until XP and Vista came around I’d dare to say that this was not even remotely possible with a Windows system, and despite great advancements on the power management front, there is invariably some device driver or software that is reluctant to accept quick suspend/resume on the pc, and in an even more fundamentally flawed bit of reasoning a normal user application can trap, interrupt, or even cancel such power events. Even when the events do work properly and a machine suspends and resumes successfully due to poor processes the task can take an age (it takes my brand-spanking-new right-out-of-the-box high-end Vista-running desktop about 90s to resume) And all of this takes us back to point one:

PC laptops (generally) don’t suspend automatically (or don’t suspend reliably) when the lid is closed because suspend/resume doesn’t actually work properly anyway. Who closes the lid of their laptop and wants it to keep running full tilt? The kind of people that don’t want to wait 1-4 minutes to get back to work when they re-open it! What kind of manufacturer would want to put that feature into a laptop and create a support nightmare for themselves when it never worked properly?

With the slow trend towards portables (laptops outselling desktops, etc) in the consumer market, this problem will get better — eventually (read: hopefully) Microsof will actually solve the power management problem once and for all by forcing drivers and software to comply or by the consumer market failing to accept broken devices or implementations.

I’m being a little unfair here — so I’m going to mention the two counterpoints in advance to any arguing about them:

1) People sometimes want to let their laptops run when closed — say to wait on a download or do a backup or access remotely. Or they want to use the latpop with an external monitor and keyboard — Great; give the user an option or setting, a physical switch, etc. Don’t sleep if there’s an external monitor and keyboard attached. There are a lot of obvious solutions to this problem so it doesn’t even make sense to argue on this point.

2) A lot of PC laptops *DO* trigger sleep when the lid is closed. Saying they do not is overgeneralazing, but it does not change the fact that even on many of the machines that are capable of this ship with the feature disabled or have the feature crippled by drivers or software that do not behave correctly during sleep/resume.

Again, this applicastion is a good idea and is arguably useful, but it still gambles on suspend/resume actually working. Imagine if instead of reading the motion sensor, you could just read the state of the laptop’s lid latch — it is simpler, less resource intensive and is probably more reliable. But the problem is that ACPI should already be doing this — it shouldn’t take another program to solve this problem!

ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Documents and Settings\hackmiester\My Documents\downloads\BedTimeAlpha\BedTime.application resulted in exception. Following failure messages were detected:
+ Downloading file:///C:/Documents and Settings/hackmiester/My Documents/downloads/BedTimeAlpha/BedTime_1_0_1_16/BedTime.exe.manifest did not succeed.
+ Could not find a part of the path ‘C:\Documents and Settings\hackmiester\My Documents\downloads\BedTimeAlpha\BedTime_1_0_1_16\BedTime.exe.manifest’.
+ Could not find a part of the path ‘C:\Documents and Settings\hackmiester\My Documents\downloads\BedTimeAlpha\BedTime_1_0_1_16\BedTime.exe.manifest’.
+ Could not find a part of the path ‘C:\Documents and Settings\hackmiester\My Documents\downloads\BedTimeAlpha\BedTime_1_0_1_16\BedTime.exe.manifest’.

Another thing, shouldn’t #1 be “absence of user activity must be detected?” I’m pretty sure the current wording states that you have to be using the Laptop to have it sleep. I can’t wait to see this in action!

Ok, I finally posted the source. Go to…http://www.suite304.com/BedTimeSource.zip
…Now, if you change this and make it better PLEASE SHARE YOUR CHANGES WITH ME. I will give full credit to ANY contributions. Trust me, I’m not going to screw you (I’m a Woz-ish geek).
…Oh, and I really need a new icon (the asterisk was last minute). So if you can create something cool please send it to me and I’ll add you to the credits (that will exist in the RTM version).

Well I just got around to installing it – it works flawlessly on my IBM R51 type 1830 from circa 2003. So you don’t need a brand new laptop… I think the R51 was the first one in the R series to have the HD Active Protection sensor so I got lucky 😀

Hey man software looks great. Having the same problem about the sensor.dll though. Its also on a toshiba. Interested in playing with the icon as well. Glad we have some innovative people out there in open source!

If those having problems with Sensor.dll can tell me what driver their laptop uses for APM (active protection managment) that’d be super. I think I can track down APIs for other drivers online. …I’m also trying to findout what Microsoft’s recommendation is on supporting accelerators.

It looks like a USB Accelerometer can be made for less then $10. I’m considering turning my little siblings into a soldering assembly line and slinging little USB devices with an Accelerometer and BedTime pre-loaded. …Then you’d just have to plug it in and it’d work (no visible software install required).

I think my participation in this is going the same path as Chris’, my Dell Precision M65 doesn’t seem to have a sensor.dll and I can’t find any specs that tell me whether I’ve got an accelerometer or not. 😦
I’m still in for testing it in combination with custom built hardware, though, if that should happen.
Cheers, MT

haha, to be honest, i’ve actually got 5 extras, which cost a total of about $100 off ebay. Some are a few years old now so they’re down to about 1.5hrs of usage. The common form factor for the M7s battery is likely the only reason I was able to find them so cheap, however.

Gavin,
I’ve just come across them sporadically, but my latest two were “off the beaten trail” so to speak as they’re Canadian and thus bare the Canadian product number (-4BAS instead of -4BRS). The others were just a mixture of luck and good timing I think…

Similarly, Dell’s StrikeZone technology, available on select models from its Latitude and Precision lines, uses specialized damping materials to cushion notebook hard drives and make them more durable.

Lenovo and Toshiba take a more active approach to this problem, utilizing motion sensors to detect impacts and sudden motions. When detected, hard drives are temporarily parked to protect the head and platter in a fall.

Lenovo offers this feature, called the Active Protection System, on select ThinkPad models. Toshiba’s version, dubbed HDD Protection, is available on a number of Toshiba’s Portege and Tecra laptops.

Kudos on a neat app. I hacked up a version that works on an OQO 02. The source is at http://www.math.uaa.alaska.edu/~afkjm/files/ if you’re interested. It won’t run without an OQO 02 but if you care to access the accelerometer part all you need is the DLL and one look at the APS.cs class reveals everything. I’d love to see OQO 02 support integrated into your official app and would be glad to help.

The source code that I downloaded didn’t seem to have anything to detect user activity? It looked like it was always “Yes”, or maybe I’m missing something? I put in some code to detect idle time (mouse/keyboard) and threw that in there too.

I’m gettin the ‘sensor.dll failed’ too. I’ve got a brand new Fujitsu-Simens Amilo Pro V3515. I’ve tried to find what kind of APM driver it got (if it got one), but no luck. I love this little app, even though I’ve never tried it 🙂 Please help…

Hi!
I really like your program and would like to participate in a beta test if possible. The only problem: I have an ASUS R1F and don’t know whether it has an accelerometer or not. Any possibility to find out?

Hopefully you will publish the program for free 😉 Or maybe ad driven?
Andreas

hay man that sounds really really great, please i would love to be a beta tester, i have just ordered a Dell laptop which im fairly sure that has an accelerometer, anyway do you use vb.net? if so how did you acces the accelerometer?
anyway thankx bro, this is my Emailahut10@exemail.com.au

Maybe for the people without accelerometers, you could allow it to read USB GPS devices. They can get pretty accurate as far as being able to tell if you have moved only a few feet or if you move to a higher elevation.

If you want to test with GPS at all, I have a Win XP, Win 2000 and a Mac OSX 10.3.

I have a HP nc6400 with “HP 3D Protection module” it uses Accelerometer.dll. Ive tried replacing “sensor.dll” with “Accelerometerdll.DLL” in the DLLImport statement in APS.cs but i cannot find the correct method call. I get the error “Unable to find an entry point named ‘ShockproofGetAccelerometerData’ in DLL ‘accelerometerdll.DLL’.” When I examine the dll in DLL Export Viewer i found a function called ?GetRealTimeXYZ@@YGKPAXPAGPAU_OVERLAPPED@@@Z which should be the one i need but i cannot figure out how to call it in APS.cs. Any help would be great thanks.

I also have a HP laptop, a NW8440 to be exact. I’m getting the same error as gluk, as I expected because the HP system has a driver named accelerometerdll.dll instead of the sensor.dll that the program calls.

While Bedtime looks really handy, I’m really hoping to find a way to map accelerometer data to key combinations. Maybe anyone has some ideas?

I have a Dell Inspiron 1525, and I too get the sensor.dll error. I did some digging about the hard drive in my laptop, and I found this info:

WD’s ShockGuard™ technology protects the drive mechanics and platter surfaces from shocks. WD’s SecurePark™ parks the recording heads off the disk surface during spin up, spin down, and when the drive is off.

That’s all I could find so far, and I cannot find either “accelerometer.dll” nor “sensor.dll” on my system.

I have an HP TM2 and I also get the same error as gluk. The EntryPoint of the Accelerometerdll.DLL should be the one Ben already mentioned: ?GetRealTimeXYZ@@YGKPAXPAGPAU_OVERLAPPED@@@Z but i really don’t know how to access this funktion.

Apple now has Rhapsody as an app, which is a great start, but it is currently hampered by the inability to store locally on your iPod, and has a dismal 64kbps bit rate. If this changes, then it will somewhat negate this advantage for the Zune, but the 10 songs per month will still be a big plus in Zune Pass’ favor. Webmaster of the php framework

how you dare! I mean, the only thing you had to do was set sleep when the screen was closed; neither was necesary any script, only change a couple of settings on vista. Poor HDD, poor nature, all taht energy wasted.

lol, you missed the point. My app used the accelerometer to detect movement. It triggered sleep when the laptop was not MOVING and closed.

Like many other people, I close my laptop while moving from my desk to our meeting area. I do this a few times a week, some people do it A LOT more often. Closing our lids triggers sleep (if we flip that setting you mention) which means we have to TURN ON our laptops and wait for resume during the meeting. Of course, if we disable sleep when the lid closes we run the risk of forgetting and putting the laptop in the bag while it’s on (which can cause system failure if things get hot enough).

Bottom line, with this app your laptop won’t end up overheating in the bag and it won’t go to sleep when you don’t want it to.