00001
00028 #include <ctype.h>
00029
00030 #include "wl_api.h"
00031 #include "intc.h"
00032 #include "board.h"
00033 #include "printf-stdarg.h"
00034 #include "print_funcs.h"
00035 #include "console.h"
00036 #include "timer.h"
00037 #include "wl_util.h"
00038 #include "gui.h"
00039 #if BOARD == EVK1104 || BOARD == EVK1105
00040 #include "et024006dhu.h"
00041 #endif
00042 #if BOARD == EVK1100
00043 #include "dip204.h"
00044 #endif
00045
00046 #define SCROLL_X 0
00047 #define SCROLL_Y 40
00048 #define SCROLL_W 320
00049 #define SCROLL_H 160
00050 #define SCROLL_BG_COLOR WHITE
00051 #define SCROLL_FG_COLOR BLACK
00052 #define CURSOR_BG_COLOR BLUE
00053 #define CURSOR_FG_COLOR WHITE
00054
00055 #define GS_MAX_ROWS 4
00056
00057 char char_array[][30] =
00058 {
00059 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
00060 "abcdefghijklmnopqrstuvwxyz",
00061 "0123456789",
00062 "!\"#$%&'()*+,-./:;<=>?@",
00063 "XXX"
00064 };
00065
00066 char func_row[][16] =
00067 {
00068 "<BAC>",
00069 "<DEL>",
00070 "<ACC>"
00071 };
00072
00073 #if BOARD == EVK1100
00074 #define SCROLL_DISP_LINES 2
00075 #define MAX_LINE_LEN 20
00076 #else
00077 #define SCROLL_DISP_LINES 11
00078 #define MAX_LINE_LEN 37
00079 #endif
00080
00081 struct {
00082 int ready;
00083 int escape;
00084 int rowstart;
00085 int row;
00086 int colstart;
00087 int col;
00088 } get_string_data;
00089
00090
00091 extern short mod;
00092 short redisplay = FALSE;
00093
00094 char *getstring;
00095 int gs_max_len;
00096
00097 int gs_idx = 0;
00098
00099 static void gs_button_0()
00100 {
00101
00102 get_string_data.col--;
00103
00104 if (get_string_data.col < 0) {
00105 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00106 if (get_string_data.colstart < get_string_data.col - MAX_LINE_LEN + 1) {
00107 get_string_data.colstart = get_string_data.col - MAX_LINE_LEN + 1 ;
00108 redisplay = TRUE;
00109 }
00110 }
00111
00112 if (get_string_data.col < get_string_data.colstart) {
00113 get_string_data.colstart--;
00114 redisplay = TRUE;
00115 }
00116 mod = TRUE;
00117 }
00118
00119 static void gs_button_1()
00120 {
00121
00122 get_string_data.col++;
00123
00124 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00125 get_string_data.col = 0;
00126 if (get_string_data.colstart > 0) {
00127 get_string_data.colstart = 0;
00128 redisplay = TRUE;
00129 }
00130 }
00131
00132 if (get_string_data.col >= get_string_data.colstart + MAX_LINE_LEN) {
00133 get_string_data.colstart++;
00134 redisplay = TRUE;
00135 }
00136 mod = TRUE;
00137 }
00138
00139 static void gs_button_2()
00140 {
00141
00142 get_string_data.row--;
00143
00144 if (get_string_data.row < 0)
00145 get_string_data.row = GS_MAX_ROWS;
00146
00147 if (get_string_data.row < get_string_data.rowstart) {
00148 get_string_data.rowstart--;
00149 redisplay = TRUE;
00150 }
00151
00152 if (get_string_data.row > get_string_data.rowstart + SCROLL_DISP_LINES) {
00153 get_string_data.rowstart = get_string_data.row - SCROLL_DISP_LINES;
00154 redisplay = TRUE;
00155 }
00156
00157 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00158 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00159 if (get_string_data.col < MAX_LINE_LEN) {
00160 get_string_data.colstart = 0;
00161 redisplay = TRUE;
00162 }
00163 }
00164
00165 mod = TRUE;
00166 }
00167
00168 static void gs_button_3()
00169 {
00170
00171
00172 get_string_data.row++;
00173
00174 if (get_string_data.row > GS_MAX_ROWS) {
00175 get_string_data.row = 0;
00176 get_string_data.rowstart = 0;
00177 redisplay = TRUE;
00178 }
00179 if (get_string_data.row > get_string_data.rowstart + SCROLL_DISP_LINES) {
00180 get_string_data.rowstart = get_string_data.row - SCROLL_DISP_LINES;
00181 redisplay = TRUE;
00182 }
00183
00184 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00185 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00186 if (get_string_data.col < MAX_LINE_LEN) {
00187 get_string_data.colstart = 0;
00188 redisplay = TRUE;
00189 }
00190 }
00191
00192 mod = TRUE;
00193 }
00194
00195 static void gs_button_4()
00196 {
00197
00198
00199 char chr;
00200
00201 if (get_string_data.row == GS_MAX_ROWS)
00202 {
00203
00204 if (get_string_data.col == 0)
00205 {
00206 get_string_data.ready = TRUE;
00207 get_string_data.escape = TRUE;
00208 }
00209 else if (get_string_data.col == 1)
00210 {
00211 gs_idx--;
00212 if (gs_idx < 0) gs_idx = 0;
00213 getstring[gs_idx] = 0;
00214 gui_set_title(getstring, 1);
00215 }
00216 else if (get_string_data.col == 2)
00217 {
00218 get_string_data.ready = TRUE;
00219 get_string_data.escape = FALSE;
00220 }
00221 }
00222 else
00223 {
00224
00225 chr = char_array[get_string_data.row][get_string_data.col];
00226 getstring[gs_idx] = chr;
00227 gs_idx++;
00228 if (gs_idx > gs_max_len) gs_idx = gs_max_len;
00229 getstring[gs_idx] = 0;
00230 }
00231 #if BOARD == EVK1100
00232 dip204_set_cursor_position(1,1);
00233 dip204_write_string(getstring);
00234 dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
00235 get_string_data.row + 2 - get_string_data.rowstart);
00236 #else
00237 gui_set_title(getstring, 1);
00238 #endif
00239 mod = TRUE;
00240 }
00241
00242
00243 void poll(uint8_t flags);
00244
00245 Bool gui_getstring(char *string, int max_len)
00246 {
00247
00248 getstring = string;
00249 gs_max_len = max_len;
00250
00251 gui_save_buttons();
00252 #if BOARD == EVK1100
00253 dip204_clear_display();
00254 redisplay = TRUE;
00255 #endif
00256 gui_draw(1);
00257 gui_set_title("Enter preshared key", 0);
00258 gui_set_title(getstring, 1);
00259 gui_set_button(0, "Left", sizeof "Left",gs_button_0);
00260 gui_set_button(1, "Right", sizeof "Right", gs_button_1);
00261 gui_set_button(2, "Up", sizeof "Up", gs_button_2);
00262 gui_set_button(3, "Down", sizeof "Down", gs_button_3);
00263 gui_set_button(4, "Enter", sizeof "Enter", gs_button_4);
00264
00265 get_string_data.col = 0;
00266 get_string_data.row = 0;
00267 get_string_data.colstart = 0;
00268 get_string_data.rowstart = 0;
00269 get_string_data.ready = FALSE;
00270 get_string_data.escape = FALSE;
00271
00272 gui_getstring_onoff(TRUE);
00273 while(!get_string_data.ready)
00274 poll(0);
00275
00276 gui_getstring_onoff(FALSE);
00277 gui_restore_buttons();
00278 if (get_string_data.escape)
00279 return FALSE;
00280 else
00281 return TRUE;
00282
00283 }
00284
00285
00286
00287
00288
00289 void gui_display_getstring(void)
00290 {
00291 int j;
00292 int i;
00293 #if BOARD != EVK1100
00294 int fg_color, bg_color;
00295 #endif
00296 char str[22];
00297
00298 #if BOARD == EVK1100
00299 if (redisplay) {
00300 dip204_clear_display();
00301 for (j = 0; j <= SCROLL_DISP_LINES; j++) {
00302 strncpy(str, &(char_array[get_string_data.rowstart+j][get_string_data.colstart]), MAX_LINE_LEN);
00303 str[MAX_LINE_LEN] = '\0';
00304 dip204_set_cursor_position(1,j+2);
00305 dip204_write_string(str);
00306 }
00307 }
00308 #else
00309 for (j = 0; j < GS_MAX_ROWS; j++) {
00310 for (i = 0; i < strlen(char_array[j]); i++) {
00311 if (get_string_data.row == j && get_string_data.col == i) {
00312 fg_color = CURSOR_FG_COLOR;
00313 bg_color = CURSOR_BG_COLOR;
00314 } else {
00315 fg_color = SCROLL_FG_COLOR;
00316 bg_color = SCROLL_BG_COLOR;
00317 }
00318 str[0] = char_array[j][i];
00319 str[1] = 0;
00320 et024006_PrintString(str,
00321 (const unsigned char*)&FONT8x8,
00322 (i+1)*10+SCROLL_X + 10,
00323 (j+1)*12+SCROLL_Y,
00324 fg_color,
00325 bg_color);
00326 }
00327 }
00328 #endif
00329
00330 #if BOARD == EVK1100
00331 if (redisplay){
00332 if (get_string_data.rowstart == GS_MAX_ROWS - SCROLL_DISP_LINES) {
00333 dip204_set_cursor_position(1,1);
00334 dip204_write_string(" ");
00335 j = 1;
00336 for (i = 0; i < (sizeof func_row/sizeof func_row[0]); i++) {
00337 dip204_set_cursor_position(j,get_string_data.rowstart + SCROLL_DISP_LINES);
00338 dip204_write_string(func_row[i]);
00339 j += strlen(func_row[i]);
00340 }
00341 }
00342 redisplay = FALSE;
00343 }
00344
00345 dip204_set_cursor_position(1,1);
00346 dip204_write_string(" ");
00347 dip204_set_cursor_position(1,1);
00348 dip204_write_string(getstring);
00349 if (get_string_data.row == GS_MAX_ROWS) {
00350 dip204_set_cursor_position(get_string_data.col * strlen(func_row[0]) + 2, GS_MAX_ROWS);
00351 } else {
00352 dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
00353 get_string_data.row + 2 - get_string_data.rowstart);
00354 }
00355 dip204_show_cursor();
00356 #else
00357 j = 1;
00358 for (i = 0; i < (sizeof func_row/sizeof func_row[0]); i++) {
00359 if (get_string_data.row == GS_MAX_ROWS && get_string_data.col == i) {
00360 fg_color = CURSOR_FG_COLOR;
00361 bg_color = CURSOR_BG_COLOR;
00362 } else {
00363 fg_color = SCROLL_FG_COLOR;
00364 bg_color = SCROLL_BG_COLOR;
00365 }
00366 et024006_PrintString(func_row[i],
00367 (const unsigned char*)&FONT8x8,
00368 j*10 + SCROLL_X + 10,
00369 5*12+SCROLL_Y,
00370 fg_color,
00371 bg_color);
00372 j += strlen(func_row[i])-1;
00373 }
00374 #endif
00375 }