Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1916 - 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 <inttypes.h>
38
#include <stdlib.h>
39
#include <avr/pgmspace.h>
40
#include <avr/wdt.h>
41
#include <util/delay.h>
42
#include <avr/eeprom.h>
43
 
44
 
45
//************************************************************************************
46
// Watchdog integrieren und abschalten, wird für Bootloader benötigt
47
// !!muss hier stehen bleiben!!
48
 
49
//--------------------------------------------------------------
50
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1")));
51
 
52
//--------------------------------------------------------------
53
void wdt_init(void)
54
{
55
        MCUSR = 0;
56
        wdt_disable();
57
        return;
58
}
59
 
60
//************************************************************************************
61
// erst ab hier weitere #includes
62
 
63
 
64
#include "lipo/lipo.h"
65
#include "main.h"
66
#include "lcd/lcd.h"
67
#include "uart/usart.h"
68
 
69
#include "uart/uart1.h"
70
#include "mk-data-structs.h"
71
#include "parameter.h"
72
#include "menu.h"
73
#include "display.h"
74
#include "timer/timer.h"
75
#include "eeprom/eeprom.h"
76
#include "wi232/Wi232.h"
77
#include "motortest/twimaster.h"
78
#include "messages.h"
79
 
80
//#define MTEST 0       // Menu Test (skip FC/NC detection)
81
 
82
 
83
 
84
Version_t *version;
85
 
86
volatile uint8_t mode = 0;
87
uint8_t hardware = 0;
88
uint8_t current_hardware = 0;
89
mk_param_struct_t *mk_param_struct;
90
 
91
 
92
uint8_t searchMK(void)
93
{
94
 
95
 
96
  uint8_t timeout;
97
  uint8_t val =0;
98
  uint8_t spalte =0;
99
  uint8_t RetVal;
100
 
101
 
102
  // switch to NC
103
   USART_putc (0x1b);
104
   USART_putc (0x1b);
105
   USART_putc (0x55);
106
   USART_putc (0xaa);
107
   USART_putc (0x00);
108
 
109
   mode = 'V';
110
 
111
//#ifndef DEBUG
112
 
113
   do
114
   {
115
           timeout = 50;
116
 
117
           lcd_cls();
118
 
119
           lcd_puts_at(0, 4, strGet(START_SEARCHFC), 0);
120
           lcd_puts_at(12, 7, strGet(ENDE), 0);
121
 
122
           while (!rxd_buffer_locked && timeout)
123
           {
124
                   SendOutData('v', ADDRESS_ANY, 0);
125
 
126
                   timer = 20;
127
 
128
                   while (timer > 0);
129
                           timeout--;
130
 
131
                   if (spalte <= 20)
132
                   {
133
                           lcd_printp_at (spalte,6,PSTR("?"),0);
134
                           spalte++;
135
                   }
136
                   else
137
                   {
138
                           lcd_cls_line (0,6,21);
139
                           spalte=0;
140
                   }
141
 
142
                   if (get_key_press (1 << KEY_ESC))
143
                   {
144
                           get_key_press(KEY_ALL);
145
                           for (;;)
146
                           {
147
                               Config.Debug = 0;
148
                                   hardware = NO;
149
                                   main_menu ();
150
                           }
151
                   }
152
 
153
           }
154
 
155
           if(timeout == 0)
156
           {
157
//                      lcd_printp_at (0,5,PSTR("FC nicht gefunden!"), 0);
158
                   lcd_puts_at(0, 5, strGet(START_FCNOTFOUND), 0);
159
                   timer = 90;
160
                   RetVal = false;
161
                   while (timer > 0);
162
           }
163
   }
164
   while(timeout == 0);
165
 
166
   if (timeout != 0)
167
           Decode64 ();
168
 
169
   version = (Version_t *) pRxData;
170
 
171
   if (Config.PKT_StartInfo == true)
172
   {
173
           lcd_cls ();
174
           lcd_puts_at(0, 0, strGet(START_FCFOUND), 0);
175
           lcd_puts_at(0, 1, strGet(START_FCFOUND1), 0);
176
 
177
   }
178
 
179
   if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
180
   {
181
           if (Config.PKT_StartInfo == true)
182
           {
183
                   lcd_puts_at(0, 2, strGet(START_FCFOUND2), 0);
184
           }
185
           hardware = FC;
186
           current_hardware = hardware;
187
           RetVal = true;
188
   }
189
   else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
190
   {
191
           if (Config.PKT_StartInfo == true)
192
           {
193
//                      lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
194
                   lcd_puts_at(0, 2, strGet(START_FCFOUND3), 0);
195
           }
196
           hardware = NC;
197
           current_hardware = hardware;
198
           RetVal = true;
199
   }
200
 
201
   if (Config.PKT_StartInfo == true)
202
   {
203
//              lcd_printp (PSTR("Version: "), 0);
204
           lcd_puts_at(0, 3, strGet(START_VERSIONCHECK), 0);
205
           lcd_write_number_u_at (9, 3, version->SWMajor);
206
           lcd_printp_at (10,3,PSTR("."), 0);
207
           lcd_write_number_u_at (11,3,version->SWMinor);
208
           lcd_write_number_u_at (14,3, version->SWPatch + 'a');
209
           _delay_ms(2500);
210
   }
211
   SwitchToFC();
212
//#else
213
//      if (PKT_StartInfo == true)
214
//      {
215
//              lcd_cls ();
216
//              lcd_printp (PSTR("PKT-Test DEBUG\r\n"), 0);
217
//              _delay_ms(1500);
218
//      }
219
//
220
//#endif
221
 
222
 
223
#ifndef IgnoreFCVersion
224
 
225
   // EEprom Version / Struktur prüfen
226
//      val = load_setting(1); // Parameterset 1 holen
227
   val = load_setting(0xff); // aktuelles Parameterset holen
228
   if (!Config.Debug)
229
     {
230
       if (mk_param_struct->Revision != EEProm_Version)
231
       {
232
               lcd_cls ();
233
 
234
               lcd_printp_at (0, 0, PSTR("EEPromRev "), 0);
235
               lcd_write_number_u (EEProm_Version);
236
 
237
               lcd_puts_at(13, 0, strGet(START_VERSIONCHECK1), 0);
238
    //              lcd_printp (PSTR("erwartet\r\n"), 0);
239
 
240
               lcd_printp_at (0, 2, PSTR("EEPromRev "), 0);
241
               lcd_write_number_u (mk_param_struct->Revision);
242
 
243
               lcd_puts_at(13, 2, strGet(START_VERSIONCHECK2), 0);
244
    //              lcd_printp (PSTR(" gefunden\r\n"), 0);
245
 
246
    //              lcd_printp (PSTR("PKT-Tool nur mit\r\n"), 0);
247
    //              lcd_printp (PSTR("FC Software "), 0);
248
               lcd_puts_at(0, 4, strGet(START_VERSIONCHECK3), 0);
249
               lcd_puts_at(0, 5, strGet(START_VERSIONCHECK4), 0);
250
 
251
    //              lcd_printp (PSTR(FC_Version), 0);
252
               lcd_printp_at (12, 5, PSTR(FC_Version), 0);
253
 
254
    //              lcd_printp (PSTR("\r\nkompatibel"), 0);
255
               lcd_puts_at(0, 6, strGet(START_VERSIONCHECK5), 0);
256
               hardware = NO;
257
               set_beep ( 1500, 0x0040, BeepNormal);
258
 
259
               _delay_ms(4000);
260
       }
261
     }
262
 
263
#endif
264
   mode = 0;
265
   rxd_buffer_locked = FALSE;
266
 
267
   timer = 50;
268
   while (timer > 0);
269
   return RetVal;
270
}
271
 
272
 
273
 
274
//--------------------------------------------------------------
275
int main (void)
276
{
277
 
278
 
279
        InitHWPorts();                                  // Hardwareanhängige Ports konfigurieren
280
                                                        // dafür wird je nach Hardware die HAL_HWxxx verwendet
281
                                                        // Define dazu in der main.h
282
 
283
        hardware = NO;
284
        current_hardware = 0;
285
 
286
 
287
        if (Config.PKT_StartInfo == true)
288
        {
289
                lcd_cls ();
290
                lcd_puts_at(0, 0, strGet(START_MSG1), 0);
291
                lcd_puts_at(0, 1, strGet(START_MSG2), 0);
292
                lcd_puts_at(0, 3, strGet(GNU_GPL), 0);
293
 
294
#ifdef HWVERSION1_2
295
//              lcd_printp_at (0,4,PSTR("Hardware 1.2"), 0);
296
//              lcd_printp_at (0,5,PSTR("ATmega 644"), 0);
297
                lcd_puts_at(0, 4, strGet(HW12), 0);
298
                lcd_puts_at(0, 5, strGet(ATMEGA644), 0);
299
#endif
300
 
301
#ifdef HWVERSION1_2W
302
//              lcd_printp_at (0,4,PSTR("Hardware 1.2W"), 0);
303
//              lcd_printp_at (0,5,PSTR("ATmega 644"), 0);
304
                lcd_puts_at(0, 4, strGet(HW12W), 0);
305
                lcd_puts_at(0, 5, strGet(ATMEGA644), 0);
306
#endif
307
 
308
#ifdef HWVERSION1_3
309
//              lcd_printp_at (0,4,PSTR("Hardware 1.3"), 0);
310
//              lcd_printp_at (0,5,PSTR("ATmega 644P"), 0);
311
                lcd_puts_at(0, 4, strGet(HW13), 0);
312
                lcd_puts_at(0, 5, strGet(ATMEGA644P), 0);
313
#endif
314
 
315
#ifdef HWVERSION1_3W
316
//              lcd_printp_at (0,4,PSTR("Hardware 1.3W"), 0);
317
//              lcd_printp_at (0,5,PSTR("ATmega 644P"), 0);
318
                lcd_puts_at(0, 4, strGet(HW13W), 0);
319
                lcd_puts_at(0, 5, strGet(ATMEGA644P), 0);
320
#endif
321
 
322
#ifdef HWVERSION3_9
323
 
324
                lcd_puts_at(0, 4, strGet(HW39), 0);
325
                lcd_puts_at(0, 5, strGet(ATMEGA1284P), 0);
326
#endif
327
 
328
        _delay_ms(1500);
329
        }
330
 
331
//#ifndef DEBUG
332
 
333
 
334
 
335
        if (Config.LastLongitude>0x00000000 && Config.LastLatitude>0x00000000)
336
        {
337
                lcd_cls ();
338
//              lcd_printp_at (0, 4, PSTR("   Letzte Position   "), 2);
339
//              lcd_printp_at (0, 5, PSTR(" Breitengr  Längengr "), 2);
340
//              lcd_printp_at (0, 7, PSTR("löschen        weiter"), 0);
341
                lcd_puts_at(0, 0, strGet(START_LASTPOS), 2);
342
                lcd_puts_at(0, 1, strGet(START_LASTPOS3), 2);
343
                lcd_puts_at(0, 2, strGet(START_LASTPOS1), 2);
344
                lcd_puts_at(0, 7, strGet(START_LASTPOS2), 0);
345
 
346
 
347
                write_ndigit_number_u (1, 4, (uint16_t)(Config.LastLatitude/10000000), 2, 0,0);
348
                lcd_printp_at (3, 4, PSTR("."), 0);
349
                write_ndigit_number_u (4, 4, (uint16_t)((Config.LastLatitude/1000) % 10000), 4, 1,0);
350
                write_ndigit_number_u (8, 4, (uint16_t)((Config.LastLatitude/10) % 100), 2, 1,0);
351
 
352
 
353
                write_ndigit_number_u (12, 4, (uint16_t)(Config.LastLongitude/10000000), 2, 0,0);
354
                lcd_printp_at (14, 4, PSTR("."), 0);
355
                write_ndigit_number_u (15, 4, (uint16_t)((Config.LastLongitude/1000) % 10000), 4, 1,0);
356
                write_ndigit_number_u (19, 4, (uint16_t)((Config.LastLongitude/10) % 100), 2, 1,0);
357
 
358
                for (;;)
359
                {
360
                        if (get_key_press (1 << KEY_MINUS))
361
                        {
362
                                WriteLastPosition(0x00000000,0x00000000);  // Löschen
363
                                lcd_frect (0, (8*4), 128, 8, 0);  // Zeile löschen (x, y, l, h, in Pixel)
364
                                lcd_frect (0, (8*5), 128, 8, 0);
365
//                              lcd_printp_at (0,5,PSTR("      gelöscht       "), 0);
366
                                lcd_puts_at(0, 5, strGet(START_LASTPOSDEL), 0);
367
 
368
                                lcd_cls_line (0, 6, 21);
369
                                lcd_cls_line (0, 7, 21);
370
 
371
                                _delay_ms(1000);
372
                                break;
373
                        }
374
                        if (get_key_press (1 << KEY_ENTER))
375
                        {
376
                                lcd_cls_line (0, 4, 21);
377
                                lcd_cls_line (0, 5, 21);
378
                                lcd_cls_line (0, 6, 21);
379
                                lcd_cls_line (0, 7, 21);
380
                                break;
381
                        }
382
                }
383
        }
384
//#endif
385
 
386
        searchMK();  // MK suchen
387
 
388
 
389
        for (;;)
390
        {
391
                main_menu ();
392
        }
393
}
394