Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
730 | woggle | 1 | /***************************************************************************** |
2 | * Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net * |
||
3 | * * |
||
4 | * This program is free software; you can redistribute it and/or modify * |
||
5 | * it under the terms of the GNU General Public License as published by * |
||
6 | * the Free Software Foundation; either version 2 of the License. * |
||
7 | * * |
||
8 | * This program is distributed in the hope that it will be useful, * |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
11 | * GNU General Public License for more details. * |
||
12 | * * |
||
13 | * You should have received a copy of the GNU General Public License * |
||
14 | * along with this program; if not, write to the * |
||
15 | * Free Software Foundation, Inc., * |
||
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
17 | * * |
||
18 | *****************************************************************************/ |
||
19 | |||
20 | #include <avr/io.h> |
||
21 | #include <inttypes.h> |
||
22 | #include <stdlib.h> |
||
23 | #include <avr/pgmspace.h> |
||
24 | |||
25 | #include "main.h" |
||
26 | #include "lcd.h" |
||
27 | #include "parameter.h" |
||
28 | #include "menu.h" |
||
29 | #include "display.h" |
||
30 | #include "motortest.h" |
||
31 | #include "debug.h" |
||
32 | #include "settings.h" |
||
33 | #include "timer.h" |
||
34 | #include "osd.h" |
||
35 | #include "jeti.h" |
||
36 | #include "servo.h" |
||
37 | #include "lipo.h" |
||
38 | #include "status.h" |
||
39 | |||
40 | |||
41 | void utils (void); |
||
42 | void sett (void); |
||
43 | |||
44 | |||
45 | //***************************************************************************** |
||
46 | // Main Menu |
||
47 | const char mm_item_0[] PROGMEM = "Navi Data"; |
||
48 | const char mm_item_1[] PROGMEM = "Display"; |
||
49 | const char mm_item_2[] PROGMEM = "Parameters"; |
||
50 | const char mm_item_3[] PROGMEM = "Debug Data"; |
||
51 | #ifndef USE_MMT |
||
52 | const char mm_item_4[] PROGMEM = "Jeti"; |
||
53 | #endif |
||
54 | const char mm_item_5[] PROGMEM = "Utilities..."; |
||
55 | |||
56 | const struct menu menu_main[] PROGMEM = { |
||
57 | {mm_item_0, osd}, |
||
58 | {mm_item_1, display_data}, |
||
59 | {mm_item_2, edit_parameter}, |
||
60 | {mm_item_3, display_debug}, |
||
61 | #ifndef USE_MMT |
||
62 | {mm_item_4, jeti}, |
||
63 | #endif |
||
64 | {mm_item_5, utils}, // sub menu |
||
65 | }; |
||
66 | #define N_MAIN (sizeof menu_main / sizeof menu_main[0]) |
||
67 | |||
68 | |||
69 | //***************************************************************************** |
||
70 | // Utilities Menu |
||
71 | const char mu_item_0[] PROGMEM = "Motor Test"; |
||
72 | const char mu_item_1[] PROGMEM = "I2C Motor Test"; |
||
73 | #ifndef USE_MMT |
||
74 | const char mu_item_2[] PROGMEM = "Servo Tester"; |
||
75 | const char mu_item_3[] PROGMEM = "LiPo Status"; |
||
76 | #endif |
||
77 | const char mu_item_4[] PROGMEM = "Status"; |
||
78 | const char mu_item_5[] PROGMEM = "Settings..."; |
||
79 | |||
80 | const struct menu menu_util[] PROGMEM = { |
||
81 | {mu_item_0, motor_test}, |
||
82 | {mu_item_1, motor_i2c}, |
||
83 | #ifndef USE_MMT |
||
84 | {mu_item_2, servo_test}, |
||
85 | {mu_item_3, lipo}, |
||
86 | #endif |
||
87 | {mu_item_4, status}, |
||
88 | {mu_item_5, sett}, // sub menu |
||
89 | }; |
||
90 | #define N_UTIL (sizeof menu_util / sizeof menu_util[0]) |
||
91 | |||
92 | |||
93 | //***************************************************************************** |
||
94 | // Settings Menu |
||
95 | const char ms_item_0[] PROGMEM = "Orientation"; |
||
96 | #ifndef USE_MMT |
||
97 | const char ms_item_1[] PROGMEM = "LiPo Warn"; |
||
98 | #endif |
||
99 | const char ms_item_2[] PROGMEM = "View Font"; |
||
100 | const char ms_item_3[] PROGMEM = "Line"; |
||
101 | const char ms_item_4[] PROGMEM = "Rectangle"; |
||
102 | |||
103 | const struct menu menu_set[] PROGMEM = { |
||
104 | {ms_item_0, set_toggledisplay}, |
||
105 | #ifndef USE_MMT |
||
106 | {ms_item_1, set_lipo}, |
||
107 | #endif |
||
108 | {ms_item_2, set_viewfont}, |
||
109 | {ms_item_3, set_line}, |
||
110 | {ms_item_4, set_rect}, |
||
111 | }; |
||
112 | #define N_SET (sizeof menu_set / sizeof menu_set[0]) |
||
113 | |||
114 | #if 0 |
||
115 | const struct menus PROGMEM = { |
||
116 | {menu_main, N_MAIN, title_main}, |
||
117 | {menu_util, N_UTIL, title_util}, |
||
118 | {menu_set, N_SET, title_set}, |
||
119 | }; |
||
120 | #endif |
||
121 | |||
122 | |||
123 | //***************************************************************************** |
||
124 | // |
||
125 | void menu_print (const struct menu m[], uint8_t size) |
||
126 | { |
||
127 | uint8_t i; |
||
128 | |||
129 | for (i = MENU_LINE; i < MENU_LINE + size; i++) |
||
130 | { |
||
131 | lcd_printp_at (MENU_COL, i, (const char *) pgm_read_word(&(m[i - MENU_LINE].str)), 0); |
||
132 | } |
||
133 | lcd_printpns_at (0, 7, PSTR(" \x1a \x1b Back \x0c"), 0); |
||
134 | } |
||
135 | |||
136 | |||
137 | //***************************************************************************** |
||
138 | // |
||
139 | void utils (void) |
||
140 | { |
||
141 | static uint8_t f = MENU_LINE; |
||
142 | |||
143 | do |
||
144 | { |
||
145 | lcd_cls (); |
||
146 | lcd_printp (PSTR("Utilities:"), 0); |
||
147 | menu_print(menu_util, N_UTIL); |
||
148 | |||
149 | f = menu_choose (MENU_LINE, N_UTIL, CURSOR_COL, f); |
||
150 | if (f != 255) |
||
151 | { |
||
152 | ((pfunc)(pgm_read_word (&(menu_util[f - MENU_LINE].func))))(); |
||
153 | } |
||
154 | } |
||
155 | while (f != 255); |
||
156 | f = MENU_LINE; |
||
157 | } |
||
158 | |||
159 | |||
160 | //***************************************************************************** |
||
161 | // |
||
162 | void sett (void) |
||
163 | { |
||
164 | static uint8_t f = MENU_LINE; |
||
165 | |||
166 | do |
||
167 | { |
||
168 | lcd_cls (); |
||
169 | lcd_printp (PSTR("Settings:"), 0); |
||
170 | menu_print(menu_set, N_SET); |
||
171 | |||
172 | f = menu_choose (MENU_LINE, N_SET, CURSOR_COL, f); |
||
173 | if (f != 255) |
||
174 | { |
||
175 | ((pfunc)(pgm_read_word (&(menu_set[f - MENU_LINE].func))))(); |
||
176 | } |
||
177 | } |
||
178 | while (f != 255); |
||
179 | f = MENU_LINE; |
||
180 | } |
||
181 | |||
182 | |||
183 | //***************************************************************************** |
||
184 | // print cursor |
||
185 | void menu_set_cursor (uint8_t before, uint8_t line, uint8_t pos) |
||
186 | { |
||
187 | lcd_printp_at (pos, before, PSTR(" "), 0); |
||
188 | lcd_printp_at (pos, line, PSTR("\x1D"), 0); |
||
189 | } |
||
190 | |||
191 | |||
192 | //***************************************************************************** |
||
193 | // |
||
194 | uint8_t menu_choose (uint8_t min, uint8_t max, uint8_t pos, uint8_t start) |
||
195 | { |
||
196 | uint8_t line = start; |
||
197 | uint8_t before = start; |
||
198 | |||
199 | uint8_t k; |
||
200 | |||
201 | menu_set_cursor (line, line, pos); |
||
202 | |||
203 | do |
||
204 | { |
||
205 | if (get_key_press (1 << KEY_PLUS)) |
||
206 | { |
||
207 | if (line < max) |
||
208 | { |
||
209 | line ++; |
||
210 | } |
||
211 | else |
||
212 | { |
||
213 | line = min; |
||
214 | } |
||
215 | } |
||
216 | |||
217 | if (get_key_press (1 << KEY_MINUS)) |
||
218 | { |
||
219 | if (line > min) |
||
220 | { |
||
221 | line --; |
||
222 | } |
||
223 | else |
||
224 | { |
||
225 | line = max; |
||
226 | } |
||
227 | } |
||
228 | |||
229 | if (line != before) |
||
230 | { |
||
231 | menu_set_cursor (before, line, pos); |
||
232 | before = line; |
||
233 | } |
||
234 | } |
||
235 | while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC)))); |
||
236 | if (k & (1 << KEY_ESC)) |
||
237 | { |
||
238 | line = 255; |
||
239 | } |
||
240 | |||
241 | return line; |
||
242 | } |
||
243 | |||
244 | |||
245 | //***************************************************************************** |
||
246 | // |
||
247 | void main_menu (void) |
||
248 | { |
||
249 | static uint8_t f = MENU_LINE; |
||
250 | |||
251 | lcd_cls (); |
||
252 | //lcd_printp (PSTR("Portable Kopter Tool"), 0); |
||
253 | lcd_printp (PSTR("MK Multi Box"), 0); |
||
254 | menu_print(menu_main, N_MAIN); |
||
255 | |||
256 | f = menu_choose (MENU_LINE, N_MAIN, CURSOR_COL, f); |
||
257 | if (f != 255) |
||
258 | { |
||
259 | ((pfunc)(pgm_read_word (&(menu_main[f - MENU_LINE].func))))(); |
||
260 | } |
||
261 | else |
||
262 | { |
||
263 | f = MENU_LINE; |
||
264 | } |
||
265 | } |