Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
724 woggle 1
/*****************************************************************************
2
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
3
 *                                                                           *
4
 *   This program is free software; you can redistribute it and/or modify    *
5
 *   it under the terms of the GNU General Public License as published by    *
6
 *   the Free Software Foundation; either version 2 of the License.          *
7
 *                                                                           *
8
 *   This program is distributed in the hope that it will be useful,         *
9
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
10
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
11
 *   GNU General Public License for more details.                            *
12
 *                                                                           *
13
 *   You should have received a copy of the GNU General Public License       *
14
 *   along with this program; if not, write to the                           *
15
 *   Free Software Foundation, Inc.,                                         *
16
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
17
 *                                                                           *
18
 *****************************************************************************/
19
 
20
#include <avr/io.h>
21
#include <avr/pgmspace.h>
22
#include <util/delay.h>
23
 
24
#include "main.h"
25
#include "lcd.h"
26
#include "usart.h"
27
#include "timer.h"
28
 
29
#include "mk-data-structs.h"
30
 
31
#define TIMEOUT 500     // 5 sec
32
 
33
void display_data (void)
34
{
35
        uint8_t cmd;
36
        uint8_t flag = 0;;
37
 
38
        mode = 'H';
39
 
40
        lcd_cls ();
41
        if (current_hardware == NC)
42
        {
43
                lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  FC"), 0);
44
        }
45
        else
46
        {
47
                if (hardware == FC)
48
                {
49
                        lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit"), 0);
50
                }
51
                else
52
                {
53
                        lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  NC"), 0);
54
                }
55
        }
56
        lcd_printp_at (0, 0, PSTR("Display"), 0);
57
 
58
        rxd_buffer_locked = FALSE;
59
        timer = TIMEOUT;
60
        cmd = 0x03;     // Home = first page
61
 
62
        do
63
        {
64
                SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
65
                cmd = 0;
66
                //LED6_TOGGLE;
67
                _delay_ms (250);
68
 
69
                if (rxd_buffer_locked)
70
                {
71
                        Decode64 ();
72
                        flag = 1;
73
 
74
                        if (!hardware)
75
                        {       // hardware was not detected at startup
76
                                hardware = rxd_buffer[1] - 'a';
77
                                if (hardware == NC)
78
                                {
79
                                        lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  FC"), 0);
80
                                        current_hardware = NC;
81
                                }
82
                                else
83
                                {
84
                                        lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit"), 0);
85
                                        current_hardware = FC;
86
                                }
87
                        }
88
 
89
                        rxd_buffer[24] = 0;
90
 
91
                        lcd_print_at (0, rxd_buffer[3] + 1, (uint8_t *) &rxd_buffer[4], 0);
92
 
93
                        rxd_buffer_locked = FALSE;
94
                        timer = TIMEOUT;
95
                }
96
 
97
                if (get_key_press (1 << KEY_MINUS))
98
                {
99
                        cmd = 0x01;     // next page
100
                        LED1_TOGGLE;
101
                        //SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
102
                        //cmd = 0;
103
                }
104
                else if (get_key_press (1 << KEY_PLUS))
105
                {
106
                        cmd = 0x02;     // previous page
107
                        LED2_TOGGLE;
108
                        //SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
109
                        //cmd = 0;
110
                }
111
                else if ((hardware == NC) && get_key_press (1 << KEY_ENTER))
112
                {
113
                        if (current_hardware == NC)
114
                        {
115
                                SwitchToFC();
116
 
117
                                //timer = TIMEOUT;
118
                                lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  NC"), 0);
119
                                LED3_TOGGLE;
120
                        }
121
                        else
122
                        {
123
                                SwitchToNC();
124
 
125
                                //timer = TIMEOUT;
126
                                lcd_printpns_at (0, 7, PSTR(" \x1c    \x1d     Exit  FC"), 0);
127
                                LED4_TOGGLE;
128
                        }
129
                        cmd = 0x03;     // Home = first page
130
                        //SendOutData('h', ADDRESS_ANY, 1, &cmd, 1);
131
                        //cmd = 0;
132
                }
133
        }
134
        while (!get_key_press (1 << KEY_ESC) && timer);
135
 
136
        get_key_press(KEY_ALL);
137
 
138
        mode = 0;
139
        rxd_buffer_locked = FALSE;
140
 
141
        if (!timer)
142
        {       // timeout occured
143
                if (flag)
144
                {
145
                        lcd_cls ();
146
                }
147
                lcd_printp_at (0, 2, PSTR("ERROR: no data"), 0);
148
 
149
                timer = 100;
150
                while (timer > 0);
151
        }
152
        LED_ALL_OFF;
153
}