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[MAX_LINE_LEN];
00095
00096 int gs_idx = 0;
00097
00098 static void gs_button_0()
00099 {
00100
00101 get_string_data.col--;
00102
00103 if (get_string_data.col < 0) {
00104 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00105 if (get_string_data.colstart < get_string_data.col - MAX_LINE_LEN + 1) {
00106 get_string_data.colstart = get_string_data.col - MAX_LINE_LEN + 1 ;
00107 redisplay = TRUE;
00108 }
00109 }
00110
00111 if (get_string_data.col < get_string_data.colstart) {
00112 get_string_data.colstart--;
00113 redisplay = TRUE;
00114 }
00115 mod = TRUE;
00116 }
00117
00118 static void gs_button_1()
00119 {
00120
00121 get_string_data.col++;
00122
00123 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00124 get_string_data.col = 0;
00125 if (get_string_data.colstart > 0) {
00126 get_string_data.colstart = 0;
00127 redisplay = TRUE;
00128 }
00129 }
00130
00131 if (get_string_data.col >= get_string_data.colstart + MAX_LINE_LEN) {
00132 get_string_data.colstart++;
00133 redisplay = TRUE;
00134 }
00135 mod = TRUE;
00136 }
00137
00138 static void gs_button_2()
00139 {
00140
00141 get_string_data.row--;
00142
00143 if (get_string_data.row < 0)
00144 get_string_data.row = GS_MAX_ROWS;
00145
00146 if (get_string_data.row < get_string_data.rowstart) {
00147 get_string_data.rowstart--;
00148 redisplay = TRUE;
00149 }
00150
00151 if (get_string_data.row > get_string_data.rowstart + SCROLL_DISP_LINES) {
00152 get_string_data.rowstart = get_string_data.row - SCROLL_DISP_LINES;
00153 redisplay = TRUE;
00154 }
00155
00156 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00157 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00158 if (get_string_data.col < MAX_LINE_LEN) {
00159 get_string_data.colstart = 0;
00160 redisplay = TRUE;
00161 }
00162 }
00163
00164 mod = TRUE;
00165 }
00166
00167 static void gs_button_3()
00168 {
00169
00170
00171 get_string_data.row++;
00172
00173 if (get_string_data.row > GS_MAX_ROWS) {
00174 get_string_data.row = 0;
00175 get_string_data.rowstart = 0;
00176 redisplay = TRUE;
00177 }
00178 if (get_string_data.row > get_string_data.rowstart + SCROLL_DISP_LINES) {
00179 get_string_data.rowstart = get_string_data.row - SCROLL_DISP_LINES;
00180 redisplay = TRUE;
00181 }
00182
00183 if (get_string_data.col >= strlen(char_array[get_string_data.row])) {
00184 get_string_data.col = strlen(char_array[get_string_data.row]) - 1;
00185 if (get_string_data.col < MAX_LINE_LEN) {
00186 get_string_data.colstart = 0;
00187 redisplay = TRUE;
00188 }
00189 }
00190
00191 mod = TRUE;
00192 }
00193
00194 static void gs_button_4()
00195 {
00196
00197
00198 char chr;
00199
00200 if (get_string_data.row == GS_MAX_ROWS)
00201 {
00202
00203 if (get_string_data.col == 0)
00204 {
00205 get_string_data.ready = TRUE;
00206 get_string_data.escape = TRUE;
00207 }
00208 else if (get_string_data.col == 1)
00209 {
00210 gs_idx--;
00211 if (gs_idx < 0) gs_idx = 0;
00212 getstring[gs_idx] = 0;
00213 gui_set_title(getstring, 1);
00214 }
00215 else if (get_string_data.col == 2)
00216 {
00217 get_string_data.ready = TRUE;
00218 get_string_data.escape = FALSE;
00219 }
00220 }
00221 else
00222 {
00223
00224 chr = char_array[get_string_data.row][get_string_data.col];
00225 getstring[gs_idx] = chr;
00226 gs_idx++;
00227 if (gs_idx > sizeof getstring) {
00228 gs_idx = sizeof getstring;
00229 }
00230 getstring[gs_idx] = 0;
00231 }
00232 #if BOARD == EVK1100
00233 dip204_set_cursor_position(1,1);
00234 dip204_write_string(getstring);
00235 dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
00236 get_string_data.row + 2 - get_string_data.rowstart);
00237 #else
00238 gui_set_title(getstring, 1);
00239 #endif
00240 mod = TRUE;
00241 }
00242
00243
00244 void gui_getstring(getstring_cb cb, void *ctx) {
00245 static enum { IDLE, INIT, POLLING, FINISH } state = IDLE;
00246 static getstring_cb saved_cb;
00247 static void *cb_ctx;
00248 switch (state)
00249 {
00250 case IDLE:
00251 if (cb) {
00252 saved_cb = cb;
00253 cb_ctx = ctx;
00254 state = INIT;
00255 }
00256 else {
00257 return;
00258 }
00259
00260 case INIT: {
00261 gui_save_buttons();
00262 #if BOARD == EVK1100
00263 dip204_clear_display();
00264 redisplay = TRUE;
00265 #endif
00266 gui_set_title("Enter preshared key", 0);
00267 gui_set_title(getstring, 1);
00268 gui_set_button(0, "Left", sizeof "Left",gs_button_0);
00269 gui_set_button(1, "Right", sizeof "Right", gs_button_1);
00270 gui_set_button(2, "Up", sizeof "Up", gs_button_2);
00271 gui_set_button(3, "Down", sizeof "Down", gs_button_3);
00272 gui_set_button(4, "Enter", sizeof "Enter", gs_button_4);
00273
00274 get_string_data.col = 0;
00275 get_string_data.row = 0;
00276 get_string_data.colstart = 0;
00277 get_string_data.rowstart = 0;
00278 get_string_data.ready = FALSE;
00279 get_string_data.escape = FALSE;
00280
00281 gui_getstring_onoff(TRUE);
00282 state = POLLING;
00283 break;
00284 }
00285 case POLLING:
00286 if (get_string_data.ready) {
00287 state = FINISH;
00288 }
00289 break;
00290 case FINISH:
00291 gui_getstring_onoff(FALSE);
00292 gui_restore_buttons();
00293 if (get_string_data.escape)
00294 saved_cb(NULL, 0, cb_ctx);
00295 else
00296 saved_cb(getstring, strlen(getstring), cb_ctx);
00297 saved_cb = NULL;
00298 cb_ctx = NULL;
00299 state = IDLE;
00300 break;
00301 }
00302
00303 return;
00304 }
00305
00306
00307
00308
00309
00310 void gui_display_getstring(void)
00311 {
00312 int j;
00313 int i;
00314 #if BOARD != EVK1100
00315 int fg_color, bg_color;
00316 #endif
00317 char str[22];
00318
00319 #if BOARD == EVK1100
00320 if (redisplay) {
00321 dip204_clear_display();
00322 for (j = 0; j <= SCROLL_DISP_LINES; j++) {
00323 strncpy(str, &(char_array[get_string_data.rowstart+j][get_string_data.colstart]), MAX_LINE_LEN);
00324 str[MAX_LINE_LEN] = '\0';
00325 dip204_set_cursor_position(1,j+2);
00326 dip204_write_string(str);
00327 }
00328 }
00329 #else
00330 for (j = 0; j < GS_MAX_ROWS; j++) {
00331 for (i = 0; i < strlen(char_array[j]); i++) {
00332 if (get_string_data.row == j && get_string_data.col == i) {
00333 fg_color = CURSOR_FG_COLOR;
00334 bg_color = CURSOR_BG_COLOR;
00335 } else {
00336 fg_color = SCROLL_FG_COLOR;
00337 bg_color = SCROLL_BG_COLOR;
00338 }
00339 str[0] = char_array[j][i];
00340 str[1] = 0;
00341 et024006_PrintString(str,
00342 (const unsigned char*)&FONT8x8,
00343 (i+1)*10+SCROLL_X + 10,
00344 (j+1)*12+SCROLL_Y,
00345 fg_color,
00346 bg_color);
00347 }
00348 }
00349 #endif
00350
00351 #if BOARD == EVK1100
00352 if (redisplay){
00353 if (get_string_data.rowstart == GS_MAX_ROWS - SCROLL_DISP_LINES) {
00354 dip204_set_cursor_position(1,1);
00355 dip204_write_string(" ");
00356 j = 1;
00357 for (i = 0; i < (sizeof func_row/sizeof func_row[0]); i++) {
00358 dip204_set_cursor_position(j,get_string_data.rowstart + SCROLL_DISP_LINES);
00359 dip204_write_string(func_row[i]);
00360 j += strlen(func_row[i]);
00361 }
00362 }
00363 redisplay = FALSE;
00364 }
00365
00366 dip204_set_cursor_position(1,1);
00367 dip204_write_string(" ");
00368 dip204_set_cursor_position(1,1);
00369 dip204_write_string(getstring);
00370 if (get_string_data.row == GS_MAX_ROWS) {
00371 dip204_set_cursor_position(get_string_data.col * strlen(func_row[0]) + 2, GS_MAX_ROWS);
00372 } else {
00373 dip204_set_cursor_position(get_string_data.col + 1 - get_string_data.colstart,
00374 get_string_data.row + 2 - get_string_data.rowstart);
00375 }
00376 dip204_show_cursor();
00377 #else
00378 j = 1;
00379 for (i = 0; i < (sizeof func_row/sizeof func_row[0]); i++) {
00380 if (get_string_data.row == GS_MAX_ROWS && get_string_data.col == i) {
00381 fg_color = CURSOR_FG_COLOR;
00382 bg_color = CURSOR_BG_COLOR;
00383 } else {
00384 fg_color = SCROLL_FG_COLOR;
00385 bg_color = SCROLL_BG_COLOR;
00386 }
00387 et024006_PrintString(func_row[i],
00388 (const unsigned char*)&FONT8x8,
00389 j*10 + SCROLL_X + 10,
00390 5*12+SCROLL_Y,
00391 fg_color,
00392 bg_color);
00393 j += strlen(func_row[i])-1;
00394 }
00395 #endif
00396 }