Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2136 - 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
//# HISTORY  connect.c
36
//#
37
//# 10.06.2014 OG
38
//# - del: Port_USB2CFG_Wi() - jetzt in Wi232.c als Wi232_ConfigPC()
39
//#
40
//# 13.04.2014 OG
41
//# - add: Baud_to_uint32()
42
//#
43
//# 10.04.2014 OG
44
//# - del: Port_FC2CFG_WL()
45
//#
46
//# 01.04.2014 OG
47
//# - add: wait_and_restore() redundanten Code einsparen
48
//# - add: Port_BLE2Wi() (Bluetooth 4 Low Energy Modul an SV2)
49
//#
50
//# 28.02.2014 OG
51
//# - chg: alle Anzeigescreens von 'PKT Connect' auf Connect_Screen() umgestellt
52
//# - add: Connect_Screen()
53
//#
54
//# 12.02.2014 OG
55
//# - chg: Port_WiFly2Wi() Auskommentiert: "unused variable 'i'"
56
//#
57
//# 15.07.2013 Cebra
58
//# - chg: Port_FC2CFG_WL, Konfiguration Wlan Modul mit PC, Texte geändert
59
//#
60
//# 02.07.2013 Cebra
61
//# - add: Port_FC2CFG_WL, Konfiguration Wlan Modul mit PC
62
//#
63
//# 26.06.2013 Cebra
64
//# - chg: Modulumschaltung für WiFlypatch geändert
65
//# - add: Port_WiFly2Wi, Wlan-Wi232 Verbindung
66
//#
67
//# 24.6.2013 Cebra
68
//# - fix: Fehler beim UART1 bei der Rückschaltung von USB2FC,USB2WI,BT2FC,BT2WI
69
//#
70
//# 19.06.2013 OG
71
//# - chg: Screen-Layout von Port_BT2Wi(), Port_USB2Wi()
72
//############################################################################
73
 
74
 
75
#include "cpu.h"
76
#include <avr/pgmspace.h>
77
#include <util/delay.h>
78
#include <string.h>
79
 
80
#include "lcd/lcd.h"
81
#include "timer/timer.h"
82
#include "eeprom/eeprom.h"
83
#include "messages.h"
84
#include "lipo/lipo.h"
85
#include "main.h"
86
#include "bluetooth/bluetooth.h"
87
#include "wifly/PKT_WiFlyHQ.h"
88
#include "uart/uart1.h"
89
#include "utils/xutils.h"
90
 
91
 
92
//#if defined HWVERSION3_9
93
//--------------------------------------------------------------
94
void Change_Output(uint8_t UartMode)    // Schaltet die Rx/Tx Richtungen
95
{
96
    // hiermit werden die 74HTC125 (IC5) Gatter geschaltet
97
    clr_USB2FC();       // PC2 aus  IC5 A/D
98
    clr_USB2Wi();       // PB0 aus  IC5 B/C
99
    clr_Uart02FC();     // PC6 aus  IC4 C/D
100
    clr_Uart02Wi();     // PC5 aus  IC4 A/B
101
 
102
 
103
    switch (UartMode)
104
    {
105
        case USB2FC:
106
            UCSR1B &= ~(1<<RXEN1);
107
            UCSR1B &= ~(1<<TXEN1);
108
            UCSR1B &= ~(1<<RXCIE1);
109
 
110
            DDRD  &= ~(1<<DDD2);    // Pins auf Eingang setzen
111
            DDRD  &= ~(1<<DDD3);
112
            PORTD &= ~(1<<PD2);     // Pullup aus
113
            PORTD &= ~(1<<PD3);
114
 
115
            set_USB2FC();
116
            break;
117
 
118
        case Uart02Wi:
119
            set_Uart02Wi();
120
            break;
121
 
122
        case Uart02FC:
123
            set_Uart02FC();
124
            break;
125
 
126
        case USB2Wi:
127
            UCSR1B &= ~(1<<RXEN1);
128
            UCSR1B &= ~(1<<TXEN1);
129
            UCSR1B &= ~(1<<RXCIE1);
130
 
131
            DDRD  &= ~(1<<DDD2);    // Pins auf Eingang setzen
132
            DDRD  &= ~(1<<DDD3);
133
            PORTD &= ~(1<<PD2);     // Pullup aus
134
            PORTD &= ~(1<<PD3);
135
 
136
            set_USB2Wi();
137
            break;
138
    }
139
}
140
 
141
 
142
 
143
//--------------------------------------------------------------
144
// gibt eine uebergebene Baud-Rate als uint32_t zurueck
145
//--------------------------------------------------------------
146
uint32_t Baud_to_uint32( uint8_t baud )
147
{
148
    switch( baud )
149
    {
150
        case Baud_2400:   return( 2400   );
151
        case Baud_4800:   return( 4800   );
152
        case Baud_9600:   return( 9600   );
153
        case Baud_19200:  return( 19200  );
154
        case Baud_38400:  return( 38400  );
155
        case Baud_57600:  return( 57600  );
156
        case Baud_115200: return( 115200 );
157
    }
158
    return( 0 );
159
}
160
 
161
 
162
 
163
//--------------------------------------------------------------
164
// Connect_Screen(
165
//
166
// Parameter:
167
//   title      : PROGMEM
168
//   message    : RAM oder PROGMEM je nach msg_progmem
169
//   msg_progmem: true/false
170
//                true = message im PROGMEM
171
//                false = message im RAM
172
//--------------------------------------------------------------
173
void Connect_Screen( const char *title, const char *message, uint8_t msg_progmem  )
174
{
175
    lcd_cls ();
176
 
177
    lcd_frect( 0, 0, 127, 7, 1);                                            // Titel: Invers
178
    lcd_printp_at( 1, 0, title, MINVERS);                                   // Titel
179
    show_Lipo();
180
 
181
    lcdx_printp_center( 2, title             , MNORMAL,  0,-3);             //
182
    lcdx_printp_center( 3, strGet(STR_ACTIVE), MNORMAL,  0,1);              // "AKTIV!"
183
 
184
    if( (!msg_progmem && strlen(message)>0) || (msg_progmem && strlen_P(message)>0) )
185
    {
186
        if( msg_progmem )
187
            lcdx_printp_center( 5, message, MNORMAL,  0,1);
188
        else
189
            lcdx_print_center( 5, (unsigned char *) message, MNORMAL,  0,1);
190
 
191
        lcd_rect_round( 0, 5*7+2, 127, 8+6, 1, R2);                         // Rahmen
192
    }
193
 
194
    lcd_printp_at(12, 7, strGet(ENDE)               , MNORMAL);             // Keyline
195
}
196
 
197
 
198
 
199
//--------------------------------------------------------------
200
// INTERN
201
//
202
// _port_wait_and_restore()
203
//
204
// Wartet bis der Benutzer beendet und restauriert Einstellungen
205
//
206
// gemeinsamer Code um Speicherplatz zu sparen
207
//--------------------------------------------------------------
208
void wait_and_restore( void )
209
{
210
    while( !get_key_press(1 << KEY_ESC) )
211
    {
212
        show_Lipo();
213
    }
214
 
215
    uart1_init( UART_BAUD_SELECT(57600,F_CPU) );
216
 
217
    SetBaudUart1( Config.PKT_Baudrate );
218
 
219
    if( Config.U02SV2 == 1 )
220
        Change_Output( Uart02FC );
221
    else
222
        Change_Output( Uart02Wi );
223
 
224
    set_Modul_On( USB );
225
}
226
 
227
 
228
 
229
//--------------------------------------------------------------
230
// Function: BT2FC()
231
// Purpose:  Connect BT direct to FC-Kabel (SV2 as MKUSB)
232
// Returns:
233
//--------------------------------------------------------------
234
void Port_BT2FC(void)
235
{
236
    /*
237
    // mit Anzeige von 'Baud'
238
    // verbraucht einige Bytes mehr...
239
    char *message;
240
    uint32_t baud;
241
 
242
    switch( Config.PKT_Baudrate )
243
    {
244
        case Baud_2400:   baud = 2400;      break;
245
        case Baud_4800:   baud = 4800;      break;
246
        case Baud_9600:   baud = 9600;      break;
247
        case Baud_19200:  baud = 19200;     break;
248
        case Baud_38400:  baud = 38400;     break;
249
        case Baud_57600:  baud = 57600;     break;
250
        case Baud_115200: baud = 115200;    break;
251
    }
252
    message = buffered_sprintf_P( PSTR("%lu Baud"), baud);
253
    Connect_Screen( PSTR("BT -> SV2 Kabel"), message, false );
254
    */
255
 
256
    // ohne Anzeige von 'Baud'
257
    Connect_Screen( PSTR("BT -> SV2 Kabel"), "", false );
258
 
259
    // set_BTOn();
260
    set_Modul_On(Bluetooth);
261
    _delay_ms(1000);
262
    //_delay_ms(2000);
263
 
264
    if( !Config.BTIsSlave==true )
265
        bt_set_mode(BLUETOOTH_SLAVE);
266
 
267
    Change_Output(USB2FC);
268
    wait_and_restore();
269
}
270
 
271
 
272
 
273
//--------------------------------------------------------------
274
// Function: BT2Wi()
275
// Purpose:  Connect BT direct to Wi.232
276
// Returns:
277
//--------------------------------------------------------------
278
void Port_BT2Wi( void )
279
{
280
    char *message = "RE-ID: 0000";
281
 
282
    strcpy( &message[7], Config.RE_ID);
283
    Connect_Screen( PSTR("BT Extender"), message, false );
284
 
285
    set_Modul_On( Bluetooth );      // set_BTOn();
286
    _delay_ms(1500);
287
    if( !Config.BTIsSlave==true ) bt_set_mode(BLUETOOTH_SLAVE);
288
 
289
    Change_Output(USB2Wi);
290
    wait_and_restore();
291
}
292
 
293
 
294
 
295
 
296
//--------------------------------------------------------------
297
// Function: WiFly2Wi()
298
// Purpose:  Connect WiFly direct to Wi.232
299
// Hinweis: SV2 RxTx Patch erforderlich!
300
// Returns:
301
//--------------------------------------------------------------
302
void Port_WiFly2Wi( void )
303
{
304
    Connect_Screen( PSTR("WLAN Extender"), PSTR("169.254.1.1:2000"), true );
305
 
306
    set_Modul_On( Wlan );
307
    Change_Output( USB2Wi );
308
    wait_and_restore();
309
}
310
 
311
 
312
 
313
//--------------------------------------------------------------
314
// Function: BLE2Wi()
315
// Purpose:  Connect BLE direct to Wi.232
316
// Hinweis: SV2 RxTx Patch erforderlich!
317
// Returns:
318
//--------------------------------------------------------------
319
void Port_BLE2Wi( void )
320
{
321
    Connect_Screen( PSTR("BLE Extender"), "", false );
322
 
323
    set_Modul_On(Wlan);     // verwendet wie Wlan/WiFly SV2
324
    Change_Output(USB2Wi);
325
    wait_and_restore();
326
}
327
 
328
 
329
 
330
//--------------------------------------------------------------
331
// Function: FC2CFG_BT()
332
// Purpose:  Connect FC (Tx1 Pin3, Rx1 Pin4) direct to BT
333
// Returns:
334
//--------------------------------------------------------------
335
void Port_FC2CFG_BT(void)
336
{
337
    lcd_cls ();
338
    lcd_printp_at (0, 0, PSTR("BTM-222 Konfigurieren"), 2);
339
    lcd_printp_at (0, 1, PSTR("FC > MK-USB > BTM-222"), 2);
340
    lcd_printp_at (0, 3, PSTR("MK-USB an PC anschl. "), 0);
341
    lcd_printp_at (0, 4, PSTR("Zwischen MK-USB und  "), 0);
342
    lcd_printp_at (0, 5, PSTR("PKT ein gekreuztes   "), 0);
343
    lcd_printp_at (0, 6, PSTR("Kabel anschliessen.  "), 0);
344
    lcd_printp_at(12, 7, strGet(ESC), 0);
345
 
346
//    set_BTOn();
347
    set_Modul_On(Bluetooth);
348
    Change_Output(USB2FC);
349
 
350
    while(!get_key_press (1 << KEY_ESC));
351
 
352
    if (Config.U02SV2 == 1)
353
        Change_Output(Uart02FC);
354
    else
355
        Change_Output(Uart02Wi);
356
    set_Modul_On(USB);
357
//    set_BTOff();
358
    return;
359
}
360
 
361
 
362
 
363
//--------------------------------------------------------------
364
// Function: USB2FC()
365
// Purpose:  Connect USB direct to FC-Kabel (SV2 as MKUSB)
366
// Returns:
367
//--------------------------------------------------------------
368
void Port_USB2FC(void)
369
{
370
    Connect_Screen( PSTR("USB -> SV2 Kabel"), PSTR("MK-USB"), true );
371
 
372
    Change_Output(USB2FC);
373
    wait_and_restore();
374
 
375
/*
376
//------
377
// 01.04.2014 OG: ersetzt durch: wait_and_restore()
378
//            Unterschied: zum Schluss wird bei wait_and_restore()
379
//            noch ein set_Modul_On(USB) gemacht - ist das relevant?
380
//------
381
    do
382
    {
383
        show_Lipo();
384
    } while(!get_key_press (1 << KEY_ESC));
385
 
386
    get_key_press(KEY_ALL);
387
    uart1_init (UART_BAUD_SELECT(57600,F_CPU));
388
    SetBaudUart1(Config.PKT_Baudrate);
389
 
390
    if (Config.U02SV2 == 1)
391
        Change_Output(Uart02FC);
392
    else
393
        Change_Output(Uart02Wi);
394
 
395
    return;
396
*/
397
}
398
 
399
 
400
 
401
//--------------------------------------------------------------
402
// Function: USB2Wi()
403
// Purpose:  Connect USB direct to Wi.232
404
// Returns:
405
//--------------------------------------------------------------
406
void Port_USB2Wi(void)
407
{
408
    Connect_Screen( PSTR("USB -> Wi.232"), "", false );
409
 
410
    Change_Output(USB2Wi);
411
    wait_and_restore();
412
 
413
/*
414
//------
415
// 01.04.2014 OG: ersetzt durch: wait_and_restore()
416
//            Unterschied: zum Schluss wird bei wait_and_restore()
417
//            noch ein set_Modul_On(USB) gemacht - ist das relevant?
418
//------
419
    do
420
    {
421
        show_Lipo();
422
    }
423
    while( !get_key_press(1 << KEY_ESC) );
424
 
425
    if( Config.U02SV2 == 1 )
426
            Change_Output(Uart02FC);
427
    else
428
            Change_Output(Uart02Wi);
429
 
430
    get_key_press(KEY_ALL);
431
    return;
432
*/
433
}
434
 
435
 
436
//#endif