Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1918 → Rev 1919

/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/eeprom/eeprom.c
0,0 → 1,329
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2013 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/interrupt.h>
#include <avr/eeprom.h>
#include <stdbool.h>
#include <avr/wdt.h>
#include "../lcd/lcd.h"
#include "../main.h"
#include "../timer/timer.h"
#include "eeprom.h"
#include "../wi232/Wi232.h"
#include "../setup/setup.h"
#include "../bluetooth/bluetooth.h"
#include "../mk-data-structs.h"
#include "../connect.h"
#include "../tracking/ng_servo.h"
#include "../tracking/tracking.h"
//------------------------------------------------------------------------------------------
 
ST EEMEM EEStruct;
 
ST Config;
 
//------------------------------------------------------------------------------------------
void WriteWiInitFlag(void)
{
Config.WiIsSet = true;
// WriteParameter();
}
 
 
//--------------------------------------------------------------
//
void WriteBTInitFlag(void)
{
Config.BTIsSet = true;
// WriteParameter();
}
//--------------------------------------------------------------
//
void WriteBTSlaveFlag(void)
{
Config.BTIsSlave = true;
// WriteParameter();
}
//--------------------------------------------------------------
//
void WriteBTMasterFlag(void)
{
Config.BTIsSlave = false;
// WriteParameter();
 
}
 
 
 
//--------------------------------------------------------------
//
void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude)
 
{
Config.LastLongitude = ELongitude;
Config.LastLatitude = ELatitude;
// WriteParameter();
 
}
 
 
//--------------------------------------------------------------
//
void ReadParameter (void)
{
uint8_t update=false;
 
eeprom_read_block((void*)&Config, (const void*)&EEStruct, sizeof(ST));
 
if (Config.Version != EEpromVersion)
{
 
switch (Config.Version)
{
case 0x77: // PKT Version 3.6.6a
 
PointList_Clear();
update = true;
break;
 
case 0x78: // PKT Version 3.6.6b
/* Do necessary steps to perform upgrade */
update = true;
break;
 
default:Delete_EEPROM(); //wenn kein Update möglich alles auf Default setzen
break;
}
 
if (update)
{
Config.Version = EEpromVersion; /* Update the EEPROM version number */
sei();
lcd_cls();
lcd_printp_at (0, 2, PSTR("EEPromUpdate to new"), 0);
lcd_printp_at (0, 3, PSTR(" Version "), 0);
lcd_printp_at (0, 5, PSTR("check the settings!"), 0);
lcd_printp_at (18, 7, PSTR("OK"), 0);
 
while (!get_key_press (1 << KEY_ENTER));
WriteParameter();
cli();
}
}
}
 
 
void WriteParameter (void)
{
copy_line(7);
lcd_printp_at (0, 7, PSTR(" Write EEPROM "), 0);
eeprom_update_block((const void*)&Config, (void*)&EEStruct, sizeof(ST));
paste_line(7);
 
}
 
 
 
//--------------------------------------------------------------
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);
 
Config.MK_LowBat = 137; // 13,7V
Config.DisplayTimeout = 0; // Display immer an
Config.DisplayLanguage = 5; // default undefined
Config.WiTXRXChannel = 1; // Kanal 1 MK Standard
Config.WiNetworkGroup = 66; // Gruppe 66 MK Standard
Config.WiNetworkMode = NetMode_Normal; // MK Standard
Config.WiTXTO = TWaitTime16; // MK Standard
Config.WiUartMTU = UartMTU64; // MK Standard
Config.LCD_ORIENTATION = 0; // normale Ansicht
Config.LCD_DisplayMode = 0; // Normal
Config.LCD_Kontrast = 20; // Kontrast normal
Config.LCD_Helligkeit = 100; // Helligkeit in %
Config.USBBT = 0; // USB Betrieb
Config.U02SV2 = 0; // SV2 (Kabel) Standard
Config.Debug = 0; // kein Debug
Config.UseWi = false; // Wi.232 eingebaut?
Config.UseBT = false; // BT-222 eingebaut?
Config.WiIsSet = true; // Flag für die Initialisierung Wi232
Config.BTIsSet = true; // Flag für die Initialisierung Bluetooth
Config.BTIsSlave = true; // Slave Flag setzen
Config.PKT_IdleBeep = 0; // kein Piepsen bei Inaktivität
Config.PKT_StartInfo = false; // Startinformationen anzeigen
Config.PKT_Accutyp = true; // True = Lipo, False= LiON
Config.OSD_RCErrorbeep = true; // OSD Receiveerrorbeep
Config.OSD_InvertOut = false; // LED Anzeige invertiren
Config.OSD_LEDform = 1; // Form der Anzeige ( + oder schwarz)
Config.OSD_SendOSD = false; // OSD Daten an SV2
Config.OSD_Fallspeed = 40; // maximale Sinkrate
Config.OSD_VarioBeep = 1; // Vario Beep ein
Config.OSD_HomeMKView = true; // Home Circle from MK View
Config.OSD_mAh_Warning = 10000; //mAh Warnschwelle
Config.OSD_ScreenMode = 0; // Variante des OSD Screen
Config.OSD_LipoBar = 0; //Bargraphanzeige für MK Lipo
Config.PKT_Baudrate = Baud_57600; //Baudrate für BT und Wi232
Config.Lipo_UOffset = 6000; // Offset für PKT-Lipomessung
Config.FM_Refresh = 500; // FollowMe interval
Config.FM_Speed = 30; // FollowMe Speed in m/s *0.1
Config.FM_Radius = 5; // Waypoint Tolerance Radius in meter
Config.HWSound = 0; // Hardware Sounderweiterung an PD7
Config.HWBeeper = 1; // Hardware Beeper an PC7
Config.Volume = 0; //Lautstärke
Config.LastLongitude = 88199720;
Config.LastLatitude = 522039630;
 
strcpy_P(Config.bt_pin, PSTR("0000"));
strcpy_P(Config.bt_name, PSTR("PKT Cebra ")); // Wenn Name kürzer als "bt_name_length" mit Leerzeichen auffüllen
strcpy_P(Config.bt_Mac, PSTR("0000-00-000000"));
strcpy_P(Config.RE_ID, PSTR("0000"));
for(uint8_t i = 0; i < 20; i++)
{
Config.gps_UsedDevName[i] = 0; // benutztes GPS Device Name
}
for(uint8_t i = 0; i < 14; i++)
{
Config.gps_UsedMac[i] = '0'; // benutztes GPS Device Mac Adresse
}
Config.gps_UseGPS = false; // ist GPS aktiv?
Config.gps_UsedGPSMouse = GPS_Bluetoothmouse1;
Config.WiIsSet = false;
Config.BTIsSet = false;
Config.Version = EEpromVersion;
Config.sIdxSteps= STEPS_255;
Config.servo[0].rev = SERVO_REV;
Config.servo[0].min = SERVO_I0_RIGHT;
Config.servo[0].max = SERVO_I0_LEFT;
Config.servo[0].mid = SERVO_I0_MIDDLE;
Config.servo[1].rev = SERVO_REV;
Config.servo[1].min = SERVO_I0_RIGHT;
Config.servo[1].max = SERVO_I0_LEFT;
Config.servo[1].mid = SERVO_I0_MIDDLE;
Config.servo_frame = SERVO_PERIODE;
Config.single_step= SINGLE_STEP; // nur bei Test-Servo
Config.repeat= REPEAT; // nur bei Test-Servo
Config.pause = PAUSE; // nur bei Test-Servo
Config.pause_step= PAUSE_STEP; // nur bei Test-Servo
Config.tracking = TRACKING_MIN;
Config.track_hyst = TRACKING_HYSTERESE;
Config.track_tx = 0;
 
for (uint8_t i = 0; i < 5; i++) {
Config.stick_min[i] = 30+i;
Config.stick_max[i] = 270+i;
Config.stick_typ[i] = 0;
Config.stick_dir[i] = 0;
Config.stick_neutral[i] = 0;
}
Config.Lipomessung = true;
PointList_Clear();
WriteParameter();
 
// lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0);
// EEWayPointList_Clear();
 
lcd_printp_at (0, 6, PSTR("!!Check Parameter!! "), 0);
lcd_printp_at (18, 7, PSTR("OK"), 0);
sei ();
set_beep ( 200, 0x0080, BeepNormal);
do{}
while (!(get_key_press (1 << KEY_ENTER)));
 
#if defined HWVERSION3_9
clr_V_On();
#else
 
wdt_enable( WDTO_250MS );
while (1)
{;}
#endif
}
 
 
//--------------------------------------------------------------
//
//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);
 
//}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/eeprom/eeprom.h
0,0 → 1,218
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2013 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*
*****************************************************************************/
 
 
#ifndef _EEPROM_H
#define _EEPROM_H
 
#include <stdbool.h>
#include "../mk-data-structs.h"
#include "../connect.h"
#include "../tracking/ng_servo.h"
#include "../waypoints/waypoints.h"
 
 
 
 
//[General]
//FileVersion = 2
//NumberOfWaypoints = 15
//UsePOI = 0
//POI_CAM_NICK_CTRL = 0
 
//[POI]
//Altitude = 1
//Latitude = 46.7140763
//Longitude = 19.2507334
 
//[Waypoint1]
//Latitude = 46.7145686
//Longitude = 19.2515702
//Radius = 10
//Altitude = 15
//ClimbRate = 0
//DelayTime = 4
//WP_Event_Channel_Value = 96
//Heading = 180
 
 
#define EEpromVersion 0x78 //wird nach jeder Parametererweiterung hochgezählt
 
#define NumberOfWaypoints 55 //Anzahl der Waypoints in der EEPromliste
#define NumberOfWPLists 5 //Anzahl WP Listen im PKT
#define MAX_LIST_LEN 31 // Länge Waypointlist
 
#define bt_pin_length 4
#define RE_ID_length 4 // Länge der RE-ID
#define bt_name_length 10
#define bt_mac_length 14
#define GPS_Bluetoothmouse1 0 //NMEA BT-Mouse
#define GPS_Mikrokopter 1 // GPS Daten vom MK für Tracking
 
 
#define POINT_TYPE_INVALID 255
#define POINT_TYPE_WP 0
#define POINT_TYPE_POI 1
#define INVALID 0x00
#define MAX_WPLIST_LEN 31
 
 
 
 
typedef struct {
uint8_t rev;
uint16_t min;
uint16_t max;
uint16_t mid;
} servo_t;
 
 
typedef struct
{
uint8_t WPIndex; // Index in der EEpromliste
Point_t Waypoint; // Waypoint
} WayPoints;
 
typedef struct
{
uint8_t WPListnumber; // Nummer der WP Liste im PKT
uint8_t WPListAktiv; // Liste aktiv
uint8_t WPDirectory[31]; // Enthält die Indexe der Waypoints im EEPROM
uint8_t UsePOI;
uint8_t POI_CAM_NICK_CTR;
 
} WPListHeader;
 
typedef struct
{
WPListHeader WPList; // Waypointliste im PKT
} WPListDirectory;
 
 
 
 
typedef struct SStructure{
uint8_t Version;
uint8_t MK_LowBat;
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
volatile uint8_t BTIsSlave; // Slave Flag
char bt_pin[bt_pin_length + 1]; // BT Pinnummer
char bt_name[bt_name_length + 1]; // BT Name
char RE_ID[RE_ID_length + 1]; // RE-ID
char bt_Mac[bt_mac_length + 1]; // MAC-Adresse BTM222
 
char gps_UsedDevName[20]; // benutztes GPS Device Name
char gps_UsedMac[14]; // benutztes GPS Device Mac Adresse
volatile uint8_t gps_UseGPS; // ist GPS aktiv?
volatile uint8_t gps_UsedGPSMouse; // GPS Maustyp
 
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 uint8_t OSD_RCErrorbeep; //Empfangsausffallwarnung im OSD Screen
volatile uint8_t OSD_InvertOut; // Out1/2 invertiert anzeigen
volatile uint8_t OSD_LEDform; // Form der Anzeige ( + oder schwarz)
volatile uint8_t OSD_SendOSD; // OSD Daten an SV2 senden
volatile uint8_t OSD_Fallspeed; // maximale Sinkrate
volatile uint8_t OSD_VarioBeep; // Vario Beep im OSD Screen
volatile uint8_t OSD_HomeMKView; // Home Circle from MK-View
volatile uint16_t OSD_mAh_Warning; // mAh Warnschwelle
volatile uint8_t OSD_ScreenMode; //Variante des OSD-Screen
volatile uint8_t OSD_LipoBar; //Bargraphanzeige für MK Lipo
volatile uint8_t PKT_Baudrate; // Baudrate für BT und Wi232
volatile uint16_t FM_Refresh; // FollowMe interval
volatile uint16_t FM_Speed; // FollowMe Speed in m/s *0.1
volatile uint16_t FM_Radius; // Waypoint Tolerance Radius in meter
volatile uint8_t HWSound; // Hardware Sounderweiterung an PD7
volatile uint8_t HWBeeper; // Hardware Beeper an PC7
volatile uint8_t Volume; // Lautstärke
volatile servo_t servo[2];
volatile uint8_t sIdxSteps;
volatile uint16_t hyst_u_min;
volatile uint8_t servo_frame;
 
volatile uint8_t single_step;
volatile uint8_t repeat;
volatile uint8_t pause;
volatile uint8_t pause_step;
volatile uint8_t tracking;
volatile uint8_t track_hyst;
volatile uint8_t track_tx;
// Stickparameter
volatile uint16_t stick_min[5];
volatile uint16_t stick_max[5];
volatile uint8_t stick_typ[5];
volatile uint8_t stick_dir[5];
volatile uint8_t stick_neutral[5]; // ja/nein
volatile uint8_t Lipomessung; // wenn Lipomessung deaktiviert(Lötbrücke öffnen), kann der Kanal als Stick verwendet werden
Point_t PointList[MAX_LIST_LEN]; // ab 3.6.6b EEPROM Version 78
 
 
//!!!neue Parameter immer am Ende anfügen!!!!!!
} ST;
 
extern ST Config;
 
void ReadParameter (void);
void WriteParameter (void);
void ReadLastPosition(void);
void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude);
void WriteWiInitFlag(void);
void WriteBTInitFlag(void);
void WriteBTSlaveFlag(void);
void WriteBTMasterFlag(void);
void Delete_EEPROM(void);
//void EEWayPointList_Clear(void); // l�schen der Waypointliste im EEProm
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property