GUI Frameworks of all modern OS like Windows, Linux (Qt & GTK+), MAC etc have a concept of standard dialogs. For example all applications running under Windows shows the same file open dialog for selecting a file. Similarly their are standard dialogs for folder selection, colour selection, font selection etc. This concept has several advantages, and the most important is a easy user interface. Since the user is already familiar with file selection in one application, he/she can use file open dialog of any application. Building on the same concept our GUI framework for ProGFX (avr glcd driver) will too have many standard dialogs for common user interface. In this tutorial we will build the "Time Input Dialog" that helps programmer ask the user to input time. The time could be anything like :-
- "On" or "Off" time for a relay in a timer application.
- Alarm time in an alarm clock application.
- Period start time in a school bell application.
- And many others.
The programmer just need to call the function.
void ShowGetTimeDlg(uint8_t *h,uint8_t *m,uint8_t *s,uint8_t *am_pm)
It takes four parameters hour, minutes, second and am_pm. All parameters are passed by reference(pointer actually), this is because the function modifies the value of those variables. It shows a dialog as shown below :-
Time Input Dialog
The user can use the LEFT and RIGHT navigation keys on D-PAD to move from one field to another (like hour, minutes, seconds etc.). Then he/she can use the UP and DOWN key to increase/decrease the value of that field. Once the user has entered the time they can press OK to end the dialog. As soon as user presses OK button the values are copied to the variables h,m,s,am_pm. If the user presses CANCEL in place of OK the variables are not changed.
//Declare variables uint8_t h,m,s,am_pm; //Initialize variables h=10; m=10; s=20; am_pm=AM; //Show the time input dialog ShowGetTimeDlg(&h,&m,&s,&am_pm);
The above code will show the time input dialog with initial time of 10:10:20 AM if the user change time and press OK the variable h,m,s,am_pm will be changed accordingly. But if user presses cancel (even after modifying time) the variables (h,m,s,am_pm) will retain their original value i.e. 10:10:20 AM.
You can run the above code in our GLCD Development Board, otherwise you may build the circuit as shown below.
GLCD Development Board Schematic
- The Fuse Byte of ATmega32 must be set as follows. (LOW Fuse = 0xFF, HIGH Fuse = 0xC9).
- Adjust RV1 until you get a clear display.