1 /**
2  * \file
3  *
4  * \brief Simple menu system
5  *
6  * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  *
22  * 3. The name of Atmel may not be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * 4. This software may only be redistributed and used in connection with an
26  *    Atmel microcontroller product.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  * \asf_license_stop
41  *
42  */
43 /*
44  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45  */
46 #ifndef GFX_MONO_MENU_H
47 #define GFX_MONO_MENU_H
48 
49 #include "compiler.h"
50 #include "conf_menu.h"
51 #include "gfx_mono.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /**
58  * \ingroup asfdoc_common2_gfx_mono
59  * \defgroup asfdoc_common2_gfx_mono_menu Menu system for monochrome graphical displays
60  *
61  * This module provides a simple menu system for monochrome graphical
62  * displays.
63  *
64  * Typical flow of an application using the menu system:
65  *
66  * 1) Define menu structure.\n
67  * 2) Call asfdoc_common2_gfx_mono_menu_init.\n
68  * 3) Get user input.\n
69  * 4) Update menu with user input using function \ref
70  *    gfx_mono_menu_process_key.\n
71  * 5) Interpret \ref gfx_mono_menu_process_key return value.\n
72  * 6) Go to 3.\n
73  *
74  * The menu is declared using the \ref gfx_mono_menu struct.
75  *
76  * To start the menu system, call the \ref gfx_mono_menu_init function.
77  * This function will clear the display and draw the menu.
78  *
79  * Before the menu can be updated, you need input from the user. Methods for
80  * getting input is not part of the menu module.
81  *
82  * As soon as input is received, inform the menu system using the
83  * \ref gfx_mono_menu_process_key function.
84  * This function will then return a status code and act depending on the given
85  * keycode:
86  *
87  * MENU_KEYCODE_DOWN : Change selection to next menu item (or first if at
88  * bottom).
89  * Returns MENU_EVENT_IDLE.
90  *
91  * MENU_KEYCODE_UP : Change selection to previous menu item (or last if at top).
92  * Returns MENU_EVENT_IDLE.
93  *
94  * MENU_KEYCODE_ENTER : Nothing changes in menu. Returns the line selected.
95  *
96  * MENU_KEYCODE_BACK : Nothing changes in menu. Returns MENU_EVENT_EXIT.
97  *
98  * The value of the keycodes used are defined in conf_menu.h. These value can
99  * be changed if needed.
100  *
101  * The graphical indicator used to indicate menu selection is defined in
102  * conf_menu.h. This indicator can be changed if needed.
103  * @{
104  */
105 
106 /** \name Menu events definitions */
107 /** @{ */
108 /** Idle. Nothing to report. */
109 #define GFX_MONO_MENU_EVENT_IDLE    0xFF
110 /** Exit. User has pressed the back button. */
111 #define GFX_MONO_MENU_EVENT_EXIT    0xFE
112 /** @} */
113 
114 /** Maximum number of menu elements on display */
115 #define GFX_MONO_MENU_ELEMENTS_PER_SCREEN ((GFX_MONO_LCD_HEIGHT / \
116 	SYSFONT_LINESPACING) - 1)
117 
118 /** Menu struct */
119 struct gfx_mono_menu {
120 	PROGMEM_STRING_T title;
121 	PROGMEM_STRING_T *strings;
122 	uint8_t num_elements;
123 	uint8_t current_selection;
124 	uint8_t current_page;
125 };
126 
127 void gfx_mono_menu_init(struct gfx_mono_menu *menu);
128 uint8_t gfx_mono_menu_process_key(struct gfx_mono_menu *menu, uint8_t keycode);
129 
130 /** @} */
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* GFX_MONO_MENU_H */
137