Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1515 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 2011 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/eeprom.h> |
||
42 | #include <stdbool.h> |
||
43 | #include <avr/wdt.h> |
||
44 | #include "lcd.h" |
||
45 | #include "main.h" |
||
46 | #include "timer.h" |
||
47 | #include "eeprom.h" |
||
48 | #include "Wi232.h" |
||
49 | #include "mk-data-structs.h" |
||
50 | #include "connect.h" |
||
51 | |||
52 | |||
53 | //-------------------------------------------------------------- |
||
54 | // |
||
55 | |||
56 | uint8_t EE_LowBat EEMEM = 137; // 13,7V |
||
57 | uint8_t EE_DisplayTimeout EEMEM = 0; // Display immer an |
||
58 | uint8_t EE_DisplayLanguage EEMEM = 254; // Default ungesetzt |
||
59 | uint8_t EE_WiTXRXChannel EEMEM = 1; // Kanal 1 MK Standard |
||
60 | uint8_t EE_WiNetworkGroup EEMEM = 66; // Gruppe 66 MK Standard |
||
61 | uint8_t EE_WiNetworkMode EEMEM = NetMode_Normal; // MK Standard; |
||
62 | uint8_t EE_WiTXTO EEMEM = TWaitTime16; // MK Standard |
||
63 | uint8_t EE_WiUartMTU EEMEM = UartMTU64; // MK Standard |
||
64 | uint8_t EE_LCD_Orientation EEMEM = 0; // normale Ansicht |
||
65 | uint8_t EE_LCD_DisplayMode EEMEM = 0; // Normal |
||
66 | uint8_t EE_LCD_Kontrast EEMEM = 27; // Kontrast normal |
||
67 | uint8_t EE_LCD_Helligkeit EEMEM = 100; // Helligkeit in %gkeit in % |
||
68 | uint8_t EE_USBBT EEMEM = 0; // USB Betrieb |
||
69 | uint8_t EE_U02SV2 EEMEM = 1; // SV2 (Kabel) Standard |
||
70 | uint8_t EE_Debug EEMEM = 0; // kein Debug |
||
71 | uint8_t EE_UseWi EEMEM = true; // Wi.232 eingebaut? |
||
72 | uint8_t EE_UseBT EEMEM = true; // BT-222 eingebaut? |
||
73 | uint8_t EE_WiIsSet EEMEM = false; // Flag für die Initialisierung Wi232 |
||
74 | uint8_t EE_BTIsSet EEMEM = false; // Flag für die Initialisierung Bluetooth |
||
75 | uint8_t EE_PKT_IdleBeep EEMEM = 0; // kein Piepsen bei Inaktivität |
||
76 | uint8_t EE_PKT_StartInfo EEMEM = true; // Startinformationen anzeigen |
||
77 | uint16_t EE_Lipo_UOffset EEMEM = 0; // Offset für die Lipospannugsmessung |
||
78 | uint8_t EE_PKT_Accutyp EEMEM = true; // True = Lipo, False = LiON |
||
79 | uint8_t EEMEM EE_BTPin[bt_pin_length + 1]; |
||
80 | uint8_t EEMEM EE_BTName[bt_name_length + 1]; |
||
81 | uint32_t EE_LastLongitude EEMEM = 0; |
||
82 | uint32_t EE_LastLatitude EEMEM = 0; |
||
83 | |||
84 | WPListDirectory EEWPDirectory[NumberOfWPLists] EEMEM; |
||
85 | WayPoints EEWayPointList[NumberOfWaypoints] EEMEM; |
||
86 | |||
87 | |||
88 | uint8_t EE_PKTVersion EEMEM = EEpromVersion; |
||
89 | |||
90 | |||
91 | volatile uint8_t DisplayTimeout; |
||
92 | volatile uint8_t DisplayLanguage; |
||
93 | volatile uint8_t WiTXRXChannel; |
||
94 | volatile uint8_t WiNetworkGroup; |
||
95 | volatile uint8_t WiNetworkMode; |
||
96 | volatile uint8_t WiTXTO; |
||
97 | volatile uint8_t WiUartMTU; |
||
98 | volatile uint8_t LCD_ORIENTATION; |
||
99 | volatile uint8_t LCD_DisplayMode; |
||
100 | volatile uint8_t LCD_Kontrast; |
||
101 | volatile uint8_t LCD_Helligkeit; |
||
102 | volatile uint8_t USBBT; |
||
103 | volatile uint8_t U02SV2; |
||
104 | volatile uint8_t Debug; |
||
105 | volatile uint8_t UseWi; // Wi232 wird genutzt |
||
106 | volatile uint8_t UseBT; // BT wird genutzt |
||
107 | volatile uint8_t WiIsSet; // Wi232 ist initialisiert |
||
108 | volatile uint8_t BTIsSet; // BT ist initialisiert |
||
109 | char bt_pin[bt_pin_length + 1]; // BT Pinnummer |
||
110 | char bt_name[bt_name_length + 1]; // BT Name |
||
111 | |||
112 | volatile uint32_t LastLongitude; // Letzte Position |
||
113 | volatile uint32_t LastLatitude; |
||
114 | volatile uint8_t PKT_IdleBeep; |
||
115 | volatile uint8_t PKT_StartInfo; |
||
116 | volatile uint16_t Lipo_UOffset; // Offset für die Lipospannugsmessung |
||
117 | volatile uint8_t PKT_Accutyp; // verwendeter Akkutyp |
||
118 | volatile WayPoints PKTWayPoint; // Waypointdaten für einen Waypoint |
||
119 | volatile WPListDirectory PKTWayPointDirectory; // Inhaltsverzeichnis der Listen |
||
120 | |||
121 | |||
122 | |||
123 | //-------------------------------------------------------------- |
||
124 | // |
||
125 | void WriteWiInitFlag(void) |
||
126 | { |
||
127 | WiIsSet = true; |
||
128 | eeprom_write_byte(&EE_WiIsSet, WiIsSet); |
||
129 | |||
130 | } |
||
131 | |||
132 | |||
133 | //-------------------------------------------------------------- |
||
134 | // |
||
135 | void WriteBTInitFlag(void) |
||
136 | { |
||
137 | BTIsSet = true; |
||
138 | eeprom_write_byte(&EE_BTIsSet, BTIsSet); |
||
139 | |||
140 | } |
||
141 | |||
142 | |||
143 | //-------------------------------------------------------------- |
||
144 | // |
||
145 | void ReadLastPosition(void) |
||
146 | |||
147 | { |
||
148 | LastLongitude = eeprom_read_dword(&EE_LastLongitude); |
||
149 | LastLatitude = eeprom_read_dword(&EE_LastLatitude); |
||
150 | } |
||
151 | |||
152 | |||
153 | //-------------------------------------------------------------- |
||
154 | // |
||
155 | void WriteLastPosition(uint32_t ELongitude,uint32_t ELatitude) |
||
156 | |||
157 | { |
||
158 | |||
159 | eeprom_write_dword(&EE_LastLongitude,ELongitude); |
||
160 | eeprom_write_dword(&EE_LastLatitude,ELatitude); |
||
161 | } |
||
162 | |||
163 | |||
164 | //-------------------------------------------------------------- |
||
165 | // |
||
166 | void ReadParameter (void) |
||
167 | { |
||
168 | if (eeprom_read_byte(&EE_PKTVersion) == EEpromVersion) |
||
169 | |||
170 | { |
||
171 | MK_LowBat = eeprom_read_byte (&EE_LowBat); |
||
172 | DisplayTimeout = eeprom_read_byte (&EE_DisplayTimeout); |
||
173 | DisplayLanguage = eeprom_read_byte (&EE_DisplayLanguage); |
||
174 | WiTXRXChannel = eeprom_read_byte (&EE_WiTXRXChannel); |
||
175 | WiNetworkGroup = eeprom_read_byte (&EE_WiNetworkGroup); |
||
176 | WiNetworkMode = eeprom_read_byte (&EE_WiNetworkMode); |
||
177 | WiTXTO = eeprom_read_byte (&EE_WiTXTO); |
||
178 | WiUartMTU = eeprom_read_byte (&EE_WiUartMTU); |
||
179 | LCD_ORIENTATION = eeprom_read_byte (&EE_LCD_Orientation); |
||
180 | LCD_DisplayMode = eeprom_read_byte (&EE_LCD_DisplayMode); |
||
181 | LCD_Kontrast = eeprom_read_byte (&EE_LCD_Kontrast); |
||
182 | LCD_Helligkeit = eeprom_read_byte (&EE_LCD_Helligkeit); |
||
183 | USBBT = eeprom_read_byte (&EE_USBBT); |
||
184 | U02SV2 = eeprom_read_byte (&EE_U02SV2); |
||
185 | Debug = eeprom_read_byte (&EE_Debug); |
||
186 | UseWi = eeprom_read_byte (&EE_UseWi); |
||
187 | UseBT = eeprom_read_byte (&EE_UseBT); |
||
188 | WiIsSet = eeprom_read_byte (&EE_WiIsSet); |
||
189 | BTIsSet = eeprom_read_byte (&EE_BTIsSet); |
||
190 | PKT_IdleBeep = eeprom_read_byte (&EE_PKT_IdleBeep); |
||
191 | PKT_StartInfo = eeprom_read_byte (&EE_PKT_StartInfo); |
||
192 | Lipo_UOffset = eeprom_read_word (&EE_Lipo_UOffset); |
||
193 | PKT_Accutyp = eeprom_read_byte (&EE_PKT_Accutyp); |
||
194 | eeprom_read_block ((void*)&bt_pin, (const void*)&EE_BTPin, bt_pin_length); |
||
195 | eeprom_read_block ((void*)&bt_name, (const void*)&EE_BTName, bt_name_length); |
||
196 | LastLongitude = eeprom_read_dword (&EE_LastLongitude); |
||
197 | LastLatitude = eeprom_read_dword (&EE_LastLatitude); |
||
198 | } |
||
199 | |||
200 | else |
||
201 | Delete_EEPROM(); |
||
202 | |||
203 | } |
||
204 | |||
205 | //-------------------------------------------------------------- |
||
206 | void Delete_EEPROM(void) |
||
207 | { |
||
208 | // EEPROM auf Default setzen |
||
209 | |||
210 | lcd_cls(); |
||
211 | lcd_printp_at (0, 0, PSTR(" EEPROM Parameter "), 2); |
||
212 | lcd_printp_at (0, 1, PSTR("werden auf"), 0); |
||
213 | lcd_printp_at (0, 2, PSTR("Standardwerte gesetzt"), 0); |
||
214 | |||
215 | MK_LowBat = 137; // 13,7V |
||
216 | DisplayTimeout = 0; // Display immer an |
||
217 | DisplayLanguage = 1; // default englisch |
||
218 | WiTXRXChannel = 1; // Kanal 1 MK Standard |
||
219 | WiNetworkGroup = 66; // Gruppe 66 MK Standard |
||
220 | WiNetworkMode = NetMode_Normal; // MK Standard |
||
221 | WiTXTO = TWaitTime16; // MK Standard |
||
222 | WiUartMTU = UartMTU64; // MK Standard |
||
223 | LCD_ORIENTATION = 0; // normale Ansicht |
||
224 | LCD_DisplayMode = 0; // Normal |
||
225 | LCD_Kontrast = 20; // Kontrast normal |
||
226 | LCD_Helligkeit = 100; // Helligkeit in % |
||
227 | USBBT = 0; // USB Betrieb |
||
228 | U02SV2 = 0; // SV2 (Kabel) Standard |
||
229 | Debug = 0; // kein Debug |
||
230 | UseWi = true; // Wi.232 eingebaut? |
||
231 | UseBT = true; // BT-222 eingebaut? |
||
232 | WiIsSet = false; // Flag für die Initialisierung Wi232 |
||
233 | BTIsSet = false; // Flag für die Initialisierung Bluetooth |
||
234 | PKT_IdleBeep = 0; // kein Piepsen bei Inaktivität |
||
235 | PKT_StartInfo = true; // Startnformationen anzeigen |
||
236 | PKT_Accutyp = true; // True = Lipo, False= LiON |
||
237 | Lipo_UOffset = 6000; // Offset für PKT-Lipomessung |
||
238 | LastLongitude = 88199720; |
||
239 | LastLatitude = 522039630; |
||
240 | eeprom_write_dword(&EE_LastLongitude,LastLongitude); |
||
241 | eeprom_write_dword(&EE_LastLatitude,LastLatitude); |
||
242 | |||
243 | strcpy_P(bt_pin, PSTR("1234")); |
||
244 | eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length); |
||
245 | |||
246 | strcpy_P(bt_name, PSTR("PKT Cebra ")); // Wenn Name kürzer als "bt_name_length" mit Leerzeichen auffüllen |
||
247 | eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length); |
||
248 | |||
249 | eeprom_write_byte(&EE_WiIsSet,WiIsSet); |
||
250 | eeprom_write_byte(&EE_BTIsSet,BTIsSet); |
||
251 | eeprom_write_byte(&EE_PKTVersion,EEpromVersion); |
||
252 | |||
253 | WriteParameter(); |
||
254 | |||
255 | // lcd_printp_at (0, 4, PSTR("Waypoints loeschen"), 0); |
||
256 | // EEWayPointList_Clear(); |
||
257 | |||
258 | lcd_printp_at (0, 6, PSTR("!!Check Parameter!! "), 0); |
||
259 | lcd_printp_at (18, 7, PSTR("OK"), 0); |
||
260 | BeepTime = 200; |
||
261 | BeepMuster = 0x0080; |
||
262 | do{} |
||
263 | while (!(get_key_short (1 << KEY_ENTER))); |
||
264 | // _delay_ms(500); |
||
265 | //#if defined HWVERSION3_9 |
||
266 | // clr_V_On(); |
||
267 | //#else |
||
268 | // |
||
269 | // wdt_enable( WDTO_250MS ); |
||
270 | // while (1) |
||
271 | // {;} |
||
272 | //#endif |
||
273 | } |
||
274 | |||
275 | |||
276 | //-------------------------------------------------------------- |
||
277 | // |
||
278 | void WriteParameter (void) |
||
279 | { |
||
280 | eeprom_write_byte (&EE_LowBat, MK_LowBat); |
||
281 | eeprom_write_byte (&EE_DisplayTimeout, DisplayTimeout); |
||
282 | eeprom_write_byte (&EE_DisplayLanguage, DisplayLanguage); |
||
283 | eeprom_write_byte (&EE_WiTXRXChannel, WiTXRXChannel); |
||
284 | eeprom_write_byte (&EE_WiNetworkGroup, WiNetworkGroup); |
||
285 | eeprom_write_byte (&EE_WiNetworkMode, WiNetworkMode); |
||
286 | eeprom_write_byte (&EE_WiTXTO, WiTXTO); |
||
287 | eeprom_write_byte (&EE_WiUartMTU, WiUartMTU); |
||
288 | eeprom_write_byte (&EE_LCD_Orientation, LCD_ORIENTATION); |
||
289 | eeprom_write_byte (&EE_LCD_DisplayMode, LCD_DisplayMode); |
||
290 | eeprom_write_byte (&EE_LCD_Kontrast, LCD_Kontrast); |
||
291 | eeprom_write_byte (&EE_LCD_Helligkeit, LCD_Helligkeit); |
||
292 | eeprom_write_byte (&EE_USBBT, USBBT); |
||
293 | eeprom_write_byte (&EE_U02SV2, U02SV2); |
||
294 | eeprom_write_byte (&EE_Debug, Debug); |
||
295 | eeprom_write_byte (&EE_UseWi, UseWi); |
||
296 | eeprom_write_byte (&EE_UseBT, UseBT); |
||
297 | eeprom_write_byte (&EE_WiIsSet, WiIsSet); |
||
298 | eeprom_write_byte (&EE_BTIsSet, BTIsSet); |
||
299 | eeprom_write_byte (&EE_PKT_IdleBeep, PKT_IdleBeep); |
||
300 | eeprom_write_byte (&EE_PKT_StartInfo, PKT_StartInfo); |
||
301 | eeprom_write_word (&EE_Lipo_UOffset,Lipo_UOffset); |
||
302 | eeprom_write_byte (&EE_PKT_Accutyp, PKT_Accutyp); |
||
303 | |||
304 | eeprom_write_block ((const void*)&bt_pin, (void*)&EE_BTPin, bt_pin_length); |
||
305 | eeprom_write_block ((const void*)&bt_name, (void*)&EE_BTName, bt_name_length); |
||
306 | |||
307 | } |
||
308 | |||
309 | |||
310 | |||
311 | |||
312 | //-------------------------------------------------------------- |
||
313 | // |
||
314 | void EEWayPointList_Clear(void) // löschen der Waypointliste im EEProm |
||
315 | { |
||
316 | uint8_t i; |
||
317 | PKTWayPoint.Waypoint.Position.Latitude = 0; |
||
318 | PKTWayPoint.Waypoint.Position.Longitude = 0; |
||
319 | PKTWayPoint.Waypoint.Position.Altitude = 0; |
||
320 | PKTWayPoint.Waypoint.Heading = 361; |
||
321 | |||
322 | for(i = 0; i < MAX_WPLIST_LEN; i++) |
||
323 | { |
||
324 | PKTWayPointDirectory.WPList.WPDirectory[i] = 0; |
||
325 | } |
||
326 | |||
327 | for(i = 0; i < NumberOfWaypoints; i++) |
||
328 | { |
||
329 | lcd_printp (PSTR("."), 0); |
||
330 | eeprom_write_byte (&EEWayPointList[i].WPIndex, i); |
||
331 | eeprom_write_byte (&EEWayPointList[i].Waypoint.Position.Status, INVALID); |
||
332 | eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Latitude, (void*)&EEWayPointList[i].Waypoint.Position.Latitude, sizeof(EEWayPointList[i].Waypoint.Position.Latitude)); |
||
333 | eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Longitude, (void*)&EEWayPointList[i].Waypoint.Position.Longitude, sizeof(EEWayPointList[i].Waypoint.Position.Longitude)); |
||
334 | eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Position.Altitude, (void*)&EEWayPointList[i].Waypoint.Position.Altitude, sizeof(EEWayPointList[i].Waypoint.Position.Altitude)); |
||
335 | eeprom_write_block ((const void*)&PKTWayPoint.Waypoint.Heading, (void*)&EEWayPointList[i].Waypoint.Heading, sizeof(EEWayPointList[i].Waypoint.Heading)); |
||
336 | |||
337 | 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 |
||
338 | 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 |
||
339 | eeprom_write_byte (&EEWayPointList[i].Waypoint.Type, POINT_TYPE_INVALID); |
||
340 | eeprom_write_byte (&EEWayPointList[i].Waypoint.Event_Flag, 0); // future implementation |
||
341 | eeprom_write_byte (&EEWayPointList[i].Waypoint.AltitudeRate, 0); // no change of setpoint |
||
342 | } |
||
343 | |||
344 | for(i = 0; i < NumberOfWPLists; i++) |
||
345 | { |
||
346 | lcd_printp (PSTR("."), 0); |
||
347 | eeprom_write_byte (&EEWPDirectory[i].WPList.WPListnumber, i); |
||
348 | eeprom_write_byte (&EEWPDirectory[i].WPList.WPListAktiv, false); |
||
349 | eeprom_write_byte (&EEWPDirectory[i].WPList.POI_CAM_NICK_CTR, 0); |
||
350 | eeprom_write_byte (&EEWPDirectory[i].WPList.UsePOI, 0); |
||
351 | eeprom_write_block ((const void*)&PKTWayPointDirectory.WPList.WPDirectory, (void*)&EEWPDirectory[i].WPList.WPDirectory, sizeof(EEWPDirectory[i].WPList.WPDirectory)); |
||
352 | |||
353 | } |
||
354 | lcd_printp (PSTR("\r\n"), 0); |
||
355 | |||
356 | } |