Blame |
Last modification |
View Log
| RSS feed
/*****************************************************************************
* 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*
*****************************************************************************/
#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.h"
#include "parameter.h"
#include "menu.h"
#include "messages.h"
#include "display.h"
#include "debug.h"
#include "timer.h"
#include "osd.h"
#include "motortest.h"
#include "gps.h"
#include "eeprom.h"
#include "setup.h"
#include "uart1.h"
#include "mk-data-structs.h"
#include "Wi232.h"
#include "servo.h"
#include "tools.h"
#include "connect.h"
#include "lipo.h"
#include "messages.h"
#define ITEMS_NC 7
prog_char param_menuitems_nc[ITEMS_NC][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Netherlands
{
{"OSD ","OSD ","OSD ","OSD "},
{"3D Lage ","3D angeles ","3D location ","3D locatie "},
{"MK Display ","MK Display ","MK Display ","MK Display "},
{"Parameter \x1d","Parameter \x1d","Parameter \x1d","Parameters \x1d"},
{"Debug Data ","Debug Data ","Debug Data ","Debug Data "},
{"GPS Info ","GPS Info ","GPS Info ","GPS Info "},
{"PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d"},
};
#define ITEMS_FC 4
prog_char param_menuitems_fc[ITEMS_FC][NUM_LANG][18]= // zeilen,zeichen+1
{
{"MK Display ","MK Display ","MK Display ","MK Display "},
{"Parameter \x1d","Parameter \x1d","Parameter \x1d","Parameter \x1d"},
{"Debug Data ","Debug Data ","Debug Data ","Debug Data "},
{"PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d"},
};
#define ITEMS_NO 6
prog_char param_menuitems_no[ITEMS_NO][NUM_LANG][18]= // zeilen,zeichen+1
{
{"BL-Ctrl. Tester ","BL-Ctrl. Tester ","BL-Ctrl. Tester ","BL-Ctrl. Tester "},
{"Servo Tester ","Servo Tester ","Servo Tester ","Servo Tester "},
{"PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter ","PC BT > Kopter "},
{"PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter ","PC USB > Kopter "},
{"PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d","PKT Setup \x1d"},
{"PKT Version ","PKT Version ","PKT Version ","PKT Versie "},
};
#define ITEMS_CR 9
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 ",
"2011 Chr. Brandtner &",
" Harald Bongartz ",
};
//--------------------------------------------------------------
// 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;
}
show_Lipo();
}
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 (Debug==1)
hardware = NC;
if (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_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);
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][DisplayLanguage], 0);
else if(hardware == FC)
lcd_printp_at(3,ii+1,param_menuitems_fc[ii+offset][DisplayLanguage], 0);
else
lcd_printp_at(3,ii+1,param_menuitems_no[ii+offset][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;
}
#if defined HWVERSION3_9
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))
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;
}
#endif
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 )
osd(THREE_D_Mode);
if((val+offset) == 3 )
display_data();
if((val+offset) == 4 )
edit_parameter();
if((val+offset) == 5 )
display_debug();
if((val+offset) == 6 )
gps();
if((val+offset) == 7 )
PKT_Tools();
}
if(hardware == FC)
{
if((val+offset) == 1 )
display_data();
if((val+offset) == 2 )
edit_parameter();
if((val+offset) == 3 )
display_debug();
if((val+offset) == 4 )
PKT_Tools();
}
if(hardware == NO)
{
if((val+offset) == 1 )
motor_test(FC_Mode);
if((val+offset) == 2 )
servo_test();
#ifdef HWVERSION3_9
if (U02SV2 == 0)
{
if((val+offset) == 3 )
Port_BT2Wi();
if((val+offset) == 4 )
Port_USB2Wi();
}
else if (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_printp_at (0, 1, PSTR("Connect PC to PKT-USB"),0);
lcd_puts_at(0, 1, strGet(UPDATE1), 0);
// lcd_printp_at (0, 2, PSTR("Press 'Start' on PKT "),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);
// avrdude -pm1284p -cavr109 -P/dev/ttyUSB1 -b115200 -V -Uflash:w:Dateiname.hex:a
// lcd_printp_at (0, 7, PSTR(" Ende Start"), 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 ver "), 2);
// lcd_printp_at (13,0, PSTR(PKTSWVersion),2);
// lcdPuts(Msg(MSG_VERSION1));
// lcd_printp_at (0, 0, Msg(MSG_VERSION1), 2);
// lcd_printp_at (0, 1, PSTR("für FC ver "), 2);
// lcd_printp_at (12,1, PSTR(FC_Version),2);
lcd_puts_at(0, 1, strGet(START_MSG2), 2);
// lcd_printp_at (0, 7, PSTR(KEY_LINE_1), 0);
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;
}
}
}