Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1919 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 2013 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
||
5 | * Copyright (C) 2011 Harald Bongartz * |
||
6 | * * |
||
7 | * This program is free software; you can redistribute it and/or modify * |
||
8 | * it under the terms of the GNU General Public License as published by * |
||
9 | * the Free Software Foundation; either version 2 of the License. * |
||
10 | * * |
||
11 | * This program is distributed in the hope that it will be useful, * |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
14 | * GNU General Public License for more details. * |
||
15 | * * |
||
16 | * You should have received a copy of the GNU General Public License * |
||
17 | * along with this program; if not, write to the * |
||
18 | * Free Software Foundation, Inc., * |
||
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
20 | * * |
||
21 | * * |
||
22 | * Credits to: * |
||
23 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
||
24 | * http://www.mikrokopter.de * |
||
25 | * Gregor "killagreg" Stobrawa for his version of the MK code * |
||
26 | * Thomas Kaiser "thkais" for the original project. See * |
||
27 | * http://www.ft-fanpage.de/mikrokopter/ * |
||
28 | * http://forum.mikrokopter.de/topic-4061-1.html * |
||
29 | * Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
||
30 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
31 | * Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
||
32 | *****************************************************************************/ |
||
33 | |||
34 | |||
35 | #include "../cpu.h" |
||
36 | #include <avr/io.h> |
||
37 | #include <avr/pgmspace.h> |
||
38 | #include <util/delay.h> |
||
39 | #include <stdlib.h> |
||
40 | #include <string.h> |
||
41 | #include <avr/interrupt.h> |
||
42 | #include <avr/eeprom.h> |
||
43 | #include <stdbool.h> |
||
44 | #include <avr/wdt.h> |
||
45 | #include "../lcd/lcd.h" |
||
46 | #include "../main.h" |
||
47 | #include "../timer/timer.h" |
||
48 | #include "eeprom.h" |
||
49 | #include "../wi232/Wi232.h" |
||
50 | #include "../setup/setup.h" |
||
51 | #include "../bluetooth/bluetooth.h" |
||
52 | #include "../mk-data-structs.h" |
||
53 | #include "../connect.h" |
||
54 | #include "../tracking/ng_servo.h" |
||
55 | #include "../tracking/tracking.h" |
||
56 | //------------------------------------------------------------------------------------------ |
||
57 | |||
58 | ST EEMEM EEStruct; |
||
59 | |||
60 | ST Config; |
||
61 | |||
62 | //------------------------------------------------------------------------------------------ |
||
63 | void WriteWiInitFlag(void) |
||
64 | { |
||
65 | Config.WiIsSet = true; |
||
66 | // WriteParameter(); |
||
67 | } |
||
68 | |||
69 | |||
70 | //-------------------------------------------------------------- |
||
71 | // |
||
72 | void WriteBTInitFlag(void) |
||
73 | { |
||
74 | Config.BTIsSet = true; |
||
75 | // WriteParameter(); |
||
76 | } |
||
77 | //-------------------------------------------------------------- |
||
78 | // |
||
79 | void WriteBTSlaveFlag(void) |
||
80 | { |
||
81 | Config.BTIsSlave = true; |
||
82 | // WriteParameter(); |
||
83 | } |
||
84 | //-------------------------------------------------------------- |
||
85 | // |
||
86 | void WriteBTMasterFlag(void) |
||
87 | { |
||
88 | Config.BTIsSlave = false; |
||
89 | // WriteParameter(); |
||
90 | |||
91 | } |
||
92 | |||
93 | |||
94 | |||
95 | //-------------------------------------------------------------- |
||
96 | // |
||
97 | void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude) |
||
98 | |||
99 | { |
||
100 | Config.LastLongitude = ELongitude; |
||
101 | Config.LastLatitude = ELatitude; |
||
102 | // WriteParameter(); |
||
103 | |||
104 | } |
||
105 | |||
106 | |||
107 | //-------------------------------------------------------------- |
||
108 | // |
||
109 | void ReadParameter (void) |
||
110 | { |
||
111 | uint8_t update=false; |
||
112 | |||
113 | eeprom_read_block((void*)&Config, (const void*)&EEStruct, sizeof(ST)); |
||
114 | |||
115 | if (Config.Version != EEpromVersion) |
||
116 | { |
||
117 | |||
118 | switch (Config.Version) |
||
119 | { |
||
120 | case 0x77: // PKT Version 3.6.6a |
||
121 | |||
122 | PointList_Clear(); |
||
123 | update = true; |
||
124 | break; |
||
125 | |||
126 | case 0x78: // PKT Version 3.6.6b |
||
127 | /* Do necessary steps to perform upgrade */ |
||
128 | update = true; |
||
129 | break; |
||
130 | |||
131 | default:Delete_EEPROM(); //wenn kein Update möglich alles auf Default setzen |
||
132 | break; |
||
133 | } |
||
134 | |||
135 | if (update) |
||
136 | { |
||
137 | Config.Version = EEpromVersion; /* Update the EEPROM version number */ |
||
138 | sei(); |
||
139 | lcd_cls(); |
||
140 | lcd_printp_at (0, 2, PSTR("EEPromUpdate to new"), 0); |
||
141 | lcd_printp_at (0, 3, PSTR(" Version "), 0); |
||
142 | lcd_printp_at (0, 5, PSTR("check the settings!"), 0); |
||
143 | lcd_printp_at (18, 7, PSTR("OK"), 0); |
||
144 | |||
145 | while (!get_key_press (1 << KEY_ENTER)); |
||
146 | WriteParameter(); |
||
147 | cli(); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | void WriteParameter (void) |
||
154 | { |
||
155 | copy_line(7); |
||
156 | lcd_printp_at (0, 7, PSTR(" Write EEPROM "), 0); |
||
157 | eeprom_update_block((const void*)&Config, (void*)&EEStruct, sizeof(ST)); |
||
158 | paste_line(7); |
||
159 | |||
160 | } |
||
161 | |||
162 | |||
163 | |||
164 | //-------------------------------------------------------------- |
||
165 | void Delete_EEPROM(void) |
||
166 | { |
||
167 | // EEPROM auf Default setzen |
||
168 | |||
169 | lcd_cls(); |
||
170 | lcd_printp_at (0, 0, PSTR(" EEPROM Parameter "), 2); |
||
171 | lcd_printp_at (0, 1, PSTR("werden auf"), 0); |
||
172 | lcd_printp_at (0, 2, PSTR("Standardwerte gesetzt"), 0); |
||
173 | |||
174 | Config.MK_LowBat = 137; // 13,7V |
||
175 | Config.DisplayTimeout = 0; // Display immer an |
||
176 | Config.DisplayLanguage = 5; // default undefined |
||
177 | Config.WiTXRXChannel = 1; // Kanal 1 MK Standard |
||
178 | Config.WiNetworkGroup = 66; // Gruppe 66 MK Standard |
||
179 | Config.WiNetworkMode = NetMode_Normal; // MK Standard |
||
180 | Config.WiTXTO = TWaitTime16; // MK Standard |
||
181 | Config.WiUartMTU = UartMTU64; // MK Standard |
||
182 | Config.LCD_ORIENTATION = 0; // normale Ansicht |
||
183 | Config.LCD_DisplayMode = 0; // Normal |
||
184 | Config.LCD_Kontrast = 20; // Kontrast normal |
||
185 | Config.LCD_Helligkeit = 100; // Helligkeit in % |
||
186 | Config.USBBT = 0; // USB Betrieb |
||
187 | Config.U02SV2 = 0; // SV2 (Kabel) Standard |
||
188 | Config.Debug = 0; // kein Debug |
||
189 | Config.UseWi = false; // Wi.232 eingebaut? |
||
190 | Config.UseBT = false; // BT-222 eingebaut? |
||
191 | Config.WiIsSet = true; // Flag für die Initialisierung Wi232 |
||
192 | Config.BTIsSet = true; // Flag für die Initialisierung Bluetooth |
||
193 | Config.BTIsSlave = true; // Slave Flag setzen |
||
194 | Config.PKT_IdleBeep = 0; // kein Piepsen bei Inaktivität |
||
195 | Config.PKT_StartInfo = false; // Startinformationen anzeigen |
||
196 | Config.PKT_Accutyp = true; // True = Lipo, False= LiON |
||
197 | Config.OSD_RCErrorbeep = true; // OSD Receiveerrorbeep |
||
198 | Config.OSD_InvertOut = false; // LED Anzeige invertiren |
||
199 | Config.OSD_LEDform = 1; // Form der Anzeige ( + oder schwarz) |
||
200 | Config.OSD_SendOSD = false; // OSD Daten an SV2 |
||
201 | Config.OSD_Fallspeed = 40; // maximale Sinkrate |
||
202 | Config.OSD_VarioBeep = 1; // Vario Beep ein |
||
203 | Config.OSD_HomeMKView = true; // Home Circle from MK View |
||
204 | Config.OSD_mAh_Warning = 10000; //mAh Warnschwelle |
||
205 | Config.OSD_ScreenMode = 0; // Variante des OSD Screen |
||
206 | Config.OSD_LipoBar = 0; //Bargraphanzeige für MK Lipo |
||
207 | Config.PKT_Baudrate = Baud_57600; //Baudrate für BT und Wi232 |
||
208 | Config.Lipo_UOffset = 6000; // Offset für PKT-Lipomessung |
||
209 | Config.FM_Refresh = 500; // FollowMe interval |
||
210 | Config.FM_Speed = 30; // FollowMe Speed in m/s *0.1 |
||
211 | Config.FM_Radius = 5; // Waypoint Tolerance Radius in meter |
||
212 | Config.HWSound = 0; // Hardware Sounderweiterung an PD7 |
||
213 | Config.HWBeeper = 1; // Hardware Beeper an PC7 |
||
214 | Config.Volume = 0; //Lautstärke |
||
215 | Config.LastLongitude = 88199720; |
||
216 | Config.LastLatitude = 522039630; |
||
217 | |||
218 | strcpy_P(Config.bt_pin, PSTR("0000")); |
||
219 | strcpy_P(Config.bt_name, PSTR("PKT Cebra ")); // Wenn Name kürzer als "bt_name_length" mit Leerzeichen auffüllen |
||
220 | strcpy_P(Config.bt_Mac, PSTR("0000-00-000000")); |
||
221 | strcpy_P(Config.RE_ID, PSTR("0000")); |
||
222 | for(uint8_t i = 0; i < 20; i++) |
||
223 | { |
||
224 | Config.gps_UsedDevName[i] = 0; // benutztes GPS Device Name |
||
225 | } |
||
226 | for(uint8_t i = 0; i < 14; i++) |
||
227 | { |
||
228 | Config.gps_UsedMac[i] = '0'; // benutztes GPS Device Mac Adresse |
||
229 | } |
||
230 | Config.gps_UseGPS = false; // ist GPS aktiv? |
||
231 | Config.gps_UsedGPSMouse = GPS_Bluetoothmouse1; |
||
232 | Config.WiIsSet = false; |
||
233 | Config.BTIsSet = false; |
||
234 | Config.Version = EEpromVersion; |
||
235 | Config.sIdxSteps= STEPS_255; |
||
236 | Config.servo[0].rev = SERVO_REV; |
||
237 | Config.servo[0].min = SERVO_I0_RIGHT; |
||
238 | Config.servo[0].max = SERVO_I0_LEFT; |
||
239 | Config.servo[0].mid = SERVO_I0_MIDDLE; |
||
240 | Config.servo[1].rev = SERVO_REV; |
||
241 | Config.servo[1].min = SERVO_I0_RIGHT; |
||
242 | Config.servo[1].max = SERVO_I0_LEFT; |
||
243 | Config.servo[1].mid = SERVO_I0_MIDDLE; |
||
244 | Config.servo_frame = SERVO_PERIODE; |
||
245 | Config.single_step= SINGLE_STEP; // nur bei Test-Servo |
||
246 | Config.repeat= REPEAT; // nur bei Test-Servo |
||
247 | Config.pause = PAUSE; // nur bei Test-Servo |
||
248 | Config.pause_step= PAUSE_STEP; // nur bei Test-Servo |
||
249 | Config.tracking = TRACKING_MIN; |
||
250 | Config.track_hyst = TRACKING_HYSTERESE; |
||
251 | Config.track_tx = 0; |
||
252 | |||
253 | for (uint8_t i = 0; i < 5; i++) { |
||
254 | Config.stick_min[i] = 30+i; |
||
255 | Config.stick_max[i] = 270+i; |
||
256 | Config.stick_typ[i] = 0; |
||
257 | Config.stick_dir[i] = 0; |
||
258 | Config.stick_neutral[i] = 0; |
||
259 | } |
||
260 | Config.Lipomessung = true; |
||
261 | PointList_Clear(); |
||
262 | WriteParameter(); |
||
263 | |||
264 | // lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0); |
||
265 | // EEWayPointList_Clear(); |
||
266 | |||
267 | lcd_printp_at (0, 6, PSTR("!!Check Parameter!! "), 0); |
||
268 | lcd_printp_at (18, 7, PSTR("OK"), 0); |
||
269 | sei (); |
||
270 | set_beep ( 200, 0x0080, BeepNormal); |
||
271 | do{} |
||
272 | while (!(get_key_press (1 << KEY_ENTER))); |
||
273 | |||
274 | #if defined HWVERSION3_9 |
||
275 | clr_V_On(); |
||
276 | #else |
||
277 | |||
278 | wdt_enable( WDTO_250MS ); |
||
279 | while (1) |
||
280 | {;} |
||
281 | #endif |
||
282 | } |
||
283 | |||
284 | |||
285 | //-------------------------------------------------------------- |
||
286 | // |
||
287 | //void EEWayPointList_Clear(void) // löschen der Waypointliste im EEProm |
||
288 | //{ |
||
289 | // uint8_t i; |
||
290 | // PKTWayPoint.Waypoint.Position.Latitude = 0; |
||
291 | // PKTWayPoint.Waypoint.Position.Longitude = 0; |
||
292 | // PKTWayPoint.Waypoint.Position.Altitude = 0; |
||
293 | // PKTWayPoint.Waypoint.Heading = 361; |
||
294 | |||
295 | // for(i = 0; i < MAX_WPLIST_LEN; i++) |
||
296 | // { |
||
297 | // PKTWayPointDirectory.WPList.WPDirectory[i] = 0; |
||
298 | // } |
||
299 | |||
300 | // for(i = 0; i < NumberOfWaypoints; i++) |
||
301 | // { |
||
302 | // lcd_printp (PSTR("."), 0); |
||
303 | // eeprom_write_byte (&EEWayPointList[i].WPIndex, i); |
||
304 | // eeprom_write_byte (&EEWayPointList[i].Waypoint.Position.Status, INVALID); |
||
305 | // eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Latitude, (void*)&EEWayPointList[i].Waypoint.Position.Latitude, sizeof(EEWayPointList[i].Waypoint.Position.Latitude)); |
||
306 | // eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Longitude, (void*)&EEWayPointList[i].Waypoint.Position.Longitude, sizeof(EEWayPointList[i].Waypoint.Position.Longitude)); |
||
307 | // eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Altitude, (void*)&EEWayPointList[i].Waypoint.Position.Altitude, sizeof(EEWayPointList[i].Waypoint.Position.Altitude)); |
||
308 | // eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Heading, (void*)&EEWayPointList[i].Waypoint.Heading, sizeof(EEWayPointList[i].Waypoint.Heading)); |
||
309 | // |
||
310 | // 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 |
||
311 | // 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 |
||
312 | // eeprom_write_byte (&EEWayPointList[i].Waypoint.Type, POINT_TYPE_INVALID); |
||
313 | // eeprom_write_byte (&EEWayPointList[i].Waypoint.Event_Flag, 0); // future implementation |
||
314 | // eeprom_write_byte (&EEWayPointList[i].Waypoint.AltitudeRate, 0); // no change of setpoint |
||
315 | // } |
||
316 | |||
317 | // for(i = 0; i < NumberOfWPLists; i++) |
||
318 | // { |
||
319 | // lcd_printp (PSTR("."), 0); |
||
320 | // eeprom_write_byte (&EEWPDirectory[i].WPList.WPListnumber, i); |
||
321 | // eeprom_write_byte (&EEWPDirectory[i].WPList.WPListAktiv, false); |
||
322 | // eeprom_write_byte (&EEWPDirectory[i].WPList.POI_CAM_NICK_CTR, 0); |
||
323 | // eeprom_write_byte (&EEWPDirectory[i].WPList.UsePOI, 0); |
||
324 | // eeprom_write_block ((const void*)&PKTWayPointDirectory.WPList.WPDirectory, (void*)&EEWPDirectory[i].WPList.WPDirectory, sizeof(EEWPDirectory[i].WPList.WPDirectory)); |
||
325 | // |
||
326 | // } |
||
327 | // lcd_printp (PSTR("\r\n"), 0); |
||
328 | |||
329 | //} |