Subversion Repositories Projects

Rev

Rev 724 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
724 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
const char mm_item_4[] PROGMEM = "Jeti";
52
const char mm_item_5[] PROGMEM = "Utilities...";
53
 
54
const struct menu menu_main[] PROGMEM = {
55
        {mm_item_0, osd},
56
        {mm_item_1, display_data},
57
        {mm_item_2, edit_parameter},
58
        {mm_item_3, display_debug},
59
        {mm_item_4, jeti},
60
        {mm_item_5, utils},     // sub menu
61
};
62
#define N_MAIN (sizeof menu_main / sizeof menu_main[0])
63
 
64
 
65
//*****************************************************************************
66
// Utilities Menu
67
const char mu_item_0[] PROGMEM = "Motor Test";
68
const char mu_item_1[] PROGMEM = "I2C Motor Test";
69
const char mu_item_2[] PROGMEM = "Servo Tester";
70
const char mu_item_3[] PROGMEM = "LiPo Status";
71
const char mu_item_4[] PROGMEM = "Status";
72
const char mu_item_5[] PROGMEM = "Settings...";
73
 
74
const struct menu menu_util[] PROGMEM = {
75
        {mu_item_0, motor_test},
76
        {mu_item_1, motor_i2c},
77
        {mu_item_2, servo_test},
78
        {mu_item_3, lipo},
79
        {mu_item_4, status},
80
        {mu_item_5, sett},      // sub menu
81
};
82
#define N_UTIL (sizeof menu_util / sizeof menu_util[0])
83
 
84
 
85
//*****************************************************************************
86
// Settings Menu
87
const char ms_item_0[] PROGMEM = "Orientation";
88
const char ms_item_1[] PROGMEM = "LiPo Warn";
89
const char ms_item_2[] PROGMEM = "View Font";
90
const char ms_item_3[] PROGMEM = "Line";
91
const char ms_item_4[] PROGMEM = "Rectangle";
92
 
93
const struct menu menu_set[] PROGMEM = {
94
        {ms_item_0, set_toggledisplay},
95
        {ms_item_1, set_lipo},
96
        {ms_item_2, set_viewfont},
97
        {ms_item_3, set_line},
98
        {ms_item_4, set_rect},
99
};
100
#define N_SET (sizeof menu_set / sizeof menu_set[0])
101
 
102
#if 0
103
const struct menus PROGMEM = {
104
        {menu_main, N_MAIN, title_main},
105
        {menu_util, N_UTIL, title_util},
106
        {menu_set,  N_SET,  title_set},
107
};
108
#endif
109
 
110
 
111
//*****************************************************************************
112
// 
113
void menu_print (const struct menu m[], uint8_t size)
114
{
115
        uint8_t i;
116
 
117
        for (i = MENU_LINE; i < MENU_LINE + size; i++)
118
        {
119
                lcd_printp_at (MENU_COL, i, (const char *) pgm_read_word(&(m[i - MENU_LINE].str)), 0);
120
        }
121
        lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b     Back   \x0c"), 0);
122
}
123
 
124
 
125
//*****************************************************************************
126
// 
127
void utils (void)
128
{
129
        static uint8_t f = MENU_LINE;
130
 
131
        do
132
        {
133
                lcd_cls ();
134
                lcd_printp (PSTR("Utilities:"), 0);
135
                menu_print(menu_util, N_UTIL);
136
 
137
                f = menu_choose (MENU_LINE, N_UTIL, CURSOR_COL, f);
138
                if (f != 255)
139
                {
140
                        ((pfunc)(pgm_read_word (&(menu_util[f - MENU_LINE].func))))();
141
                }
142
        }
143
        while (f != 255);
144
        f = MENU_LINE;
145
}
146
 
147
 
148
//*****************************************************************************
149
// 
150
void sett (void)
151
{
152
        static uint8_t f = MENU_LINE;
153
 
154
        do
155
        {
156
                lcd_cls ();
157
                lcd_printp (PSTR("Settings:"), 0);
158
                menu_print(menu_set, N_SET);
159
 
160
                f = menu_choose (MENU_LINE, N_SET, CURSOR_COL, f);
161
                if (f != 255)
162
                {
163
                        ((pfunc)(pgm_read_word (&(menu_set[f - MENU_LINE].func))))();
164
                }
165
        }
166
        while (f != 255);
167
        f = MENU_LINE;
168
}
169
 
170
 
171
//*****************************************************************************
172
// print cursor
173
void menu_set_cursor (uint8_t before, uint8_t line, uint8_t pos)
174
{
175
        lcd_printp_at (pos, before, PSTR(" "), 0);
176
        lcd_printp_at (pos, line, PSTR("\x1D"), 0);
177
}
178
 
179
 
180
//*****************************************************************************
181
// 
182
uint8_t menu_choose (uint8_t min, uint8_t max, uint8_t pos, uint8_t start)
183
{
184
        uint8_t line = start;
185
        uint8_t before = start;
186
 
187
        uint8_t k;
188
 
189
        menu_set_cursor (line, line, pos);
190
 
191
        do
192
        {
193
                if (get_key_press (1 << KEY_PLUS))
194
                {
195
                        if (line < max)
196
                        {
197
                                line ++;
198
                        }
199
                        else
200
                        {
201
                                line = min;
202
                        }
203
                }
204
 
205
                if (get_key_press (1 << KEY_MINUS))
206
                {
207
                        if (line > min)
208
                        {
209
                                line --;
210
                        }
211
                        else
212
                        {
213
                                line = max;
214
                        }
215
                }
216
 
217
                if (line != before)
218
                {
219
                        menu_set_cursor (before, line, pos);
220
                        before = line;
221
                }
222
        }
223
        while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC))));
224
        if (k & (1 << KEY_ESC))
225
        {
226
                line = 255;
227
        }
228
 
229
        return line;
230
}
231
 
232
 
233
//*****************************************************************************
234
// 
235
void main_menu (void)
236
{
237
        static uint8_t f = MENU_LINE;
238
 
239
        lcd_cls ();
240
        //lcd_printp (PSTR("Portable Kopter Tool"), 0);
241
        lcd_printp (PSTR("MK Multi Box"), 0);
242
        menu_print(menu_main, N_MAIN);
243
 
244
        f = menu_choose (MENU_LINE, N_MAIN, CURSOR_COL, f);
245
        if (f != 255)
246
        {
247
                ((pfunc)(pgm_read_word (&(menu_main[f - MENU_LINE].func))))();
248
        }
249
        else
250
        {
251
                f = MENU_LINE;
252
        }
253
}