~ubuntu-branches/ubuntu/quantal/cobalt-panel-utils/quantal

« back to all changes in this revision

Viewing changes to lib/lcdnet.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2006-09-23 17:58:08 UTC
  • Revision ID: james.westby@ubuntu.com-20060923175808-1y364v1jk38av0yp
Tags: upstream-1.0.2
Import upstream version 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
 
3
 *
 
4
 * Use is subject to the GNU Lesser General Public License, Version 2.1,
 
5
 * February 1999, which is contained in the read-me file named
 
6
 * "README_GNU_LGPL." This library is free software; you can
 
7
 * redistribute it and/or modify it under the terms of the GNU
 
8
 * Lesser General Public License as published by the Free Software
 
9
 * Foundation; either version 2.1 of the License, or (at your
 
10
 * option) any later version. This library is distributed in the
 
11
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without
 
12
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 
13
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 
14
 * for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free
 
18
 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
19
 * MA  02111-1307  USA.
 
20
 *
 
21
 * read functions for the lcd. we handle both buttons and 
 
22
 * reading from the panel. */
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include <sys/time.h>
 
27
#include <sys/types.h>
 
28
#include <unistd.h>
 
29
#include "lcdutils.h"
 
30
#include "lcd_private.h"
 
31
 
 
32
void lcd_rev_format( char *in ) {
 
33
        int  one, two, three, four;
 
34
        
 
35
        sscanf(in,"%d.%d.%d.%d", &one, &two, &three, &four);
 
36
        if (one > 255) one = 0;
 
37
        if (two > 255) two = 0;
 
38
        if (three > 255) three = 0;
 
39
        if (four > 255) four = 0;
 
40
        sprintf(in,"%03d.%03d.%03d.%03d",one,two,three,four);
 
41
 
42
 
 
43
 
 
44
int lcd_netbutton(void *lcd) {
 
45
        int     firstdigit = 0;
 
46
        int   button, i, ctr=0;
 
47
        
 
48
        lcd_set(lcd, LCD_Cursor_On);
 
49
        while( 1 ) {
 
50
                button = lcd_readbutton(lcd) & 0x00FF;
 
51
                if ( (button != BUTTON_NONE) && (button != BUTTON_NONE_B) ) {
 
52
                        ctr++;
 
53
                        if ( (ctr==lcd_button_debounce(lcd)) ) {
 
54
                                switch (button) {
 
55
                                        case BUTTON_Left:
 
56
                                        case BUTTON_Left_B:
 
57
                                                i = lcd_getcursorpos(lcd);
 
58
                                                if (i != 0x40) {
 
59
                                                        lcd_set(lcd, LCD_Cursor_Left);
 
60
                                                        i = lcd_getcursor(lcd);
 
61
                                                        if (i == '.')
 
62
                                                                lcd_set(lcd, LCD_Cursor_Left);
 
63
                                                }
 
64
                                                break;
 
65
                                        
 
66
                                        case BUTTON_Right:
 
67
                                        case BUTTON_Right_B:
 
68
                                                i = lcd_getcursorpos(lcd);
 
69
                                                if (i != 0x4E) {
 
70
                                                        lcd_set(lcd, LCD_Cursor_Right);
 
71
                                                        i = lcd_getcursor(lcd);
 
72
                                                        if (i == '.')
 
73
                                                                lcd_set(lcd, LCD_Cursor_Right);
 
74
                                                }
 
75
                                                break;
 
76
                                        
 
77
                                        case BUTTON_Up:
 
78
                                        case BUTTON_Up_B:
 
79
                                                i = lcd_getcursorpos(lcd);
 
80
                                                firstdigit = 0;
 
81
                                                firstdigit = ( i == 0x40 ) || ( i == 0x44 ) || ( i == 0x48 ) || ( i == 0x4C );
 
82
                                                i = lcd_getcursor(lcd);
 
83
                                                if (i == '9')
 
84
                                                        i = '0';
 
85
                                                else if ((i == '2') && (firstdigit))
 
86
                                                        i = '0';
 
87
                                                else    
 
88
                                                        i++;
 
89
                                                lcd_setcursor(lcd, i);
 
90
                                                break;
 
91
                                        
 
92
                                        case BUTTON_Down:
 
93
                                        case BUTTON_Down_B:
 
94
                                                i = lcd_getcursorpos(lcd);
 
95
                                                firstdigit = 0;
 
96
                                                firstdigit = ( i == 0x40 ) || ( i == 0x44 ) || ( i == 0x48 ) || ( i == 0x4C );
 
97
                                                i = lcd_getcursor(lcd);
 
98
                                                if ((i == '0') && (!firstdigit))
 
99
                                                        i = '9';
 
100
                                                else if ((i == '0') && (firstdigit))
 
101
                                                        i = '2'; 
 
102
                                                else
 
103
                                                        i--;
 
104
                                                lcd_setcursor(lcd, i);
 
105
                                                break;
 
106
                                        
 
107
                                        case BUTTON_Next:
 
108
                                        case BUTTON_Next_B:
 
109
                                                break;
 
110
                                        
 
111
                                        case BUTTON_Enter:
 
112
                                        case BUTTON_Enter_B:
 
113
                                                lcd_getdisplay(lcd, NULL, NULL, &i);
 
114
                                                return i;
 
115
                                                break;
 
116
                                }
 
117
                                lcd_netcorrect(lcd);
 
118
                        }
 
119
                        if (ctr==lcd_button_sense(lcd)) {
 
120
                                ctr=0;
 
121
                        }
 
122
                }
 
123
                else {
 
124
                        ctr=0;
 
125
                }
 
126
        }
 
127
}
 
128
 
 
129
static void mangle_num(char *line) {
 
130
        char *first = line + 1, *second = line + 2;
 
131
        
 
132
        if ( *line == '2' ) {
 
133
                if ( *first == '9' )
 
134
                        *first = '5';
 
135
                else if ( *first > '5' )
 
136
                        *first = '0';
 
137
                else if (*first == '5') {
 
138
                        if (*second == '9') 
 
139
                                *second = '5';
 
140
                        else if (*second > '5') 
 
141
                                *second = '0';
 
142
                }  
 
143
        }
 
144
}
 
145
 
 
146
void lcd_netcorrect(void *lcd) {
 
147
        char last_address;
 
148
        char *line1, last_line1[LCD_CHARS_PER_LINE];
 
149
        char *line2, last_line2[LCD_CHARS_PER_LINE];
 
150
        
 
151
        last_address = lcd_getcursorpos(lcd);
 
152
        lcd_getdisplay(lcd, &line1, &line2, NULL);
 
153
        strcpy(last_line1, line1); 
 
154
        strcpy(last_line2, line2); 
 
155
        
 
156
        
 
157
        mangle_num(last_line2);
 
158
        mangle_num(last_line2 + 4);
 
159
        mangle_num(last_line2 + 8);
 
160
        mangle_num(last_line2 + 12);
 
161
        lcd_write(lcd, last_line1, last_line2);
 
162
        lcd_setcursorpos(lcd, last_address);
 
163
        lcd_set(lcd, LCD_Cursor_On);
 
164
}