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 "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"
#include "bluetooth.h"
#include "followme.h"
#include "stick.h" // MartinR
// #define ITEMS_NC 8 //MartinR: so war es
#define ITEMS_NC 9 //MartinR:
prog_char param_menuitems_nc[ITEMS_NC][NUM_LANG][18]= // zeilen,zeichen+1
// German, English, French, Netherlands
/* // MartinR: so war es
{
{"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 "},
{"Follow Me ","Follow Me ","Follow Me ","Follow Me "},
{"PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d","PKT Tools \x1d"},
};
*/
// MartinR: geändert
{
{"Joystick ","Joystick ","Joystick ","Joystick "},
{"OSD ","OSD ","OSD ","OSD "},
{"3D Lage ","3D angeles ","3D location ","3D locatie "},
{"GPS Info ","GPS Info ","GPS Info ","GPS Info "},
{"Follow Me ","Follow Me ","Follow Me ","Follow Me "},
{"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_FC 5
prog_char param_menuitems_fc[ITEMS_FC][NUM_LANG][18]= // zeilen,zeichen+1
{
{"Joystick ","Joystick ","Joystick ","Joystick "},
//{"OSD ","OSD ","OSD ","OSD "},
//{"3D Lage ","3D angeles ","3D location ","3D locatie "},
//{"GPS Info ","GPS Info ","GPS Info ","GPS Info "},
//{"Follow Me ","Follow Me ","Follow Me ","Follow Me "},
{"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 // MartinR: so war es
#define ITEMS_NO 2 // MartinR:
prog_char param_menuitems_no[ITEMS_NO][NUM_LANG][18]= // zeilen,zeichen+1
/* // MartinR: so war es
{
{"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 "},
};
*/
// MartinR: geändert
{
{"Joystick ","Joystick ","Joystick ","Joystick "},
//{"OSD ","OSD ","OSD ","OSD "},
//{"3D Lage ","3D angeles ","3D location ","3D locatie "},
//{"GPS Info ","GPS Info ","GPS Info ","GPS Info "},
//{"Follow Me ","Follow Me ","Follow Me ","Follow Me "},
//{"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_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 ",
"2012 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;
}
#ifdef HWVERSION3_9
#ifndef ohne_Lipo // MartinR
show_Lipo();
#endif
#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;
#ifdef HWVERSION3_9
#ifndef ohne_Lipo // MartinR
// MartinR: von HAL_HW3_9.c hierher verschoben
ADC_Init(); // ADC für Lipomessung
#endif
#endif
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);
#ifdef HWVERSION3_9
#ifndef ohne_Lipo // MartinR
show_Lipo();
#endif
#endif
}
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;
// MartinR: !!!!!!!!!!!!!!!!!!!
#ifdef HWVERSION3_9
if(hardware == NC)
{
if((val+offset) == 1 )
joystick();
if((val+offset) == 2 )
osd(OSD_Mode);
if((val+offset) == 3 )
osd(THREE_D_Mode);
if((val+offset) == 4 )
gps();
if((val+offset) == 5 )
FollowMe();
if((val+offset) == 6 )
display_data();
if((val+offset) == 7 )
edit_parameter();
if((val+offset) == 8 )
//TODO: Debug an FC087 anpassen
display_debug();
if((val+offset) == 9 )
PKT_Tools();
}
#endif
if(hardware == FC)
{
if((val+offset) == 1 )
joystick();
if((val+offset) == 2 )
display_data();
if((val+offset) == 3 )
edit_parameter();
if((val+offset) == 4 )
//TODO: Debug an FC087 anpassen
display_debug();
if((val+offset) == 5 )
PKT_Tools();
}
if(hardware == NO)
{
/* // MartinR: so war es
if((val+offset) == 1 )
motor_test(FC_Mode);
if((val+offset) == 2 )
servo_test();
#ifdef HWVERSION3_9
if (U02SV2 == 0)
{
if((val+offset) == 3 )
{
if (BTIsSlave==true)
{
Port_BT2Wi();
}
else
{
bt_set_mode(BLUETOOTH_SLAVE);
Port_BT2Wi();
}
}
if((val+offset) == 4 )
Port_USB2Wi();
}
else if (U02SV2 == 1)
{
if((val+offset) == 3 )
{
if (BTIsSlave==true)
{
Port_BT2FC();
}
else
{
bt_set_mode(BLUETOOTH_SLAVE);
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();
*/
if((val+offset) == 1 )
joystick();
if((val+offset) == 2 )
PKT_Tools();
}
}
}
//--------------------------------------------------------------
//
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 V. "), 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_printp_at (0, 1, PSTR(" "), 2); //um die ganze Zeile schwarz zu füllen.
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;
}
}
}