#include <ctype.h>
#include "wl_api.h"
#include "intc.h"
#include "board.h"
#include "printf-stdarg.h"
#include "print_funcs.h"
#include "console.h"
#include "timer.h"
#include "wl_util.h"
#include "gui.h"
#include "et024006dhu.h"
Go to the source code of this file.
Defines | |
#define | CURSOR_BG_COLOR BLUE |
#define | CURSOR_FG_COLOR WHITE |
#define | GS_MAX_ROWS 4 |
#define | MAX_LINE_LEN 37 |
#define | SCROLL_BG_COLOR WHITE |
#define | SCROLL_DISP_LINES 11 |
#define | SCROLL_FG_COLOR BLACK |
#define | SCROLL_H 160 |
#define | SCROLL_W 320 |
#define | SCROLL_X 0 |
#define | SCROLL_Y 40 |
Functions | |
static void | gs_button_0 () |
static void | gs_button_1 () |
static void | gs_button_2 () |
static void | gs_button_3 () |
static void | gs_button_4 () |
void | gui_display_getstring (void) |
void | gui_getstring (getstring_cb cb, void *ctx) |
Variables | |
char | char_array [][30] |
char | func_row [][16] |
struct { | |
int col | |
int colstart | |
int escape | |
int ready | |
int row | |
int rowstart | |
} | get_string_data |
char | getstring [MAX_LINE_LEN] |
int | gs_idx = 0 |
short | mod |
short | redisplay = FALSE |
#define CURSOR_BG_COLOR BLUE |
Definition at line 52 of file gui_getstring.c.
#define CURSOR_FG_COLOR WHITE |
Definition at line 53 of file gui_getstring.c.
#define GS_MAX_ROWS 4 |
Definition at line 55 of file gui_getstring.c.
Referenced by gs_button_2(), gs_button_3(), gs_button_4(), and gui_display_getstring().
#define MAX_LINE_LEN 37 |
Definition at line 78 of file gui_getstring.c.
#define SCROLL_BG_COLOR WHITE |
Definition at line 50 of file gui_getstring.c.
#define SCROLL_DISP_LINES 11 |
Definition at line 77 of file gui_getstring.c.
#define SCROLL_FG_COLOR BLACK |
Definition at line 51 of file gui_getstring.c.
#define SCROLL_H 160 |
Definition at line 49 of file gui_getstring.c.
#define SCROLL_W 320 |
Definition at line 48 of file gui_getstring.c.
#define SCROLL_X 0 |
Definition at line 46 of file gui_getstring.c.
#define SCROLL_Y 40 |
Definition at line 47 of file gui_getstring.c.
static void gs_button_0 | ( | ) | [static] |
Definition at line 98 of file gui_getstring.c.
References char_array, get_string_data, MAX_LINE_LEN, mod, redisplay, and TRUE.
Referenced by gui_getstring().
00099 { 00100 /* Left */ 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 }
static void gs_button_1 | ( | ) | [static] |
Definition at line 118 of file gui_getstring.c.
References char_array, get_string_data, MAX_LINE_LEN, mod, redisplay, and TRUE.
Referenced by gui_getstring().
00119 { 00120 /* Right */ 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 }
static void gs_button_2 | ( | ) | [static] |
Definition at line 138 of file gui_getstring.c.
References char_array, get_string_data, GS_MAX_ROWS, MAX_LINE_LEN, mod, redisplay, SCROLL_DISP_LINES, and TRUE.
Referenced by gui_getstring().
00139 { 00140 /* up */ 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 }
static void gs_button_3 | ( | ) | [static] |
Definition at line 167 of file gui_getstring.c.
References char_array, get_string_data, GS_MAX_ROWS, MAX_LINE_LEN, mod, redisplay, SCROLL_DISP_LINES, and TRUE.
Referenced by gui_getstring().
00168 { 00169 /* dwn */ 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 }
static void gs_button_4 | ( | ) | [static] |
Definition at line 194 of file gui_getstring.c.
References char_array, FALSE, get_string_data, getstring, gs_idx, GS_MAX_ROWS, gui_set_title(), mod, and TRUE.
Referenced by gui_getstring().
00195 { 00196 /* enter */ 00197 00198 char chr; 00199 00200 if (get_string_data.row == GS_MAX_ROWS) 00201 { 00202 /* Edit function row */ 00203 if (get_string_data.col == 0) /* back */ 00204 { 00205 get_string_data.ready = TRUE; 00206 get_string_data.escape = TRUE; 00207 } 00208 else if (get_string_data.col == 1) /* delete */ 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) /* accept */ 00216 { 00217 get_string_data.ready = TRUE; 00218 get_string_data.escape = FALSE; 00219 } 00220 } 00221 else 00222 { 00223 /* add current char */ 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); /* col,line */ 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); /* col,line */ 00237 #else 00238 gui_set_title(getstring, 1); 00239 #endif 00240 mod = TRUE; 00241 }
void gui_display_getstring | ( | void | ) |
Definition at line 310 of file gui_getstring.c.
References bg_color, char_array, CURSOR_BG_COLOR, CURSOR_FG_COLOR, FALSE, func_row, get_string_data, getstring, GS_MAX_ROWS, MAX_LINE_LEN, redisplay, SCROLL_BG_COLOR, SCROLL_DISP_LINES, SCROLL_FG_COLOR, SCROLL_X, SCROLL_Y, and str.
Referenced by gui_draw().
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); /* col,line */ 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); /* col,line */ 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); /* col,line */ 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); /* col,line */ 00367 dip204_write_string(" "); 00368 dip204_set_cursor_position(1,1); /* col,line */ 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); /* col,line */ 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); /* col,line */ 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 }
void gui_getstring | ( | getstring_cb | cb, | |
void * | ctx | |||
) |
Definition at line 244 of file gui_getstring.c.
References FALSE, get_string_data, getstring, gs_button_0(), gs_button_1(), gs_button_2(), gs_button_3(), gs_button_4(), gui_getstring_onoff(), gui_restore_buttons(), gui_save_buttons(), gui_set_button(), gui_set_title(), redisplay, and TRUE.
Referenced by gui_connect_cb(), and gui_exec().
00244 { 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 // Fallthrough 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 }
char char_array[][30] |
Initial value:
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", "0123456789", "!\"#$%&'()*+,-./:;<=>?@", "XXX" }
Definition at line 57 of file gui_getstring.c.
Referenced by gs_button_0(), gs_button_1(), gs_button_2(), gs_button_3(), gs_button_4(), and gui_display_getstring().
int col |
int colstart |
Definition at line 86 of file gui_getstring.c.
int escape |
Definition at line 83 of file gui_getstring.c.
char func_row[][16] |
Initial value:
{ "<BAC>", "<DEL>", "<ACC>" }
Definition at line 66 of file gui_getstring.c.
Referenced by gui_display_getstring().
struct { ... } get_string_data |
Referenced by gs_button_0(), gs_button_1(), gs_button_2(), gs_button_3(), gs_button_4(), gui_display_getstring(), and gui_getstring().
char getstring[MAX_LINE_LEN] |
Definition at line 94 of file gui_getstring.c.
Referenced by gs_button_4(), gui_display_getstring(), and gui_getstring().
int gs_idx = 0 |
short mod |
Definition at line 129 of file gui.c.
Referenced by gs_button_0(), gs_button_1(), gs_button_2(), gs_button_3(), and gs_button_4().
int ready |
Definition at line 82 of file gui_getstring.c.
short redisplay = FALSE |
Definition at line 92 of file gui_getstring.c.
Referenced by gs_button_0(), gs_button_1(), gs_button_2(), gs_button_3(), gui_display_getstring(), and gui_getstring().
int row |
Definition at line 85 of file gui_getstring.c.
int rowstart |
Definition at line 84 of file gui_getstring.c.