Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 729 → Rev 730

/Transportables_Koptertool/trunk/menu.c
0,0 → 1,265
/*****************************************************************************
* Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*****************************************************************************/
 
#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
 
#include "main.h"
#include "lcd.h"
#include "parameter.h"
#include "menu.h"
#include "display.h"
#include "motortest.h"
#include "debug.h"
#include "settings.h"
#include "timer.h"
#include "osd.h"
#include "jeti.h"
#include "servo.h"
#include "lipo.h"
#include "status.h"
 
 
void utils (void);
void sett (void);
 
 
//*****************************************************************************
// Main Menu
const char mm_item_0[] PROGMEM = "Navi Data";
const char mm_item_1[] PROGMEM = "Display";
const char mm_item_2[] PROGMEM = "Parameters";
const char mm_item_3[] PROGMEM = "Debug Data";
#ifndef USE_MMT
const char mm_item_4[] PROGMEM = "Jeti";
#endif
const char mm_item_5[] PROGMEM = "Utilities...";
 
const struct menu menu_main[] PROGMEM = {
{mm_item_0, osd},
{mm_item_1, display_data},
{mm_item_2, edit_parameter},
{mm_item_3, display_debug},
#ifndef USE_MMT
{mm_item_4, jeti},
#endif
{mm_item_5, utils}, // sub menu
};
#define N_MAIN (sizeof menu_main / sizeof menu_main[0])
 
 
//*****************************************************************************
// Utilities Menu
const char mu_item_0[] PROGMEM = "Motor Test";
const char mu_item_1[] PROGMEM = "I2C Motor Test";
#ifndef USE_MMT
const char mu_item_2[] PROGMEM = "Servo Tester";
const char mu_item_3[] PROGMEM = "LiPo Status";
#endif
const char mu_item_4[] PROGMEM = "Status";
const char mu_item_5[] PROGMEM = "Settings...";
 
const struct menu menu_util[] PROGMEM = {
{mu_item_0, motor_test},
{mu_item_1, motor_i2c},
#ifndef USE_MMT
{mu_item_2, servo_test},
{mu_item_3, lipo},
#endif
{mu_item_4, status},
{mu_item_5, sett}, // sub menu
};
#define N_UTIL (sizeof menu_util / sizeof menu_util[0])
 
 
//*****************************************************************************
// Settings Menu
const char ms_item_0[] PROGMEM = "Orientation";
#ifndef USE_MMT
const char ms_item_1[] PROGMEM = "LiPo Warn";
#endif
const char ms_item_2[] PROGMEM = "View Font";
const char ms_item_3[] PROGMEM = "Line";
const char ms_item_4[] PROGMEM = "Rectangle";
 
const struct menu menu_set[] PROGMEM = {
{ms_item_0, set_toggledisplay},
#ifndef USE_MMT
{ms_item_1, set_lipo},
#endif
{ms_item_2, set_viewfont},
{ms_item_3, set_line},
{ms_item_4, set_rect},
};
#define N_SET (sizeof menu_set / sizeof menu_set[0])
 
#if 0
const struct menus PROGMEM = {
{menu_main, N_MAIN, title_main},
{menu_util, N_UTIL, title_util},
{menu_set, N_SET, title_set},
};
#endif
 
 
//*****************************************************************************
//
void menu_print (const struct menu m[], uint8_t size)
{
uint8_t i;
for (i = MENU_LINE; i < MENU_LINE + size; i++)
{
lcd_printp_at (MENU_COL, i, (const char *) pgm_read_word(&(m[i - MENU_LINE].str)), 0);
}
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b Back \x0c"), 0);
}
 
 
//*****************************************************************************
//
void utils (void)
{
static uint8_t f = MENU_LINE;
do
{
lcd_cls ();
lcd_printp (PSTR("Utilities:"), 0);
menu_print(menu_util, N_UTIL);
f = menu_choose (MENU_LINE, N_UTIL, CURSOR_COL, f);
if (f != 255)
{
((pfunc)(pgm_read_word (&(menu_util[f - MENU_LINE].func))))();
}
}
while (f != 255);
f = MENU_LINE;
}
 
 
//*****************************************************************************
//
void sett (void)
{
static uint8_t f = MENU_LINE;
 
do
{
lcd_cls ();
lcd_printp (PSTR("Settings:"), 0);
menu_print(menu_set, N_SET);
f = menu_choose (MENU_LINE, N_SET, CURSOR_COL, f);
if (f != 255)
{
((pfunc)(pgm_read_word (&(menu_set[f - MENU_LINE].func))))();
}
}
while (f != 255);
f = MENU_LINE;
}
 
 
//*****************************************************************************
// print cursor
void menu_set_cursor (uint8_t before, uint8_t line, uint8_t pos)
{
lcd_printp_at (pos, before, PSTR(" "), 0);
lcd_printp_at (pos, line, PSTR("\x1D"), 0);
}
 
 
//*****************************************************************************
//
uint8_t menu_choose (uint8_t min, uint8_t max, uint8_t pos, uint8_t start)
{
uint8_t line = start;
uint8_t before = start;
uint8_t k;
 
menu_set_cursor (line, line, pos);
do
{
if (get_key_press (1 << KEY_PLUS))
{
if (line < max)
{
line ++;
}
else
{
line = min;
}
}
 
if (get_key_press (1 << KEY_MINUS))
{
if (line > min)
{
line --;
}
else
{
line = max;
}
}
 
if (line != before)
{
menu_set_cursor (before, line, pos);
before = line;
}
}
while (!(k = get_key_press ((1 << KEY_ENTER) | (1 << KEY_ESC))));
if (k & (1 << KEY_ESC))
{
line = 255;
}
 
return line;
}
 
 
//*****************************************************************************
//
void main_menu (void)
{
static uint8_t f = MENU_LINE;
lcd_cls ();
//lcd_printp (PSTR("Portable Kopter Tool"), 0);
lcd_printp (PSTR("MK Multi Box"), 0);
menu_print(menu_main, N_MAIN);
 
f = menu_choose (MENU_LINE, N_MAIN, CURSOR_COL, f);
if (f != 255)
{
((pfunc)(pgm_read_word (&(menu_main[f - MENU_LINE].func))))();
}
else
{
f = MENU_LINE;
}
}