0,0 → 1,394 |
/***************************************************************************** |
* 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/lipo.h" |
#include "main.h" |
#include "lcd/lcd.h" |
#include "uart/usart.h" |
|
#include "uart/uart1.h" |
#include "mk-data-structs.h" |
#include "parameter.h" |
#include "menu.h" |
#include "display.h" |
#include "timer/timer.h" |
#include "eeprom/eeprom.h" |
#include "wi232/Wi232.h" |
#include "motortest/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; |
|
|
uint8_t searchMK(void) |
{ |
|
|
uint8_t timeout; |
uint8_t val =0; |
uint8_t spalte =0; |
uint8_t RetVal; |
|
|
// 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_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 (;;) |
{ |
Config.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; |
RetVal = false; |
while (timer > 0); |
} |
} |
while(timeout == 0); |
|
if (timeout != 0) |
Decode64 (); |
|
version = (Version_t *) pRxData; |
|
if (Config.PKT_StartInfo == true) |
{ |
lcd_cls (); |
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 (Config.PKT_StartInfo == true) |
{ |
lcd_puts_at(0, 2, strGet(START_FCFOUND2), 0); |
} |
hardware = FC; |
current_hardware = hardware; |
RetVal = true; |
} |
else if ((rxd_buffer[1] - 'a') == ADDRESS_NC) |
{ |
if (Config.PKT_StartInfo == true) |
{ |
// lcd_printp (PSTR("Navi-Ctrl\r\n"), 0); |
lcd_puts_at(0, 2, strGet(START_FCFOUND3), 0); |
} |
hardware = NC; |
current_hardware = hardware; |
RetVal = true; |
} |
|
if (Config.PKT_StartInfo == true) |
{ |
// lcd_printp (PSTR("Version: "), 0); |
lcd_puts_at(0, 3, strGet(START_VERSIONCHECK), 0); |
lcd_write_number_u_at (9, 3, version->SWMajor); |
lcd_printp_at (10,3,PSTR("."), 0); |
lcd_write_number_u_at (11,3,version->SWMinor); |
lcd_write_number_u_at (14,3, version->SWPatch + 'a'); |
_delay_ms(2500); |
} |
SwitchToFC(); |
//#else |
// if (PKT_StartInfo == true) |
// { |
// lcd_cls (); |
// lcd_printp (PSTR("PKT-Test DEBUG\r\n"), 0); |
// _delay_ms(1500); |
// } |
// |
//#endif |
|
|
#ifndef IgnoreFCVersion |
|
// EEprom Version / Struktur prüfen |
// val = load_setting(1); // Parameterset 1 holen |
val = load_setting(0xff); // aktuelles Parameterset holen |
if (!Config.Debug) |
{ |
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(13, 0, strGet(START_VERSIONCHECK1), 0); |
// lcd_printp (PSTR("erwartet\r\n"), 0); |
|
lcd_printp_at (0, 2, PSTR("EEPromRev "), 0); |
lcd_write_number_u (mk_param_struct->Revision); |
|
lcd_puts_at(13, 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, 4, strGet(START_VERSIONCHECK3), 0); |
lcd_puts_at(0, 5, strGet(START_VERSIONCHECK4), 0); |
|
// lcd_printp (PSTR(FC_Version), 0); |
lcd_printp_at (12, 5, PSTR(FC_Version), 0); |
|
// lcd_printp (PSTR("\r\nkompatibel"), 0); |
lcd_puts_at(0, 6, strGet(START_VERSIONCHECK5), 0); |
hardware = NO; |
set_beep ( 1500, 0x0040, BeepNormal); |
|
_delay_ms(4000); |
} |
} |
|
#endif |
mode = 0; |
rxd_buffer_locked = FALSE; |
|
timer = 50; |
while (timer > 0); |
return RetVal; |
} |
|
|
|
//-------------------------------------------------------------- |
int main (void) |
{ |
|
|
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 (Config.PKT_StartInfo == true) |
{ |
lcd_cls (); |
lcd_puts_at(0, 0, strGet(START_MSG1), 0); |
lcd_puts_at(0, 1, strGet(START_MSG2), 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_puts_at(0, 4, strGet(HW39), 0); |
lcd_puts_at(0, 5, strGet(ATMEGA1284P), 0); |
#endif |
|
_delay_ms(1500); |
} |
|
//#ifndef DEBUG |
|
|
|
if (Config.LastLongitude>0x00000000 && Config.LastLatitude>0x00000000) |
{ |
lcd_cls (); |
// 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, 0, strGet(START_LASTPOS), 2); |
lcd_puts_at(0, 1, strGet(START_LASTPOS3), 2); |
lcd_puts_at(0, 2, strGet(START_LASTPOS1), 2); |
lcd_puts_at(0, 7, strGet(START_LASTPOS2), 0); |
|
|
write_ndigit_number_u (1, 4, (uint16_t)(Config.LastLatitude/10000000), 2, 0,0); |
lcd_printp_at (3, 4, PSTR("."), 0); |
write_ndigit_number_u (4, 4, (uint16_t)((Config.LastLatitude/1000) % 10000), 4, 1,0); |
write_ndigit_number_u (8, 4, (uint16_t)((Config.LastLatitude/10) % 100), 2, 1,0); |
|
|
write_ndigit_number_u (12, 4, (uint16_t)(Config.LastLongitude/10000000), 2, 0,0); |
lcd_printp_at (14, 4, PSTR("."), 0); |
write_ndigit_number_u (15, 4, (uint16_t)((Config.LastLongitude/1000) % 10000), 4, 1,0); |
write_ndigit_number_u (19, 4, (uint16_t)((Config.LastLongitude/10) % 100), 2, 1,0); |
|
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 |
|
searchMK(); // MK suchen |
|
|
for (;;) |
{ |
main_menu (); |
} |
} |
|
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |