0,0 → 1,532 |
/***************************************************************************** |
* 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 <avr/wdt.h> |
#include "main.h" |
#include "lcd.h" |
#include "parameter.h" |
#include "menu.h" |
#include "display.h" |
#include "motortest.h" |
|
#if defined HWVERSION3_1 || defined HWVERSION1_3 |
#include "motortestI2C.h" |
#endif |
|
|
#include "debug.h" |
#include "timer.h" |
#include "osd.h" |
#include "gps.h" |
#include "pwm.h" |
#include "eeprom.h" |
#include "setup.h" |
#include "uart1.h" |
//#include "jeti.h" |
#include "mk-data-structs.h" |
#include "Wi232.h" |
|
//#define ITEMS_PKT 7 |
// |
//prog_char param_menuitems_pkt[ITEMS_PKT][15]= // zeilen,zeichen+1 |
//{ |
// "LowBat Warn ", |
// "Displ.Timeout", |
// "LCD Orient. ", |
// "Language ", |
// "Wi TX/RX Chan", |
// "Wi NetW. Grp.", |
// "Wi NetW. Mode", |
// |
//}; |
|
|
#define ITEMS_NC 10 |
|
prog_char param_menuitems_nc[ITEMS_NC][15]= // zeilen,zeichen+1 |
{ |
"OSD ", |
"3D Lage ", |
"Display ", |
"Parameters ", |
"Debug Data ", |
"Motor Test ", |
"GPS Info ", |
"Setup PMK ", |
"Version ", |
"USB to FC ", |
|
|
}; |
|
#define ITEMS_FC 7 |
|
prog_char param_menuitems_fc[ITEMS_FC][15]= // zeilen,zeichen+1 |
{ |
"Display ", |
"Parameters ", |
"Debug Data ", |
"Motor Test ", |
"Setup PMK ", |
"Version ", |
"USB to FC ", |
|
|
}; |
|
#define ITEMS_NO 6 |
|
prog_char param_menuitems_no[ITEMS_NO][15]= // zeilen,zeichen+1 |
{ |
"I2C Motortest", |
"Setup PMK ", |
"Version ", |
"USB to FC ", |
"Konfig Wi.232", |
"PKT SW-Update", |
|
}; |
|
//***************************************************************************** |
// 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; |
} |
|
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)) |
{ |
if (line < max) |
{ |
line ++; |
} |
else |
{ |
if(return_at_end == 1) |
{ |
return 254; |
} |
else |
{ |
//line = min; |
} |
} |
} |
|
if (get_key_press (1 << KEY_MINUS)) |
{ |
if (line > min) |
{ |
line --; |
} |
else |
{ |
if(return_at_start == 1) |
{ |
return 253; |
} |
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; |
} |
|
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)) |
{ |
if (line < max) |
{ |
line ++; |
} |
else |
{ |
if(return_at_end == 1) |
{ |
return 254; |
} |
else |
{ |
//line = min; |
} |
} |
} |
|
if (get_key_press (1 << KEY_MINUS)) |
{ |
if (line > min) |
{ |
line --; |
} |
else |
{ |
if(return_at_start == 1) |
{ |
return 253; |
} |
else |
{ |
//line = max; |
} |
} |
} |
|
if (line != before) |
{ |
menu_set_cursor (before, line, pos); |
before = line; |
} |
} |
while (!(get_key_press (1 << KEY_ENTER))); |
|
return line; |
} |
|
void main_menu(void) |
{ |
uint8_t ii = 0; |
uint8_t offset = 0; |
uint8_t size = 0; |
|
if(hardware == NC) size = ITEMS_NC ; |
if(hardware == FC) size = ITEMS_FC ; |
if(hardware == NO) size = ITEMS_NO ; |
|
uint8_t dmode = 0; |
uint8_t target_pos = 1; |
|
uint8_t val =0; |
|
|
while(1) |
{ |
|
lcd_cls (); |
lcd_printp_at (0, 0, PSTR("PMK-Tool=FC "), 0); |
lcd_printp (PSTR(FC_Version),0); |
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b \x0c"), 0); |
|
|
while(1) |
{ |
ii = 0; |
if(offset > 0) |
{ |
lcd_printp_at(1,1, PSTR("\x1a"), 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], 0); |
} |
|
else |
|
if(hardware == FC) |
{ |
lcd_printp_at(3,ii+1,param_menuitems_fc[ii+offset], 0); |
} |
|
|
else |
{ |
lcd_printp_at(3,ii+1,param_menuitems_no[ii+offset], 0); |
} |
} |
if((ii == 5)&&(ii+offset < (size-1))) |
{ |
lcd_printp_at(1,6, PSTR("\x1b"), 0); |
} |
|
} |
|
|
|
if(dmode == 0) |
{ |
if(offset == 0) |
{ |
if(size > 6) |
{ |
val = menu_choose3 (1, 5, target_pos,0,1); |
} |
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 == 255) |
{ |
// nothing |
} |
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 ) jeti(); |
if((val+offset) == 3 ) display_data(); |
if((val+offset) == 4 ) edit_parameter(); |
if((val+offset) == 5 ) display_debug(); |
if((val+offset) == 6 ) motor_test(); |
if((val+offset) == 7 ) gps(); |
if((val+offset) == 8 ) PMK_Setup(); |
if((val+offset) == 9) Show_Version(); |
|
#if defined HWVERSION3_1 || defined HWVERSION1_3 |
if((val+offset) == 10) Wi232_FC(); |
#else |
if((val+offset) == 10) Show_Error_HW(); |
#endif |
|
} |
|
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 ) motor_test(); |
if((val+offset) == 5 ) PMK_Setup(); |
if((val+offset) == 6 ) Show_Version(); |
|
#if defined HWVERSION3_1 || defined HWVERSION1_3 |
if((val+offset) == 7) Wi232_FC(); |
#else |
if((val+offset) == 7) Show_Error_HW(); |
#endif |
} |
if(hardware == NO) |
{ |
if((val+offset) == 1 ) ; |
// if((val+offset) == 1 ) motor_i2c(); noch nicht freigegeben |
if((val+offset) == 2 ) PMK_Setup(); |
if((val+offset) == 3 ) Show_Version(); |
|
#if defined HWVERSION3_1 || defined HWVERSION1_3 |
if((val+offset) == 4) Wi232_FC(); |
if((val+offset) == 5) Wi232_USB(); |
#else |
if((val+offset) == 4) Show_Error_HW(); |
if((val+offset) == 5) Show_Error_HW(); |
#endif |
|
if((val+offset) == 6) |
{ |
|
lcd_cls(); |
lcd_printpns_at (0, 0, PSTR("Connect PC to PKT-USB"),0); |
lcd_printpns_at (0, 1, PSTR("Press 'Start' on PKT"),0); |
lcd_printpns_at (0, 2, PSTR("Then start avrdude:"),0); |
lcd_printpns_at (0, 3, PSTR("avrdude -pm644p -cavr"),0); |
lcd_printpns_at (0, 4, PSTR("109 -Pcom? -b115200 -"),0); |
lcd_printpns_at (0, 5, PSTR("Uflash:w:NEWSOFTWARE"),0); |
lcd_printpns_at (0, 6, PSTR(".hex:a"),0); |
// avrdude -pm644p -cavr109 -P/dev/ttyUSB1 -b115200 -V -Uflash:w:GPL_PKT_V3.1L_FC0.84_HW3x.hex:a |
lcd_printpns_at (0, 7, PSTR("Back Start"),0); |
|
do |
|
if ((get_key_press (1 << KEY_MINUS))) {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_printpns_at (0,0,PSTR("Mit dieser Hardware"), 0); |
lcd_printpns_at (0,1,PSTR("nicht moeglich!"), 0); |
lcd_printpns_at (0,7,PSTR(" zurueck"), 0); |
while (!(get_key_press (1 << KEY_ENTER))); |
return; |
|
} |
|
|
void Show_Version(void) |
{ |
lcd_cls (); |
|
lcd_printpns_at (0,0,PSTR("PMK Tool 3.2"), 0); |
lcd_printpns_at (0,1,PSTR("for FC "), 0); |
lcd_printpns_at (8,1,PSTR(FC_Version),0); |
lcd_printpns_at (0,2,PSTR("(C) GNU GPL License"), 0); |
lcd_printpns_at (0,3,PSTR(" NO WARRANTY"), 0); |
lcd_printpns_at (0,4,PSTR("2008 Thomas Kaiser"), 0); |
lcd_printpns_at (0,5,PSTR("2009-2010 Peter Mack"), 0); |
lcd_printpns_at (0,6,PSTR("2010 Sebastian Boehm"), 0); |
lcd_printpns_at (0,7,PSTR("2011 Chr. Brandtner "), 0); |
|
while (!(get_key_press (1 << KEY_ENTER))); |
return; |
|
} |
|
|
|
|