This morning my alarm clock didn't go off, and I didn't make it to work. That's gotta be fixed. Since this weekend I got a whizzy new MythTV setup around my house, that seems like the ideal thing to wake me up.
However, MythTV plugins are written in C++, and I don't do C++ because I'm a Python guy.
So, something of a hack. It is possible to add a menu item to MythTV which runs an external program. So, thought I, that'd be one way to do it, and indeed it works. You create a new "menu theme" which launches an external program by name. The
Myth menu theme development guide explains how. Then, write a small program to accept user input to set an alarm (I used pygame, which seems more in keeping with the MythTV approach than Gtk), and pow, Bob's your uncle.
Actually, I used pygame primarily because I needed the MythTV keys to navigate around the little alarm-setting program. I've got some weird keys bound to do navigation in MythTV (2, 4, 6, 8 for up, left, right, down) and I've got no idea how you can make the 6 key mean "go to the next field" like Tab does in a Gtk application. In pygame that's easy, so I did it that way; at some point in the future it should also allow me to theme the app so it looks like your MythTV theme, but I didn't get around to that.
The way it actually creates alarms is by putting them in your crontab, which is easy and satisfying and what cron is for.
Anyway, code in Subversion at
http://svn.kryogenix.org/svn/mythtv-alarm-clock/ if you want to have a play.
I suspect the MythTV people would be horrified by this approach. A few of them tried to convince me that I should learn C++ because it's not that hard...
I've had similar experiences with my scripted alarm clock not behaving and missing work. For a while I used a standard radio alarm clock as a backup. I much prefer the computer-based alarm clock because it can play music I actually want to listen to, so I can lie awake for long enough to properly wake up, instead of turning off the alarm straight away and never even remembering doing it.
Mine has nothing to do with MythTV, but for anyone that is interested, it works by:
- Checking that my music player is running and ready
- Creating an `at` job which will set the volumes, unmute if necessary and play the music. It then sets the volume louder over the next 20 seconds, just to make sure it doesn't start too loud.
- It then writes a timestamp to /sys/class/rtc/rtc0/wakealarm so that my PC wakes up from suspend one minute before the at job will start
The two bugs I found at different times were:
- The at 'time' and the date -d 'time' commands interpret the times differently, sometimes being 24 hours off from each other. Eg date -d '2am' will be 2am already passed today, not 2am in the future (as at would interpret it). I added a check to make sure date returns a time in the future.
- at will resume its syscall after resume for up to an hour, which can mean it misses the desired wake up time by a fair bit. I added a script to /etc/pm/sleep.d to SIGHUP atd after resume.