Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1470 → Rev 1471

/Transportables_Koptertool/branch/GPL_PKT_V3_5_8a_FC086/main.c
0,0 → 1,378
/*****************************************************************************
* 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 <avr/eeprom.h>
 
//************************************************************************************
// Watchdog integrieren und abschalten, wird für Bootloader benötigt
// !!muss hier stehen bleiben!!
 
//--------------------------------------------------------------
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1")));
 
//--------------------------------------------------------------
void wdt_init(void)
{
MCUSR = 0;
wdt_disable();
return;
}
 
//************************************************************************************
// erst ab hier weitere #includes
 
 
#include "lipo.h"
#include "main.h"
#include "lcd.h"
#include "usart.h"
#include "uart1.h"
#include "mk-data-structs.h"
#include "parameter.h"
#include "menu.h"
#include "display.h"
#include "timer.h"
#include "eeprom.h"
#include "Wi232.h"
#include "twimaster.h"
#include "messages.h"
 
//#define MTEST 0 // Menu Test (skip FC/NC detection)
 
Version_t *version;
 
volatile uint8_t mode = 0;
uint8_t hardware = 0;
uint8_t current_hardware = 0;
mk_param_struct_t *mk_param_struct;
 
 
//--------------------------------------------------------------
int main (void)
{
#ifndef DEBUG
uint8_t timeout;
uint8_t val =0;
uint8_t spalte =0;
#endif
 
InitHWPorts(); // Hardwareanhängige Ports konfigurieren
// dafür wird je nach Hardware die HAL_HWxxx verwendet
// Define dazu in der main.h
 
hardware = NO;
current_hardware = 0;
 
 
if (PKT_StartInfo == true)
{
lcd_cls ();
// lcd_printp_at (0,0,PSTR("Portables Kopter Tool"), 0);
lcd_puts_at(0, 0, strGet(START_MSG1), 0);
lcd_puts_at(0, 1, strGet(START_MSG2), 0);
// lcd_printp_at (0,1,PSTR("für FC Ver "), 0);
// lcd_printp_at (11,1,PSTR(FC_Version),0);
// lcd_printp_at (0,3,PSTR("GNU GPL License"), 0);
lcd_puts_at(0, 3, strGet(GNU_GPL), 0);
 
#ifdef HWVERSION1_2
// lcd_printp_at (0,4,PSTR("Hardware 1.2"), 0);
// lcd_printp_at (0,5,PSTR("ATmega 644"), 0);
lcd_puts_at(0, 4, strGet(HW12), 0);
lcd_puts_at(0, 5, strGet(ATMEGA644), 0);
#endif
 
#ifdef HWVERSION1_2W
// lcd_printp_at (0,4,PSTR("Hardware 1.2W"), 0);
// lcd_printp_at (0,5,PSTR("ATmega 644"), 0);
lcd_puts_at(0, 4, strGet(HW12W), 0);
lcd_puts_at(0, 5, strGet(ATMEGA644), 0);
#endif
 
#ifdef HWVERSION1_3
// lcd_printp_at (0,4,PSTR("Hardware 1.3"), 0);
// lcd_printp_at (0,5,PSTR("ATmega 644P"), 0);
lcd_puts_at(0, 4, strGet(HW13), 0);
lcd_puts_at(0, 5, strGet(ATMEGA644P), 0);
#endif
 
#ifdef HWVERSION1_3W
// lcd_printp_at (0,4,PSTR("Hardware 1.3W"), 0);
// lcd_printp_at (0,5,PSTR("ATmega 644P"), 0);
lcd_puts_at(0, 4, strGet(HW13W), 0);
lcd_puts_at(0, 5, strGet(ATMEGA644P), 0);
#endif
 
#ifdef HWVERSION3_9
// lcd_printp_at (0,4,PSTR("Hardware 3.9"), 0);
// lcd_printp_at (0,5,PSTR("ATmega 1284P"), 0);
lcd_puts_at(0, 4, strGet(HW39), 0);
lcd_puts_at(0, 5, strGet(ATMEGA1284P), 0);
#endif
 
_delay_ms(1500);
}
 
#ifndef DEBUG
 
ReadLastPosition ();
 
if (LastLongitude>0x00000000 && LastLatitude>0x00000000)
{
// lcd_printp_at (0, 4, PSTR(" Letzte Position "), 2);
// lcd_printp_at (0, 5, PSTR(" Breitengr Längengr "), 2);
// lcd_printp_at (0, 7, PSTR("löschen weiter"), 0);
lcd_puts_at(0, 4, strGet(START_LASTPOS), 2);
lcd_puts_at(0, 5, strGet(START_LASTPOS1), 3);
lcd_puts_at(0, 7, strGet(START_LASTPOS2), 0);
 
 
write_ndigit_number_u (1, 6, (uint16_t)(LastLongitude/10000000), 2, 0);
lcd_printp_at (3, 6, PSTR("."), 0);
write_ndigit_number_u (4, 6, (uint16_t)((LastLongitude/1000) % 10000), 4, 1);
write_ndigit_number_u (8, 6, (uint16_t)((LastLongitude/10) % 100), 2, 1);
 
 
write_ndigit_number_u (12, 6, (uint16_t)(LastLatitude/10000000), 2, 0);
lcd_printp_at (14, 6, PSTR("."), 0);
write_ndigit_number_u (15, 6, (uint16_t)((LastLatitude/1000) % 10000), 4, 1);
write_ndigit_number_u (19, 6, (uint16_t)((LastLatitude/10) % 100), 2, 1);
 
for (;;)
{
if (get_key_press (1 << KEY_MINUS))
{
WriteLastPosition(0x00000000,0x00000000); // Löschen
lcd_frect (0, (8*4), 128, 8, 0); // Zeile löschen (x, y, l, h, in Pixel)
lcd_frect (0, (8*5), 128, 8, 0);
// lcd_printp_at (0,5,PSTR(" gelöscht "), 0);
lcd_puts_at(0, 5, strGet(START_LASTPOSDEL), 0);
 
lcd_cls_line (0, 6, 21);
lcd_cls_line (0, 7, 21);
 
_delay_ms(1000);
break;
}
if (get_key_press (1 << KEY_ENTER))
{
lcd_cls_line (0, 4, 21);
lcd_cls_line (0, 5, 21);
lcd_cls_line (0, 6, 21);
lcd_cls_line (0, 7, 21);
break;
}
}
}
#endif
 
// switch to NC
USART_putc (0x1b);
USART_putc (0x1b);
USART_putc (0x55);
USART_putc (0xaa);
USART_putc (0x00);
 
mode = 'V';
 
#ifndef DEBUG
 
do
{
timeout = 50;
 
lcd_cls();
// lcd_printp_at (0,4,PSTR("Suche FC..."), 0);
// lcd_printp_at (12, 7, PSTR("Ende"), 0);
lcd_puts_at(0, 4, strGet(START_SEARCHFC), 0);
lcd_puts_at(12, 7, strGet(ENDE), 0);
 
while (!rxd_buffer_locked && timeout)
{
SendOutData('v', ADDRESS_ANY, 0);
 
timer = 20;
 
while (timer > 0);
timeout--;
 
if (spalte <= 20)
{
lcd_printp_at (spalte,6,PSTR("?"),0);
spalte++;
}
else
{
lcd_cls_line (0,6,21);
spalte=0;
}
 
if (get_key_press (1 << KEY_ESC))
{
get_key_press(KEY_ALL);
for (;;)
{
Debug = 0;
hardware = NO;
main_menu ();
}
}
 
}
 
if(timeout == 0)
{
// lcd_printp_at (0,5,PSTR("FC nicht gefunden!"), 0);
lcd_puts_at(0, 5, strGet(START_FCNOTFOUND), 0);
timer = 90;
while (timer > 0);
}
}
while(timeout == 0);
 
if (timeout != 0)
Decode64 ();
 
version = (Version_t *) pRxData;
 
if (PKT_StartInfo == true)
{
lcd_cls ();
// lcd_printp (PSTR("PKT-Tool GNU GPL\r\n"), 0);
// lcd_printp (PSTR("gefunden:\r\n\n"), 0);
lcd_puts_at(0, 0, strGet(START_FCFOUND), 0);
lcd_puts_at(0, 1, strGet(START_FCFOUND1), 0);
 
}
 
if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
{
if (PKT_StartInfo == true)
{
// lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
lcd_puts_at(0, 1, strGet(START_FCFOUND2), 0);
}
hardware = FC;
current_hardware = hardware;
}
else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
{
if (PKT_StartInfo == true)
{
// lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
lcd_puts_at(0, 1, strGet(START_FCFOUND3), 0);
}
hardware = NC;
current_hardware = hardware;
}
 
if (PKT_StartInfo == true)
{
// lcd_printp (PSTR("Version: "), 0);
lcd_puts_at(0, 2, strGet(START_VERSIONCHECK), 0);
lcd_write_number_u (version->SWMajor);
lcd_printp (PSTR("."), 0);
lcd_write_number_u (version->SWMinor);
lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
_delay_ms(1500);
}
SwitchToFC();
#else
if (PKT_StartInfo == true)
{
lcd_cls ();
lcd_printp (PSTR("PKT-Test DEBUG\r\n"), 0);
_delay_ms(1500);
}
 
#endif
 
 
#ifndef DEBUG
 
// EEprom Version / Struktur prüfen
// val = load_setting(1); // Parameterset 1 holen
val = load_setting(0xff); // aktuelles Parameterset holen
if (mk_param_struct->Revision != EEProm_Version)
{
lcd_cls ();
 
 
lcd_printp_at (0, 0, PSTR("EEPromRev.:"), 0);
lcd_write_number_u (EEProm_Version);
 
lcd_puts_at(0, 1, strGet(START_VERSIONCHECK1), 0);
// lcd_printp (PSTR(" erwartet\r\n"), 0);
 
lcd_printp_at (0, 1, PSTR("EEPromRev.:"), 0);
lcd_write_number_u (mk_param_struct->Revision);
lcd_puts_at(0, 2, strGet(START_VERSIONCHECK2), 0);
 
// lcd_printp (PSTR(" gefunden\r\n"), 0);
 
// lcd_printp (PSTR("PKT-Tool nur mit\r\n"), 0);
// lcd_printp (PSTR("FC Software "), 0);
lcd_puts_at(0, 3, strGet(START_VERSIONCHECK3), 0);
lcd_puts_at(0, 4, strGet(START_VERSIONCHECK4), 0);
 
lcd_printp (PSTR(FC_Version),0);
 
// lcd_printp (PSTR("\r\nkompatibel"), 0);
lcd_puts_at(0, 5, strGet(START_VERSIONCHECK5), 0);
hardware = NO;
BeepTime = 1500;
BeepMuster = 0x0040;
_delay_ms(4000);
}
 
#endif
mode = 0;
rxd_buffer_locked = FALSE;
 
timer = 50;
while (timer > 0);
 
for (;;)
{
main_menu ();
}
}