-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD_DATA_ENTRY.java
More file actions
executable file
·199 lines (182 loc) · 6.4 KB
/
LCD_DATA_ENTRY.java
File metadata and controls
executable file
·199 lines (182 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* LCD_DATA_ENTRY.java
* hold the data field format info for keypad data entry
*
* Created on January 8, 2007, 12:03 PM
*/
/**
* @author Chen-Fu Liao
* Sr. Systems Engineer
* ITS Institute, ITS Laboratory
* Center For Transportation Studies
* University of Minnesota
* 200 Transportation and Safety Building
* 511 Washington Ave. SE
* Minneapolis, MN 55455
*/
public class LCD_DATA_ENTRY {
public char[][] PAGE_CHARS = new char[16][40] ; // 16 lines x 40 char LCD array
public int page_ID = 0 ;
public int lcd_page_index = -1 ;
public int startRow = -1 ;
public int rowLength = 0 ;
public int row_index = -1 ; // cursor location y
public int col_index = -1 ; // cursor location x
public int data_mode = -1 ; // 1-numerical data(*), 2-Text(T), 3-Toggle(X), 4-^ special char
// 5-& 3-digit number, 6-% float ##.# number ex. "45.6"
public int num_key_pressed = 0 ;
/** Creates a new instance of LCD_DATA_ENTRY */
public LCD_DATA_ENTRY() {
for (int i=0; i<16; i++) {
for (int j=0; j<40; j++) {
PAGE_CHARS[i][j] = ' ' ; // init to ' ' space
} // j
} // i
}
public void cursorInit() {
// exe every 500 ms
if (row_index<0 || col_index<0) {
// move to beginneing or data entry field
row_index = startRow ;
col_index = getStartCol(0) ;
} // if
} // cursorInit subroutine
public void moveCursorLeft() {
if (row_index<0 || col_index<0) {
// move to beginneing or data entry field
row_index = startRow ;
col_index = getStartCol(0) ;
} else {
// find next left data field
for (int j=col_index-1; j>=0; j--) {
if (PAGE_CHARS[row_index][j] != ' ') {
col_index = j ;
update_data_mode(PAGE_CHARS[row_index][col_index]) ;
break ;
}
} // for j
} // if
num_key_pressed = 0 ;
//System.out.println("cur row, col="+row_index+","+col_index );
} // move cursor left
public void moveCursorRight() {
if (row_index<0 || col_index<0) {
// move to beginneing or data entry field
row_index = startRow ;
col_index = getStartCol(0) ;
} else {
// find next right data field
for (int j=col_index+1; j<40; j++) {
if (PAGE_CHARS[row_index][j] != ' ') {
col_index = j ;
update_data_mode(PAGE_CHARS[row_index][col_index]) ;
break ;
}
} // for j
} // if
num_key_pressed = 0 ;
//System.out.println("cur row, col="+row_index+","+col_index );
} // move cursor right
public void moveCursorUp() {
if (row_index<0 || col_index<0) {
// move to beginneing or data entry field
row_index = startRow ;
col_index = getStartCol(0) ;
} else {
// find next up data field
for (int i=row_index-1; i>=0; i--) {
if (isFormatExists(i)) {
row_index = i ;
findNextCol() ;
break ;
} // format exists
} // for i
} // if
num_key_pressed = 0 ;
} // moveCursorUp
public void moveCursorDown() {
if (row_index<0 || col_index<0) {
// move to beginneing or data entry field
row_index = startRow ;
col_index = getStartCol(0) ;
} else {
// find next up data field
for (int i=row_index+1; i<16; i++) {
if (isFormatExists(i)) {
row_index = i ;
findNextCol() ;
break ;
} // format exists
} // for i
} // if
num_key_pressed = 0 ;
} // moveCursorDown
private boolean isFormatExists(int row) {
boolean state = false ;
for (int j=0; j<40; j++) {
if (PAGE_CHARS[row][j] != ' ') {
state = true ;
break ;
} // if
} // for
return state ;
} // isFormatExists sub
private int getStartCol(int col_index) {
int idx = -1 ;
for (int i=col_index; i<40; i++) {
if (PAGE_CHARS[startRow][i] != ' ') {
idx = i ;
update_data_mode(PAGE_CHARS[startRow][i]) ;
break ;
} // if char not equal to blanl ' '
} // for
System.out.println("start row, col="+row_index+","+idx );
return idx ;
} // findStartCol
private void update_data_mode(char my_char) {
switch (my_char) {
case '*':
data_mode = 1 ; // 2-digit numerical data
break ;
case 'T':
data_mode = 2 ; // TEXT
break ;
case 'X':
data_mode = 3 ; // toggle
break ;
case '^':
data_mode = 4 ; // special ^
break ;
case '&':
data_mode = 5 ; // 3-digit number
break ;
case '%':
data_mode = 6 ; // 3-digit float eg. 45.6
break ;
default:
System.out.println("LCD_DATA_ENTRY Format error: "+my_char) ;
}
} // update data mode
private void findNextCol() {
boolean isEmpty = true ;
for (int j=col_index; j>=0; j--) {
if (PAGE_CHARS[row_index][j] != ' ') {
col_index = j ;
update_data_mode(PAGE_CHARS[row_index][col_index]) ;
isEmpty = false ;
break ;
}
} // for j
if (isEmpty) {
// try search in right direction
for (int j=col_index+1; j<40; j++) {
if (PAGE_CHARS[row_index][j] != ' ') {
col_index = j ;
update_data_mode(PAGE_CHARS[row_index][col_index]) ;
break ;
}
} // for j
} // if empty?
//System.out.println("cur row, col="+row_index+","+col_index );
} // findNextCol
}