0,0 → 1,353 |
/***************************************************************************** |
* 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 <avr/pgmspace.h> |
#include <util/delay.h> |
#include <stdlib.h> |
#include <string.h> |
#include <avr/eeprom.h> |
#include <stdbool.h> |
#include <avr/wdt.h> |
#include "lcd.h" |
#include "main.h" |
#include "timer.h" |
#include "eeprom.h" |
#include "Wi232.h" |
#include "mk-data-structs.h" |
#include "connect.h" |
|
|
//-------------------------------------------------------------- |
// |
|
uint8_t EE_LowBat EEMEM = 137; // 13,7V |
uint8_t EE_DisplayTimeout EEMEM = 0; // Display immer an |
uint8_t EE_DisplayLanguage EEMEM = 254; // Default ungesetzt |
uint8_t EE_WiTXRXChannel EEMEM = 1; // Kanal 1 MK Standard |
uint8_t EE_WiNetworkGroup EEMEM = 66; // Gruppe 66 MK Standard |
uint8_t EE_WiNetworkMode EEMEM = NetMode_Normal; // MK Standard; |
uint8_t EE_WiTXTO EEMEM = TWaitTime16; // MK Standard |
uint8_t EE_WiUartMTU EEMEM = UartMTU64; // MK Standard |
uint8_t EE_LCD_Orientation EEMEM = 0; // normale Ansicht |
uint8_t EE_LCD_DisplayMode EEMEM = 0; // Normal |
uint8_t EE_LCD_Kontrast EEMEM = 27; // Kontrast normal |
uint8_t EE_LCD_Helligkeit EEMEM = 100; // Helligkeit in %gkeit in % |
uint8_t EE_USBBT EEMEM = 0; // USB Betrieb |
uint8_t EE_U02SV2 EEMEM = 1; // SV2 (Kabel) Standard |
uint8_t EE_Debug EEMEM = 0; // kein Debug |
uint8_t EE_UseWi EEMEM = true; // Wi.232 eingebaut? |
uint8_t EE_UseBT EEMEM = true; // BT-222 eingebaut? |
uint8_t EE_WiIsSet EEMEM = false; // Flag für die Initialisierung Wi232 |
uint8_t EE_BTIsSet EEMEM = false; // Flag für die Initialisierung Bluetooth |
uint8_t EE_PKT_IdleBeep EEMEM = 0; // kein Piepsen bei Inaktivität |
uint8_t EE_PKT_StartInfo EEMEM = true; // Startinformationen anzeigen |
uint16_t EE_Lipo_UOffset EEMEM = 0; // Offset für die Lipospannugsmessung |
uint8_t EE_PKT_Accutyp EEMEM = true; // True = Lipo, False = LiON |
uint8_t EEMEM EE_BTPin[bt_pin_length + 1]; |
uint8_t EEMEM EE_BTName[bt_name_length + 1]; |
uint32_t EE_LastLongitude EEMEM = 0; |
uint32_t EE_LastLatitude EEMEM = 0; |
|
WPListDirectory EEWPDirectory[NumberOfWPLists] EEMEM; |
WayPoints EEWayPointList[NumberOfWaypoints] EEMEM; |
|
|
uint8_t EE_PKTVersion EEMEM = EEpromVersion; |
|
|
volatile uint8_t DisplayTimeout; |
volatile uint8_t DisplayLanguage; |
volatile uint8_t WiTXRXChannel; |
volatile uint8_t WiNetworkGroup; |
volatile uint8_t WiNetworkMode; |
volatile uint8_t WiTXTO; |
volatile uint8_t WiUartMTU; |
volatile uint8_t LCD_ORIENTATION; |
volatile uint8_t LCD_DisplayMode; |
volatile uint8_t LCD_Kontrast; |
volatile uint8_t LCD_Helligkeit; |
volatile uint8_t USBBT; |
volatile uint8_t U02SV2; |
volatile uint8_t Debug; |
volatile uint8_t UseWi; // Wi232 wird genutzt |
volatile uint8_t UseBT; // BT wird genutzt |
volatile uint8_t WiIsSet; // Wi232 ist initialisiert |
volatile uint8_t BTIsSet; // BT ist initialisiert |
char bt_pin[bt_pin_length + 1]; // BT Pinnummer |
char bt_name[bt_name_length + 1]; // BT Name |
|
volatile uint32_t LastLongitude; // Letzte Position |
volatile uint32_t LastLatitude; |
volatile uint8_t PKT_IdleBeep; |
volatile uint8_t PKT_StartInfo; |
volatile uint16_t Lipo_UOffset; // Offset für die Lipospannugsmessung |
volatile uint8_t PKT_Accutyp; // verwendeter Akkutyp |
volatile WayPoints PKTWayPoint; // Waypointdaten für einen Waypoint |
volatile WPListDirectory PKTWayPointDirectory; // Inhaltsverzeichnis der Listen |
|
|
|
//-------------------------------------------------------------- |
// |
void WriteWiInitFlag(void) |
{ |
WiIsSet = true; |
eeprom_write_byte(&EE_WiIsSet, WiIsSet); |
|
} |
|
|
//-------------------------------------------------------------- |
// |
void WriteBTInitFlag(void) |
{ |
BTIsSet = true; |
eeprom_write_byte(&EE_BTIsSet, BTIsSet); |
|
} |
|
|
//-------------------------------------------------------------- |
// |
void ReadLastPosition(void) |
|
{ |
LastLongitude = eeprom_read_dword(&EE_LastLongitude); |
LastLatitude = eeprom_read_dword(&EE_LastLatitude); |
} |
|
|
//-------------------------------------------------------------- |
// |
void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude) |
|
{ |
|
eeprom_write_dword(&EE_LastLongitude,ELongitude); |
eeprom_write_dword(&EE_LastLatitude,ELatitude); |
} |
|
|
//-------------------------------------------------------------- |
// |
void ReadParameter (void) |
{ |
if (eeprom_read_byte(&EE_PKTVersion) == EEpromVersion) |
|
{ |
MK_LowBat = eeprom_read_byte (&EE_LowBat); |
DisplayTimeout = eeprom_read_byte (&EE_DisplayTimeout); |
DisplayLanguage = eeprom_read_byte (&EE_DisplayLanguage); |
WiTXRXChannel = eeprom_read_byte (&EE_WiTXRXChannel); |
WiNetworkGroup = eeprom_read_byte (&EE_WiNetworkGroup); |
WiNetworkMode = eeprom_read_byte (&EE_WiNetworkMode); |
WiTXTO = eeprom_read_byte (&EE_WiTXTO); |
WiUartMTU = eeprom_read_byte (&EE_WiUartMTU); |
LCD_ORIENTATION = eeprom_read_byte (&EE_LCD_Orientation); |
LCD_DisplayMode = eeprom_read_byte (&EE_LCD_DisplayMode); |
LCD_Kontrast = eeprom_read_byte (&EE_LCD_Kontrast); |
LCD_Helligkeit = eeprom_read_byte (&EE_LCD_Helligkeit); |
USBBT = eeprom_read_byte (&EE_USBBT); |
U02SV2 = eeprom_read_byte (&EE_U02SV2); |
Debug = eeprom_read_byte (&EE_Debug); |
UseWi = eeprom_read_byte (&EE_UseWi); |
UseBT = eeprom_read_byte (&EE_UseBT); |
WiIsSet = eeprom_read_byte (&EE_WiIsSet); |
BTIsSet = eeprom_read_byte (&EE_BTIsSet); |
PKT_IdleBeep = eeprom_read_byte (&EE_PKT_IdleBeep); |
PKT_StartInfo = eeprom_read_byte (&EE_PKT_StartInfo); |
Lipo_UOffset = eeprom_read_word (&EE_Lipo_UOffset); |
PKT_Accutyp = eeprom_read_byte (&EE_PKT_Accutyp); |
eeprom_read_block ((void*)&bt_pin, (const void*)&EE_BTPin, bt_pin_length); |
eeprom_read_block ((void*)&bt_name, (const void*)&EE_BTName, bt_name_length); |
LastLongitude = eeprom_read_dword (&EE_LastLongitude); |
LastLatitude = eeprom_read_dword (&EE_LastLatitude); |
} |
|
else |
Delete_EEPROM(); |
|
} |
|
//-------------------------------------------------------------- |
void Delete_EEPROM(void) |
{ |
// EEPROM auf Default setzen |
|
lcd_cls(); |
lcd_printp_at (0, 0, PSTR(" EEPROM Parameter "), 2); |
lcd_printp_at (0, 1, PSTR("werden auf"), 0); |
lcd_printp_at (0, 2, PSTR("Standardwerte gesetzt"), 0); |
|
MK_LowBat = 137; // 13,7V |
DisplayTimeout = 0; // Display immer an |
DisplayLanguage = 254; // default ungesetzt |
WiTXRXChannel = 1; // Kanal 1 MK Standard |
WiNetworkGroup = 66; // Gruppe 66 MK Standard |
WiNetworkMode = NetMode_Normal; // MK Standard |
WiTXTO = TWaitTime16; // MK Standard |
WiUartMTU = UartMTU64; // MK Standard |
LCD_ORIENTATION = 0; // normale Ansicht |
LCD_DisplayMode = 0; // Normal |
LCD_Kontrast = 20; // Kontrast normal |
LCD_Helligkeit = 100; // Helligkeit in % |
USBBT = 0; // USB Betrieb |
U02SV2 = 0; // SV2 (Kabel) Standard |
Debug = 0; // kein Debug |
UseWi = true; // Wi.232 eingebaut? |
UseBT = true; // BT-222 eingebaut? |
WiIsSet = false; // Flag für die Initialisierung Wi232 |
BTIsSet = false; // Flag für die Initialisierung Bluetooth |
PKT_IdleBeep = 0; // kein Piepsen bei Inaktivität |
PKT_StartInfo = true; // Startnformationen anzeigen |
PKT_Accutyp = true; // True = Lipo, False= LiON |
Lipo_UOffset = 6000; // Offset für PKT-Lipomessung |
|
|
strcpy_P(bt_pin, PSTR("1234")); |
eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length); |
|
strcpy_P(bt_name, PSTR("PKT Cebra ")); // Wenn Name kürzer als "bt_name_length" mit Leerzeichen auffüllen |
eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length); |
|
eeprom_write_byte(&EE_WiIsSet,WiIsSet); |
eeprom_write_byte(&EE_BTIsSet,BTIsSet); |
eeprom_write_byte(&EE_PKTVersion,EEpromVersion); |
|
WriteParameter(); |
|
// lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0); |
EEWayPointList_Clear(); |
|
lcd_printp_at (0, 6, PSTR("Neu Starten mit "), 0); |
lcd_printp_at (18, 7, PSTR("OK"), 0); |
BeepTime = 200; |
BeepMuster = 0x0080; |
|
while (!(get_key_short (1 << KEY_ENTER))); |
_delay_ms(500); |
#if defined HWVERSION3_9 |
clr_V_On(); |
#else |
|
wdt_enable( WDTO_250MS ); |
while (1) |
{;} |
#endif |
} |
|
|
//-------------------------------------------------------------- |
// |
void WriteParameter (void) |
{ |
eeprom_write_byte (&EE_LowBat, MK_LowBat); |
eeprom_write_byte (&EE_DisplayTimeout, DisplayTimeout); |
eeprom_write_byte (&EE_DisplayLanguage, DisplayLanguage); |
eeprom_write_byte (&EE_WiTXRXChannel, WiTXRXChannel); |
eeprom_write_byte (&EE_WiNetworkGroup, WiNetworkGroup); |
eeprom_write_byte (&EE_WiNetworkMode, WiNetworkMode); |
eeprom_write_byte (&EE_WiTXTO, WiTXTO); |
eeprom_write_byte (&EE_WiUartMTU, WiUartMTU); |
eeprom_write_byte (&EE_LCD_Orientation, LCD_ORIENTATION); |
eeprom_write_byte (&EE_LCD_DisplayMode, LCD_DisplayMode); |
eeprom_write_byte (&EE_LCD_Kontrast, LCD_Kontrast); |
eeprom_write_byte (&EE_LCD_Helligkeit, LCD_Helligkeit); |
eeprom_write_byte (&EE_USBBT, USBBT); |
eeprom_write_byte (&EE_U02SV2, U02SV2); |
eeprom_write_byte (&EE_Debug, Debug); |
eeprom_write_byte (&EE_UseWi, UseWi); |
eeprom_write_byte (&EE_UseBT, UseBT); |
eeprom_write_byte (&EE_WiIsSet, WiIsSet); |
eeprom_write_byte (&EE_BTIsSet, BTIsSet); |
eeprom_write_byte (&EE_PKT_IdleBeep, PKT_IdleBeep); |
eeprom_write_byte (&EE_PKT_StartInfo, PKT_StartInfo); |
eeprom_write_word (&EE_Lipo_UOffset,Lipo_UOffset); |
eeprom_write_byte (&EE_PKT_Accutyp, PKT_Accutyp); |
|
eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length); |
eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length); |
|
} |
|
|
|
|
//-------------------------------------------------------------- |
// |
void EEWayPointList_Clear(void) // löschen der Waypointliste im EEProm |
{ |
uint8_t i; |
PKTWayPoint.Waypoint.Position.Latitude = 0; |
PKTWayPoint.Waypoint.Position.Longitude = 0; |
PKTWayPoint.Waypoint.Position.Altitude = 0; |
PKTWayPoint.Waypoint.Heading = 361; |
|
for(i = 0; i < MAX_WPLIST_LEN; i++) |
{ |
PKTWayPointDirectory.WPList.WPDirectory[i] = 0; |
} |
|
for(i = 0; i < NumberOfWaypoints; i++) |
{ |
lcd_printp (PSTR("."), 0); |
eeprom_write_byte (&EEWayPointList[i].WPIndex, i); |
eeprom_write_byte (&EEWayPointList[i].Waypoint.Position.Status, INVALID); |
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Latitude, (void*)&EEWayPointList[i].Waypoint.Position.Latitude, sizeof(EEWayPointList[i].Waypoint.Position.Latitude)); |
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Longitude, (void*)&EEWayPointList[i].Waypoint.Position.Longitude, sizeof(EEWayPointList[i].Waypoint.Position.Longitude)); |
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Altitude, (void*)&EEWayPointList[i].Waypoint.Position.Altitude, sizeof(EEWayPointList[i].Waypoint.Position.Altitude)); |
eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Heading, (void*)&EEWayPointList[i].Waypoint.Heading, sizeof(EEWayPointList[i].Waypoint.Heading)); |
|
eeprom_write_byte (&EEWayPointList[i].Waypoint.ToleranceRadius, 0); // in meters, if the MK is within that range around the target, then the next target is triggered |
eeprom_write_byte (&EEWayPointList[i].Waypoint.HoldTime, 0); // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
eeprom_write_byte (&EEWayPointList[i].Waypoint.Type, POINT_TYPE_INVALID); |
eeprom_write_byte (&EEWayPointList[i].Waypoint.Event_Flag, 0); // future implementation |
eeprom_write_byte (&EEWayPointList[i].Waypoint.AltitudeRate, 0); // no change of setpoint |
} |
|
for(i = 0; i < NumberOfWPLists; i++) |
{ |
lcd_printp (PSTR("."), 0); |
eeprom_write_byte (&EEWPDirectory[i].WPList.WPListnumber, i); |
eeprom_write_byte (&EEWPDirectory[i].WPList.WPListAktiv, false); |
eeprom_write_byte (&EEWPDirectory[i].WPList.POI_CAM_NICK_CTR, 0); |
eeprom_write_byte (&EEWPDirectory[i].WPList.UsePOI, 0); |
eeprom_write_block ((const void*)&PKTWayPointDirectory.WPList.WPDirectory, (void*)&EEWPDirectory[i].WPList.WPDirectory, sizeof(EEWPDirectory[i].WPList.WPDirectory)); |
|
} |
lcd_printp (PSTR("\r\n"), 0); |
|
} |