CURRENT ISSUE
Contests
FEATURE ARTICLE
|
|
Issue #216 July 2008
Second Place Microchip 2007 Design Contest
’Net-Enabled Alarm Clock
by DJ Delorie
Start | System Overview | Network | Display | MP3 | ADC | Memory | Power | Software | Time | Alarms | GUI | Remote Protocols | Construction & Packaging | Smart Combinations | Sources & PDF
GUI
The clock uses a simple GUI to manage the clock locally. This includes setting the alarms (and silencing them!), using the snooze and sleep features, and listening to music. Each time the ADC module determines that a button has been pressed, the GUI is called to handle that button.
The GUI uses a simple state machine to keep track of where it is, without having to stop the main loop. I use a feature of GCC where you can assign the address of a local label to a variable. There’s a GOTO(x) macro that stores the address of the given label into a static variable and then returns. The next time the GUI is called, it jumps to the given label to perform the next step. You can also use a standard goto if you need to jump to a common setup routine for a screen, which would use GOTO(x) to set up the next state.
As each screen is set up, icons are drawn next to each button so you know what they’re used for. Some buttons have common meanings, such as the upper-right button is always “off” or “cancel.” Others, such as the lower buttons, have different meanings for each screen, so the icons are needed. Depending on the screen, the GUI can tell the RTC module how (or if) the time (wall time or sleep time) is to be displayed on the screen. This way, the GUI can decide where to put it but let the RTC module maintain it.
When the ADC determines that no button has been pressed in a while, it pretends you pressed “timeout.” This gives the GUI an opportunity to time out and reset back to the main display.
Previous | Next *| Subscription Deals |*
|