Software design

Ofcourse, a nice PCB with a powerful processor and a nice display only is scrap without the software: especially in this case, it pretty much defines what the device does.

While developing the hardware, I already had made the decision to go with Linux and OpenWRT as an OS, as that's what runs on the Carambola by default. Using this combination also has the advantages that most of the libraries that can be used on OpenWRT also are available on my desktop machine. That makes it possible to make a version that runs there too, making it pretty easy to debug. Using an established OS also makes it easy to use open-source libraries, meaning you don't have to re-invent the wheel. In this case, I use libcairo for drawing the user interface, Mongoose as the integrated webserver and jansson as a JSON library, for the API and as storage. To play web streams, the Carambola also runs mpd, which is then remote-controlled using libmpdclient by the clock radio software. This way, a crashing mp3 decoder won't take down the complete software and stop me from waking up in the morning.

Ofcourse you may be wondering how it all works. Let me first show you the user interface on the clock radio itself:

Also, the clock has a web UI. It looks like this:

If you've watched the video, the alarm schedule may look a bit funny at first. The clock basically has a scheduled alarm time for each day of the week. It also has a so-called 'nxt' slot, which indicates the next time the alarm will go off, and the alarm type it will use. The trick is: Every day, after the alarm has sounded, the alarm for the next day is copied into the 'nxt' slot. Now, if you want to modify your alarm because either you have an unscheduled day off tomorrow, or just want to take a nap and want the clock radio to wake you up in 20 minutes, you can modify the 'nxt' alarm. That way, you don't need to mess with the scheduled alarm times and maybe forget to reset those.

The video also shows that an alarm can have three types, if it's not disabled. You can define what happens when a certain type of alarm is activated in the web interface. An alarm type consists of multiple events, that are triggered before or after a certain moment. To clarify, this is my alarm type for a day in which I don't have to work:

This alarm has four actions defined. The top one exchanges the standard FM reception for a Shoutcast station that plays chill trancy music, for waking up in a relaxed fashion. Now, every time I hit the snooze button, the second action will make sure the next snooze will be one minute shorter. That means if the default setting is 10 minutes, the second snooze will last 9 minutes, the third one 8 and so on.

I also have a light in my room that's remotely connected to my server. The third action will fetch an URL from that server that will trigger the light to turn on, in the same fashion a wake-up-light does. The fourth action will switch the light back off 10 minutes after the alarm is turned off.

Combined, the alarm schedule and the alarm types are pretty powerful: On a working day, when you have to get to work at a certain time, it can make sure you actually wake up by playing metal and refusing you a second snooze. On a sleepy sunday, you can wake up with relaxed music and snooze as long as you like.

Ofcourse, the clock radio also has an API: for example, a script running on my server can spot that I've gone downstairs without disabling the alarm and disable it for me. It might also check the train schedule and wake me up a bit later or earlier if my train has known delays.

« Prev 5 Next »

© 2006-2021 Sprite_tm - Contact