Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1931 → Rev 1932

/Transportables_Koptertool/branch/PKT/branch/GPL_PKT_V3_6_7f_FC090b/menu.c
0,0 → 1,778
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* 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. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
//############################################################################
//# HISTORY menu.c
//#
//# 10.03.2013 Cebra
//# - add: menu_select, gemeinsame Routine für alle Setupmenüs
//############################################################################
 
#include "cpu.h"
#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <util/delay.h>
 
#include "main.h"
#include "lcd/lcd.h"
#include "parameter.h"
#include "menu.h"
#include "display.h"
#include "debug.h"
#include "timer/timer.h"
#include "osd/osd.h"
#include "motortest/motortest.h"
#include "gps/gps.h"
#include "eeprom/eeprom.h"
#include "setup/setup.h"
#include "uart/uart1.h"
#include "mk-data-structs.h"
#include "wi232/Wi232.h"
#include "tracking/servo.h"
#include "tools.h"
#include "connect.h"
#include "lipo/lipo.h"
#include "messages.h"
#include "bluetooth/bluetooth.h"
#include "followme/followme.h"
#include "tracking/ng_servo.h"
#include "tracking/tracking.h"
#include "stick/stick.h"
 
 
//// Variablen für die Menüsteuerung
uint8_t ii = 0;
uint8_t offset = 0;
uint8_t size = 0;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val;
 
 
 
 
 
#define ITEMS_NC 9
 
const prog_char param_menuitems_nc[ITEMS_NC][NUM_LANG][18]= // zeilen,zeichen+1
 
 
// German, English, French, Netherlands
{
{"OSD ","OSD ","OSD "},
{"MK Display ","MK Display ","MK Display "},
{"Tracking ","Tracking ","Tracking "},
{"Parameter \x1d","Parameter \x1d","Parameters \x1d"},
{"Debug Data ","Debug Data ","Debug Data "},
{"GPS Info ","GPS Info ","GPS Info "},
{"Follow Me ","Follow Me ","Follow Me "},
{"Joystick ","Joystick ","Joystick "},
{"PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d"},
};
 
 
#define ITEMS_FC 5
 
const prog_char param_menuitems_fc[ITEMS_FC][NUM_LANG][18]= // zeilen,zeichen+1
{
{"Joystick ","Joystick ","Joystick "}, // MartinR
{"MK Display ","MK Display ","MK Display "},
{"Parameter \x1d","Parameter \x1d","Parameter \x1d"},
{"Debug Data ","Debug Data ","Debug Data "},
{"PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d"},
};
 
 
#define ITEMS_NO 6
 
const prog_char param_menuitems_no[ITEMS_NO][NUM_LANG][18]= // zeilen,zeichen+1
{
 
 
{"Suche Mikrokopter","search Mikrokopt ","search Mikrokopt "},
{"BL-Ctrl. Tester ","BL-Ctrl. Tester ","BL-Ctrl. Tester "},
{"PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter "},
{"PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter "},
{"PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d"},
{"PKT Version ","PKT Version ","PKT Versie "},
};
 
 
#define ITEMS_CR 12
 
const prog_char param_copyright[ITEMS_CR][22]= // zeilen,zeichen+1
{
" ",
"(C) GNU GPL License ",
" NO WARRANTY ",
" ",
"2008 Thomas Kaiser ",
"2009-2010 Peter Mack ",
"2010 Sebastian Boehm ",
"2012 Chr. Brandtner &",
" Harald Bongartz ",
"2012 gebad ",
"2012 Martin Runkel ",
"2013 Oliver Gemesi "
};
 
uint8_t menu_select(const char menuitem[][NUM_LANG][18],uint8_t size, uint8_t targetpos)
{
 
ii = 0;
offset = 0;
dmode = 0;
uint8_t target_pos = targetpos;
target_pos = targetpos;
val = 0;
 
while(2)
{
ii = 0;
if(offset > 0)
{
lcd_printp_at(1,1, PSTR("\x12"), 0);
}
for(ii = 0;ii < 6 ; ii++)
{
if((ii+offset) < size)
{
lcd_printp_at(3,ii+1,menuitem[ii+offset][Config.DisplayLanguage], 0);
}
if((ii == 5)&&(ii+offset < (size-1)))
{
lcd_printp_at(1,6, PSTR("\x13"), 0);
}
}
if(dmode == 0)
{
if(offset == 0)
{
if(size > 6)
{
val = menu_choose2 (1, 5, target_pos,0,1);
}
else
{
val = menu_choose2 (1, size, target_pos,0,0);
}
}
else
{
val = menu_choose2 (2, 5, target_pos,1,1);
}
}
if(dmode == 1)
{
if(offset+7 > size)
{
val = menu_choose2 (2, 6, target_pos,1,0);
}
else
{
val = menu_choose2 (2, 5, target_pos,1,1);
}
}
if(val == 254)
{
offset++;
dmode = 1;
target_pos = 5;
}
else if(val == 253)
{
offset--;
dmode = 0;
target_pos = 2;
}
else if(val == 255)
{
break;
}
else
{
break;
}
 
}
 
 
return val;
 
}
 
//--------------------------------------------------------------
// 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);
}
 
 
// F�r Seting-Auswahl ------------------------------------------
//
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) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
{
if (line < max)
line ++;
else
line = max;
// line = min; // Wenn wiederholen soll
}
 
if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
{
if (line > min)
line --;
else
line = min;
// line = max; // Wenn wiederholen soll
}
 
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;
}
 
// F�r Setup und Parameter ------------------------------------------
//
uint8_t menu_choose2 (uint8_t min, uint8_t max, uint8_t start, uint8_t return_at_start, uint8_t return_at_end)
{
uint8_t pos = 1;
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) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
{
if (line < max)
line ++;
else
{
if(return_at_end == 1)
return 254;
else
line = max;
// line = min; // Wenn wiederholen soll
}
}
 
if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
{
if (line > min)
line --;
else
{
if(return_at_start == 1)
return 253;
else
line = min;
// line = max; // Wenn wiederholen soll
}
}
 
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;
}
 
// F�r das Hauptmenue ------------------------------------------
//
uint8_t menu_choose3 (uint8_t min, uint8_t max,uint8_t start, uint8_t return_at_start, uint8_t return_at_end)
{
uint8_t pos = 1;
uint8_t line = start;
uint8_t before = start;
 
menu_set_cursor (line, line, pos);
 
do
{
 
if (get_key_press (1 << KEY_PLUS) | get_key_long_rpt_sp ((1 << KEY_PLUS), 1))
{
if (line < max)
line ++;
else
{
if(return_at_end == 1)
return 254;
else
line = max;
// line = min; // Wenn wiederholen soll
}
}
 
if (get_key_press (1 << KEY_MINUS) | get_key_long_rpt_sp ((1 << KEY_MINUS), 1))
{
if (line > min)
line --;
else
{
if(return_at_start == 1)
return 253;
else
line = min;
// line = max; // Wenn wiederholen soll
}
}
 
if (get_key_long (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
return 250;
}
 
if(get_key_long (1 << KEY_ENTER))
{
get_key_press(KEY_ALL);
return 251;
}
 
if (get_key_short (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
return 252;
}
 
if (line != before)
{
menu_set_cursor (before, line, pos);
before = line;
}
#ifdef HWVERSION3_9
show_Lipo();
#endif
}
while (!(get_key_short (1 << KEY_ENTER)));
 
return line;
}
 
//--------------------------------------------------------------
//
void main_menu (void)
{
uint8_t ii = 0;
uint8_t offset = 0;
uint8_t size = 0;
uint8_t Save_hardware = 0;
uint8_t dmode = 0;
uint8_t target_pos = 1;
uint8_t val =0;
 
Save_hardware = hardware;
 
get_key_press(KEY_ALL);
 
while(1)
{
if (Config.Debug==1)
hardware = NC;
if (Config.Debug==0)
hardware = Save_hardware;
if(hardware == NO)
size = ITEMS_NO ;
if(hardware == NC)
size = ITEMS_NC ;
if(hardware == FC)
size = ITEMS_FC ;
 
lcd_cls ();
lcd_printp_at (0, 0, PSTR("PKT-Tool FC "), 2);
lcd_printp_at (12, 0, PSTR(FC_Version), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
lcd_puts_at(12, 7, strGet(OFF), 0);
 
 
while(2)
{
 
ii = 0;
if(offset > 0)
lcd_printp_at(1,1, PSTR("\x12"), 0);
 
for(ii = 0;ii < 6 ; ii++)
{
if((ii+offset) < size)
{
if(hardware == NC)
lcd_printp_at(3,ii+1,param_menuitems_nc[ii+offset][Config.DisplayLanguage], 0);
else if(hardware == FC)
lcd_printp_at(3,ii+1,param_menuitems_fc[ii+offset][Config.DisplayLanguage], 0);
else
lcd_printp_at(3,ii+1,param_menuitems_no[ii+offset][Config.DisplayLanguage], 0);
}
 
if((ii == 5)&&(ii+offset < (size-1)))
lcd_printp_at(1,6, PSTR("\x13"), 0);
 
show_Lipo();
 
}
 
if(dmode == 0)
{
if(offset == 0)
{
if(size > 6)
val = menu_choose3 (1, 5, target_pos,0,1); //menu_choose3 (min, max, start, return_at_start, return_at_end)
else
val = menu_choose3 (1, size, target_pos,0,0);
}
else
val = menu_choose3 (2, 5, target_pos,1,1);
}
 
if(dmode == 1)
{
if(offset+7 > size)
val = menu_choose3 (2, 6, target_pos,1,0);
else
val = menu_choose3 (2, 5, target_pos,1,1);
}
 
if(val == 254)
{
offset++;
dmode = 1;
target_pos = 5;
}
else if(val == 253)
{
offset--;
dmode = 0;
target_pos = 2;
}
 
else if(val == 252)
{
 
lcd_cls();
// lcd_printp_at (0, 2, PSTR(" PKT ausschalten?"),0);
lcd_puts_at(0, 2, strGet(SHUTDOWN), 0);
// lcd_printp_at (12, 7, PSTR("Nein Ja"),0);
lcd_puts_at(12, 7, strGet(YESNO), 0);
while(1)
{
if (get_key_press (1 << KEY_ENTER))
{
WriteParameter(); // am Ende alle Parameter sichern
clr_V_On(); // Spannung abschalten
}
 
if (get_key_short (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
lcd_cls();
lcd_printp_at (0, 0, PSTR("PKT-Tool FC "), 2);
lcd_printp_at (12, 0,PSTR(FC_Version), 2);
// show_Lipo();
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
// lcd_printp_at (12, 7, PSTR("Aus "), 0);
lcd_puts_at(12, 7, strGet(OFF), 0);
break;
}
}
}
else if(val == 251)
{
PC_Fast_Connect();
return;
}
 
else if(val == 250)
{
// Test_HB();
// Test_Language();
return;
}
else
break;
}
 
target_pos = val;
 
 
if(hardware == NC)
{
if((val+offset) == 1 )
osd(OSD_Mode);
if((val+offset) == 2 )
display_data();
if((val+offset) == 3 )
PKT_tracking();
if((val+offset) == 4 )
edit_parameter();
#ifdef HWVERSION3_9
if((val+offset) == 5 )
 
#ifdef analognames
display_debug();
#else
{
copy_line(7);
lcd_printp_at (0, 7, PSTR(" not possible "),0);
_delay_ms(1000);
paste_line(7);
}
#endif
if((val+offset) == 6 )
gps();
#endif
 
if((val+offset) == 7 )
FollowMe();
 
if((val+offset) == 8 )
joystick();
if((val+offset) == 9 )
PKT_Tools();
 
}
 
 
if(hardware == FC)
{
if((val+offset) == 1 )
joystick();
if((val+offset) == 2 )
display_data();
if((val+offset) == 3 )
edit_parameter();
if((val+offset) == 4 )
#ifdef analognames
display_debug();
#else
{
copy_line(7);
lcd_printp_at (0, 7, PSTR(" not possible "),0);
_delay_ms(1000);
paste_line(7);
}
#endif
 
if((val+offset) == 4 )
PKT_Tools();
 
}
 
 
if(hardware == NO)
{
if((val+offset) == 1 )
if (searchMK()){
Save_hardware = hardware;
continue;
}
 
if((val+offset) == 2 )
motor_test(FC_Mode);
 
#ifdef HWVERSION3_9
if (Config.U02SV2 == 0)
{
if((val+offset) == 3 )
Port_BT2Wi();
if((val+offset) == 4 )
Port_USB2Wi();
}
else if (Config.U02SV2 == 1)
{
if((val+offset) == 3 )
Port_BT2FC();
if((val+offset) == 4 )
Port_USB2FC();
}
#else
if((val+offset) == 3 )
Show_Error_HW();
if((val+offset) == 4 )
Show_Error_HW();
#endif
if((val+offset) == 5 )
PKT_Setup();
if((val+offset) == 6 )
Show_Version();
 
}
 
 
}
}
 
 
//--------------------------------------------------------------
//
void Update_PKT (void)
{
lcd_cls();
lcd_printp_at (0, 0, PSTR(" PKT Update "),2);
lcd_puts_at(0, 1, strGet(UPDATE1), 0);
lcd_puts_at(0, 2, strGet(UPDATE2), 0);
lcd_printp_at (0, 3, PSTR("Start avrdude.exe "),0);
lcd_printp_at (0, 4, PSTR("-pm1284p -cavr109 "),0);
lcd_printp_at (0, 5, PSTR("-Pcom? -b115200 "),0);
lcd_printp_at (0, 6, PSTR("-Uflash:w:FILE.hex:a "),0);
lcd_puts_at(0, 7, strGet(ENDSTART), 0);
 
do
{
if (get_key_press (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
return;
}
}
while (!(get_key_press (1 << KEY_ENTER)));
{
 
// start bootloader with Reset, Hold KEY_ENTER*/
wdt_enable( WDTO_250MS );
while (1)
{;}
}
}
 
 
//--------------------------------------------------------------
//
void Show_Error_HW (void)
{
lcd_cls ();
lcd_printp_at (0, 2, PSTR(" Mit dieser Hardware"), 0);
lcd_printp_at (0, 3, PSTR(" nicht möglich!"), 0);
lcd_printp_at (12, 7, PSTR("Ende"), 0);
 
while (!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
return;
}
 
 
//--------------------------------------------------------------
//
void Show_Version (void)
{
uint8_t ii = 0;
uint8_t size = ITEMS_CR;
uint8_t page = 0;
 
lcd_cls ();
 
lcd_printp_at (0, 0, PSTR("PKT Tool V. "), 2);
lcd_printp_at (13,0, PSTR(PKTSWVersion),2);
lcd_printp_at (0, 1, PSTR(" "), 2); //um die ganze Zeile schwarz zu füllen.
lcd_puts_at(0, 1, strGet(START_MSG2), 2);
lcd_puts_at(0, 7, strGet(KEYLINE1), 0);
 
while(1)
{
for(ii = 0;ii < 3 ; ii++)
if((ii + page) < size)
lcd_printp_at(0,ii + 3,param_copyright[ii + page], 0);
 
if (page == 0)
{
lcd_printp_at (0, 2, PSTR(" "), 0);
lcd_printp_at (0, 6, PSTR("\x13"), 0);
}
 
if (page > 0 && page < (size - 3))
{
lcd_printp_at (0, 2, PSTR("\x12"), 0);
lcd_printp_at (0, 6, PSTR("\x13"), 0);
}
 
if (page >= (size - 3))
{
lcd_printp_at (0, 2, PSTR("\x12"), 0);
lcd_printp_at (0, 6, PSTR(" "), 0);
}
 
 
if (get_key_press (1 << KEY_PLUS))
if (page < size - 3)
page++;
 
if (get_key_press (1 << KEY_MINUS))
if (page > 0)
page--;
 
if (get_key_press (1 << KEY_ESC) || get_key_press (1 << KEY_ENTER))
{
get_key_press(KEY_ALL);
return;
}
}
}
 
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property