Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
2136 - 1
/*
2
 * wifly_setup.c
3
 *
4
 *  Created on: 02.07.2013
5
 *      Author: cebra
6
 */
7
/*****************************************************************************
8
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
9
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
10
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
11
 *   Copyright (C) 2011 Harald Bongartz                                      *
12
 *                                                                           *
13
 *   This program is free software; you can redistribute it and/or modify    *
14
 *   it under the terms of the GNU General Public License as published by    *
15
 *   the Free Software Foundation; either version 2 of the License.          *
16
 *                                                                           *
17
 *   This program is distributed in the hope that it will be useful,         *
18
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
19
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
20
 *   GNU General Public License for more details.                            *
21
 *                                                                           *
22
 *   You should have received a copy of the GNU General Public License       *
23
 *   along with this program; if not, write to the                           *
24
 *   Free Software Foundation, Inc.,                                         *
25
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
26
 *                                                                           *
27
 *                                                                           *
28
 *   Credits to:                                                             *
29
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
30
 *                        http://www.mikrokopter.de                          *
31
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
32
 *   Thomas Kaiser "thkais" for the original project. See                    *
33
 *                        http://www.ft-fanpage.de/mikrokopter/              *
34
 *                        http://forum.mikrokopter.de/topic-4061-1.html      *
35
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
36
 *                        http://www.mylifesucks.de/oss/c-osd/               *
37
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
38
 *****************************************************************************/
39
 
40
//############################################################################
41
//# HISTORY  wifly_setup.c
42
//#
43
//# 08.06.2014 OG
44
//# - chg: Setup_WiFly() - Tipptext fuer Module-Installed ergaenzt
45
//#
46
//# 04.06.2014 OG
47
//# - chg: Menuetext angepasst; Menue-Separator hinzugefuegt
48
//#
49
//# 31.05.2014 OG
50
//# - chg: Setup's auf geaendertes Edit_String() umgestellt (Param 'Text' entfernt)
51
//#
52
//# 28.05.2014 OG
53
//# - chg: Setup's auf das neue Edit_generic() umgestellt
54
//#
55
//# 13.04.2014 OG
56
//# - ggf. Probleme beim Downgrade des WiFly auf v2.38 -> deaktiviert
57
//# - FAST KOMPLETT NEUER CODE
58
//#
59
//# 03.04.2014 OG
60
//# - add: #include "../pkt/pkt.h"
61
//#
62
//# 30.03.2014 OG
63
//# - chg: Text von WL_INSTALLED geaendert von "Modul eingebaut?" auf "Modul vorhanden?"
64
//#        -> das Modul wird aufgesteckt und nicht eingebaut...
65
//# - chg: ein paar englische Texte geaendert
66
//# - chg: Sprache Hollaendisch vollstaendig entfernt
67
//# - chg: MenuCtrl_PushML_P() umgestellt auf MenuCtrl_PushML2_P()
68
//#
69
//# 11.03.2014 SH
70
//# - add: neue Menüpunkte Reset, Version und Update
71
//# - chg: Menüpunkt Passwort wurde wieder aktiviert
72
//# - chg: beim Menüpunkt Kanal fängt die Auswahl jetzt bei 0 an (Modul sucht sich automatisch den besten Kanal)
73
//#
74
//# 12.02.2014 OG
75
//# - chg: Setup_WiFly() Auskommentiert: "unused variable 'z'"
76
//# - chg: Setup_WiFly() Auskommentiert: "unused variable 'i'"
77
//#
78
//# 02.07.2013 cebra
79
//# - new: wifly_setup(): Setup für WiFly WLAN-Modul
80
//###########################################################################
81
 
82
 
83
#include "../cpu.h"
84
#include <avr/io.h>
85
#include <avr/interrupt.h>
86
//#include <avr/pgmspace.h>
87
//#include <string.h>
88
//#include <util/delay.h>
89
//#include <string.h>
90
 
91
#include <avr/pgmspace.h>
92
#include <stdbool.h>
93
#include <stdlib.h>
94
#include <stdarg.h>
95
#include <util/delay.h>
96
#include <inttypes.h>
97
#include <string.h>
98
 
99
#include "../main.h"
100
#include "../messages.h"
101
#include "../lcd/lcd.h"
102
#include "../pkt/pkt.h"
103
#include "../utils/menuctrl.h"
104
#include "../utils/xutils.h"
105
#include "../eeprom/eeprom.h"
106
#include "../uart/uart1.h"
107
#include "../setup/setup.h"
108
#include "../wifly/PKT_WiFlyHQ.h"
109
#include "wifly_setup.h"
110
 
111
 
112
#ifdef USE_WLAN
113
 
114
 
115
//char buffer[20];      // fuer Versionsabfrage
116
 
117
 
118
 
119
//-----------------------------
120
// Setup_WiFly() (WLAN)
121
//-----------------------------
122
#define WL_INSTALLED  1
123
#define WL_SSID       2
124
#define WL_PASSWORD   3
125
#define WL_CHANNEL    4
126
#define WL_INIT       5
127
#define WL_RESET      6
128
#define WL_VERSION    7
129
#define WL_UPDATE     8
130
#define WL_PCCONFIG   9
131
#define WL_WPA        10
132
 
133
#define WL_HOMESSID       11
134
#define WL_HOMEPASSWORD   12
135
#define WL_TEST           99
136
 
137
 
138
static const char WL_INSTALLED_de[]     PROGMEM = "WiFly Modus";
139
static const char WL_INSTALLED_en[]     PROGMEM = "WiFly mode";
140
 
141
static const char WL_SSID_de[]          PROGMEM = "SSID";
142
#define           WL_SSID_en            WL_SSID_de
143
 
144
static const char WL_PASSWORD_de[]      PROGMEM = "Passwort";
145
static const char WL_PASSWORD_en[]      PROGMEM = "Password";
146
 
147
static const char WL_HOMESSID_de[]      PROGMEM = "Home SSID";
148
#define           WL_HOMESSID_en        WL_HOMESSID_de
149
 
150
static const char WL_HOMEPASSWORD_de[]  PROGMEM = "Home Passwort";
151
static const char WL_HOMEPASSWORD_en[]  PROGMEM = "Home Password";
152
 
153
static const char WL_CHANNEL_de[]       PROGMEM = "Kanal";
154
static const char WL_CHANNEL_en[]       PROGMEM = "Channel";
155
 
156
static const char WL_VERSION_de[]       PROGMEM = "zeige Version";
157
static const char WL_VERSION_en[]       PROGMEM = "show version";
158
 
159
static const char WL_UPDATE_de[]        PROGMEM = "Update";
160
#define           WL_UPDATE_en          WL_UPDATE_de
161
 
162
static const char WL_PCCONFIG_de[]      PROGMEM = "WiFly einschalten";
163
static const char WL_PCCONFIG_en[]      PROGMEM = "WiFly power on";
164
 
165
static const char WL_WPA_de[]           PROGMEM = "Sicherheit";
166
static const char WL_WPA_en[]           PROGMEM = "Security";
167
 
168
 
169
//############################################################################
170
 
171
 
172
//--------------------------------------------------------------
173
// Setup_WiFly_MenuCreate()
174
//
175
// das Menue aendert sich je nachdem ob WiFly ein- oder
176
// ausgeschaltet ist
177
//--------------------------------------------------------------
178
void Setup_WiFly_MenuCreate( void )
179
{
180
 
181
    //---------------
182
    // Create
183
    //---------------
184
    MenuCtrl_Create();
185
 
186
    if(      Config.UseWL == WIFLY_APMODE )     MenuCtrl_SetTitle_P( PSTR("WiFly AP-Mode"));
187
    else if( Config.UseWL == WIFLY_ADHOC  )     MenuCtrl_SetTitle_P( PSTR("WiFly AdHoc"));
188
    else                                        MenuCtrl_SetTitle_P( PSTR("WiFly"));
189
 
190
 
191
    //---------------
192
    // Menuitems
193
    //---------------
194
    MenuCtrl_PushML2_P( WL_INSTALLED , MENU_ITEM, NOFUNC , WL_INSTALLED_de , WL_INSTALLED_en );
195
 
196
    if( Config.UseWL )
197
    {
198
      //MenuCtrl_Push_P(      WL_TEST      , MENU_ITEM, NOFUNC          , PSTR("TEST")  );
199
 
200
        MenuCtrl_PushML2_P(   WL_VERSION   , MENU_ITEM, NOFUNC          , WL_VERSION_de   , WL_VERSION_en  );
201
 
202
        MenuCtrl_PushSeparator();
203
 
204
        MenuCtrl_PushML2_P(   WL_SSID      , MENU_ITEM, NOFUNC          , WL_SSID_de      , WL_SSID_en     );
205
 
206
        if( Config.UseWL == WIFLY_APMODE )
207
            MenuCtrl_PushML2_P( WL_PASSWORD, MENU_ITEM, NOFUNC          , WL_PASSWORD_de  , WL_PASSWORD_en );
208
 
209
        MenuCtrl_PushML2_P(   WL_CHANNEL   , MENU_ITEM, NOFUNC          , WL_CHANNEL_de   , WL_CHANNEL_en  );
210
 
211
 
212
        if( Config.UseWL == WIFLY_APMODE )
213
            MenuCtrl_Push_P( WL_INIT       , MENU_ITEM, NOFUNC          , PSTR("INIT: AP-Mode")  );
214
        else
215
            MenuCtrl_Push_P( WL_INIT       , MENU_ITEM, NOFUNC          , PSTR("INIT: AdHoc")  );
216
 
217
        MenuCtrl_PushSeparator();
218
 
219
        MenuCtrl_PushML2_P( WL_HOMESSID    , MENU_ITEM, NOFUNC          , WL_HOMESSID_de      , WL_HOMESSID_en     );
220
        MenuCtrl_PushML2_P( WL_HOMEPASSWORD, MENU_ITEM, NOFUNC          , WL_HOMEPASSWORD_de  , WL_HOMEPASSWORD_en );
221
        MenuCtrl_Push_P(    WL_UPDATE      , MENU_ITEM, NOFUNC          , PSTR("UPDATE: WiFly")  );
222
 
223
        MenuCtrl_PushSeparator();
224
 
225
        MenuCtrl_Push_P(    WL_RESET       , MENU_ITEM, NOFUNC          , PSTR("RESET: WiFly")  );
226
        MenuCtrl_PushML2_P( WL_PCCONFIG    , MENU_ITEM, &Port_WiFly2Wi  , WL_PCCONFIG_de  , WL_PCCONFIG_en );
227
      //MenuCtrl_PushML2_P( WL_WPA         , MENU_ITEM, NOFUNC          , WL_WPA_de       , WL_WPA_en      );
228
 
229
 
230
        if( Config.UseWL == WIFLY_ADHOC )
231
        {
232
            // aktuell kann es zu Problemen kommen wenn das WiFly
233
            // auf v2.38 gedowngraded wird (WiFly nicht mehr ansprechbar)
234
            // -> deshalb: deaktiviert
235
            MenuCtrl_ItemActive( WL_UPDATE, false );
236
        }
237
    }
238
}
239
 
240
 
241
 
242
//--------------------------------------------------------------
243
// Setup_WiFly()
244
//--------------------------------------------------------------
245
void Setup_WiFly( void )
246
{
247
    uint8_t itemid;
248
    uint8_t UseWL;
249
    char    string[20];
250
 
251
    Setup_WiFly_MenuCreate();
252
 
253
    //---------------
254
    // Control
255
    //---------------
256
    while( true )
257
    {
258
        MenuCtrl_Control( MENUCTRL_EVENT );
259
 
260
        if( MenuCtrl_GetKey() == KEY_ESC )  break;      // ENDE
261
 
262
        itemid = MenuCtrl_GetItemId();                  // welcher Menu-Punkt (ID)
263
        edit = 0;
264
 
265
 
266
        //--------------------
267
        // TEST
268
        //--------------------
269
        /*
270
        if( itemid == WL_TEST )
271
        {
272
            lcd_cls();
273
            ShowTitle_P( PSTR("TEST"), true );
274
            wifly_test();
275
        }
276
        */
277
 
278
 
279
 
280
        //--------------------
281
        // Wlan_INSTALLED
282
        //--------------------
283
        if( itemid == WL_INSTALLED )
284
        {
285
            UseWL = Config.UseWL;
286
 
287
            Config.UseWL = Edit_generic( Config.UseWL, 0, 2, WlanMode, 1,  strGet(STR_EXTSV2MODULE),NULL);
288
 
289
            if( UseWL != Config.UseWL )                 // hat Benutzer Einstellung geaendert?
290
            {
291
                MenuCtrl_Destroy();                     // Menue aendern wegen wechsel Wlan vorhanden / nicht vorhanden
292
                Setup_WiFly_MenuCreate();
293
                continue;
294
            }
295
        }
296
 
297
 
298
        //--------------------
299
        // WL_VERSION
300
        //--------------------
301
        if( itemid == WL_VERSION )
302
        {
303
            wifly_version_show();
304
        }
305
 
306
 
307
        //--------------------
308
        // WL_SSID
309
        //--------------------
310
        if( itemid == WL_SSID )
311
        {
312
            strncpyfill( string, Config.Wlan_SSID, wlan_ssid_length+1 );                // wlan_ssid_length
313
            Edit_String( string, wlan_ssid_length , EDIT_SSID );
314
 
315
            if( edit == 1 )
316
            {
317
                strrtrim( EditString );                                                  // Leerzeichen rechts entfernen
318
                strncpy( Config.Wlan_SSID, EditString, wlan_ssid_length+1 );
319
            }
320
        }
321
 
322
 
323
        //--------------------
324
        // WL_PASSWORD
325
        //--------------------
326
        if( itemid == WL_PASSWORD)
327
        {
328
            strncpyfill( string, Config.Wlan_Password, wlan_password_length+1 );                    //
329
            Edit_String( string, wlan_password_length , EDIT_WL_PASSWORD );
330
 
331
            if( edit == 1 )
332
            {
333
                strrtrim( EditString );                                                  // Leerzeichen rechts entfernen
334
                strncpy( Config.Wlan_Password, EditString, wlan_password_length+1 );
335
            }
336
        }
337
 
338
 
339
        //--------------------
340
        // WL_HOMESSID
341
        //--------------------
342
        if( itemid == WL_HOMESSID )
343
        {
344
            strncpyfill( string, Config.Wlan_HomeSSID, wlan_ssid_length+1 );                // wlan_ssid_length
345
            Edit_String( string, wlan_ssid_length , EDIT_SSID );
346
 
347
            if( edit == 1 )
348
            {
349
                strrtrim( EditString);                                                  // Leerzeichen rechts entfernen
350
                strncpy( Config.Wlan_HomeSSID, EditString, wlan_ssid_length+1 );
351
            }
352
        }
353
 
354
 
355
        //--------------------
356
        // WL_HOMEPASSWORD
357
        //--------------------
358
        if( itemid == WL_HOMEPASSWORD)
359
        {
360
            strncpyfill( string, Config.Wlan_HomePassword, wlan_password_length+1 );                    //
361
            Edit_String( string, wlan_password_length , EDIT_WL_PASSWORD );
362
 
363
            if( edit == 1 )
364
            {
365
                strrtrim( EditString );                                                  // Leerzeichen rechts entfernen
366
                strncpy( Config.Wlan_HomePassword, EditString, wlan_password_length+1 );
367
            }
368
        }
369
 
370
 
371
 
372
        //--------------------
373
        // WL_CHANNEL
374
        //--------------------
375
        if( itemid == WL_CHANNEL )
376
        {
377
            Config.Wlan_Channel = Edit_generic( Config.Wlan_Channel,  0,13,Show_uint3,1  ,NULL,NULL);
378
        }
379
 
380
 
381
        //--------------------
382
        // WL_INIT
383
        //--------------------
384
        if( itemid == WL_INIT )
385
        {
386
            wifly_init( Config.UseWL ); // Config.UseWL = WIFLY_APMODE oder WIFLY_ADHOC
387
        }
388
 
389
 
390
        //--------------------
391
         // Wlan_RESET
392
         //--------------------
393
         if( itemid == WL_RESET )
394
         {
395
            wifly_reset();
396
         }
397
 
398
 
399
         //--------------------
400
         // Wlan_UPDATE
401
         //--------------------
402
         if( itemid == WL_UPDATE )
403
         {
404
            wifly_update( Config.UseWL );   // Config.UseWL = WIFLY_APMODE oder WIFLY_ADHOC
405
         }
406
 
407
         //--------------------
408
         // Wlan_WPA
409
         //--------------------
410
         //if( itemid == WL_WPA )
411
         //{
412
         //   Config.Wlan_WPA = Edit_generic(Config.Wlan_WPA,0,1,WL3,WlanSecurity,1);
413
         //}
414
 
415
    }  // end: while( true )
416
 
417
    //---------------
418
    // Destroy
419
    //---------------
420
    MenuCtrl_Destroy();
421
 
422
} // end: Setup_WiFly()
423
 
424
#endif