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  mkdisplay.c
36
//#
37
//#
38
//# 05.04.2015 Cebra
39
//# - chg: SendOutData( 'h', ADDRESS_ANY, 2, &cmd, 1, 0x00 ,1) ergänzt um 2. Parameter wegen Fehlfunktion mit NC 2.09h
40
//#
41
//# 04.06.2014 OG
42
//# - chg: MK_Display() umgestellt auf PKT_Message_Datenverlust()
43
//#
44
//# 31.05.2014 OG
45
//# - chg: MK_Display() - umgestellt auf PKT_KeylineUpDown()
46
//#
47
//# 28.04.2014 OG
48
//# - chg: MK_Display() - leichte Optimierung der Display-Ausgabe um ein paar
49
//#        Bytes Code zu sparen
50
//#
51
//# 09.04.2014 OG  -  vervollstaendigte Steuerung des MK-Display's
52
//# - chg: die Tasten fuer 'Ende' und NC/FC-Umschaltung muessen jetzt lange
53
//#        gedruekckt werden (get_key_long) - keine Beschriftung mehr dafuer
54
//#        vorhanden da die Beschriftung jetzt hoch/runter zeigt!
55
//#        (aber 'Ende' ist da wo es immer im PKT ist)
56
//# - add: Unterstuetzung der hoch/runter Tasten
57
//# - chg: diverse Aenderungen bei der Kommunkation und Einbindung aktueller
58
//#        Funktionen von mkbase.c
59
//#
60
//# 29.01.2014 OG
61
//# - chg: ehemals display_data() jetzt MK_display()
62
//# - chg: ehemals 'display.c' jetzt 'mk/mkdisplay.c'
63
//#
64
//# 25.01.2014 OG
65
//# - optisches Facelift
66
//# - PKT_CtrlHook() eingeklinkt
67
//# - Versionshistorie hinzugefuegt
68
//############################################################################
69
 
70
 
71
#include "../cpu.h"
72
#include <avr/io.h>
73
#include <avr/pgmspace.h>
74
#include <util/delay.h>
75
#include <stdbool.h>
76
 
77
#include "../main.h"
78
#include "../lcd/lcd.h"
79
#include "../uart/usart.h"
80
#include "../timer/timer.h"
81
#include "../messages.h"
82
#include "../lipo/lipo.h"
83
#include "../pkt/pkt.h"
84
#include "../mk-data-structs.h"
85
#include "mkbase.h"
86
#include "mkdisplay.h"
87
 
88
#define TIMEOUT 500 // 5 sec
89
 
90
 
91
uint8_t ACC_Display=false;
92
 
93
 
94
//--------------------------------------------------------------
95
//--------------------------------------------------------------
96
void MK_Display(void)
97
{
98
    uint8_t cmd;
99
    uint8_t redraw = true;
100
    uint8_t exit   = false;
101
 
102
    mode              = 'H';
103
    rxd_buffer_locked = FALSE;
104
    timer             = TIMEOUT;
105
//    cmd               = 0xfc;   // Home = first page
106
    cmd               = 0xff;   // aktuelle Seite
107
 
108
    redraw = true;
109
    MK_SwitchToFC();  // add 31.3.2014 Cebra, definierter Zustand
110
 
111
    if (ACC_Display==true)
112
      {
113
       cmd = 0x06;
114
       SendOutData( 'l', ADDRESS_ANY, 1, &cmd,1);
115
       cmd = 0xff;
116
       if( rxd_buffer_locked )
117
       {
118
           Decode64 ();
119
           //------------------------------------------
120
           // RX-Buffer freigeben
121
           //------------------------------------------
122
           rxd_buffer_locked = FALSE;
123
           timer = TIMEOUT;
124
 
125
       } // end: if( rxd_buffer_locked )
126
//       _delay_ms(250);
127
      }
128
 
129
 
130
 
131
    do
132
    {
133
        //------------------------------------------
134
        // Screen neu zeichnen
135
        //------------------------------------------
136
        if( redraw )
137
        {
138
            ShowTitle_P( ( current_hardware == NC ? PSTR("NC") : PSTR("FC") ), true );
139
            lcd_printp_at( 4, 0, PSTR("Display"), MINVERS);
140
 
141
            lcd_rect_round( 0, 2*7-3, 127, 5*7+3+3, 1, R2);                         // Rahmen
142
            lcdx_printp_at( 2, 7, PSTR("\x18    \x19"), MNORMAL,  0,0);             // Keyline: Links / Rechts
143
            PKT_KeylineUpDown( 18, 13,  0,0);                                       // Keyline: Down / Up
144
 
145
            redraw = false;
146
        }
147
 
148
 
149
        show_Lipo();
150
 
151
 
152
        SendOutData( 'h', ADDRESS_ANY, 2, &cmd, 1, 0x00 ,1); // 05.04.2015 Cebra, 2.er Parameter wg NC 2.09i
153
        cmd = 0xff;
154
 
155
        _delay_ms(250);
156
 
157
        if( rxd_buffer_locked )
158
        {
159
            Decode64 ();
160
 
161
            //------------------------------------------
162
            // Ausgabe auf PKT-Anzeige
163
            // 4 Zeilen a 20 Zeichen
164
            // (Anzeige von unten nach oben)
165
            //------------------------------------------
166
            rxd_buffer[83] = 0;
167
            lcdx_print_at( 0,5, (uint8_t *) &rxd_buffer[3+60],  MNORMAL,  5,2);
168
 
169
            rxd_buffer[63] = 0;
170
            lcdx_print_at( 0,4, (uint8_t *) &rxd_buffer[3+40],  MNORMAL,  5,1);
171
 
172
            rxd_buffer[43] = 0;
173
            lcdx_print_at( 0,3, (uint8_t *) &rxd_buffer[3+20],  MNORMAL,  5,0);
174
 
175
            rxd_buffer[23] = 0;
176
            lcdx_print_at( 0,2, (uint8_t *) &rxd_buffer[3+ 0],  MNORMAL,  5,-1);
177
 
178
 
179
            //------------------------------------------
180
            // RX-Buffer freigeben
181
            //------------------------------------------
182
            rxd_buffer_locked = FALSE;
183
            timer = TIMEOUT;
184
 
185
        } // end: if( rxd_buffer_locked )
186
 
187
 
188
        //------------------------------------------
189
        // Pruefe PKT Update oder andere PKT-Aktion
190
        //------------------------------------------
191
        if( PKT_CtrlHook() )                                                                // Update vom Updatetool angefordert?
192
        {
193
            redraw = true;
194
        }
195
 
196
 
197
        if( get_key_press(1 << KEY_MINUS) || get_key_long_rpt_sp((1 << KEY_MINUS),2) )
198
        {
199
            cmd = 0xfe;         // key: rechts (next page)
200
        }
201
 
202
        if( get_key_press(1 << KEY_PLUS) || get_key_long_rpt_sp((1 << KEY_PLUS),2) )
203
        {
204
            cmd = 0xfd;         // key: links (previous page)
205
        }
206
 
207
        if( get_key_short(1 << KEY_ESC) )
208
        {
209
            cmd = 0xfb;         // key: runter
210
        }
211
 
212
        if( get_key_short(1 << KEY_ENTER) )
213
        {
214
            cmd = 0xf7;         // key: hoch
215
        }
216
 
217
 
218
        if( (hardware == NC) && get_key_long(1 << KEY_ENTER) )
219
        {
220
            set_beep( 25, 0xffff, BeepNormal );                             // kurzer Bestaetigungs-Beep
221
 
222
            if( current_hardware == NC )
223
            {
224
 
225
                MK_SwitchToFC();
226
                redraw = true;
227
            }
228
            else
229
            {
230
 
231
                MK_SwitchToNC();
232
 
233
                MK_SwitchToNC();
234
 
235
                redraw = true;
236
            }
237
//            cmd = 0xff;
238
 
239
            timer2 = 50;
240
            while( timer2 > 0 );
241
        }
242
 
243
 
244
        if( get_key_long(1 << KEY_ESC) )
245
        {
246
            set_beep( 25, 0xffff, BeepNormal );                             // kurzer Bestaetigungs-Beep
247
            exit = true;
248
        }
249
    }
250
    while( (!exit) && timer );
251
 
252
 
253
    mode = 0;
254
    rxd_buffer_locked = FALSE;
255
 
256
 
257
    //------------------------------------------
258
    // Timeout?
259
    //------------------------------------------
260
    if( !timer )
261
    {   // timeout occured
262
      //PKT_Message_Datenverlust( timeout, beep)
263
        PKT_Message_Datenverlust( 500, true);       // 500 = 5 Sekunden
264
    }
265
 
266
    clear_key_all();
267
}