gui.h File Reference

#include "pm.h"
#include <stdio.h>
#include "console.h"
#include <stdint.h>

Go to the source code of this file.

Typedefs

typedef void(* button_cb_t )(void)
typedef void(* getstring_cb )(char *str, size_t len, void *ctx)

Functions

void gui_add_infobox_item (const char *str, int line)
void gui_add_scroll_box_item (const char *str, size_t len)
void gui_clear_infobox (short color)
void gui_clear_scroll_box (void)
void gui_dec_scroll_cursor (void)
void gui_del_scroll_box_item (const char *str, size_t len)
void gui_display_pic (void *pic, size_t len)
void gui_draw (int force_draw)
void gui_exec (uint32_t ticks)
int gui_get_scroll_box_focused_item (char **str, size_t *len)
void gui_getstring (getstring_cb cb, void *ctx)
void gui_getstring_onoff (int state)
void gui_inc_scroll_cursor (void)
void gui_infobox_onoff (int state)
int gui_infobox_state (void)
void gui_init (const pm_freq_param_t *pm_freq_param)
void gui_restore_buttons (void)
void gui_save_buttons (void)
int gui_scroll_idx (void)
void gui_set_bg_color (short color)
int gui_set_button (short id, const char *label, size_t len, button_cb_t cb)
void gui_set_title (const char *str, unsigned char line)


Typedef Documentation

typedef void(* button_cb_t)(void)

Definition at line 40 of file gui.h.

typedef void(* getstring_cb)(char *str, size_t len, void *ctx)

Definition at line 43 of file gui.h.


Function Documentation

void gui_add_infobox_item ( const char *  str,
int  line 
)

Definition at line 547 of file gui.c.

References INFO_MAX_LINES, and infobox_contents.

Referenced by gui_status_up_cb().

00548 {
00549         if (line < INFO_MAX_LINES) {
00550                 strncpy(infobox_contents.lines[line], str, sizeof infobox_contents.lines[line]);
00551                 mod = 1;
00552         }
00553 }

void gui_add_scroll_box_item ( const char *  str,
size_t  len 
)

Definition at line 412 of file gui.c.

References cnt, scroll_box_contents, and SCROLL_MAX_LINES.

Referenced by gui_scan_cb(), and gui_start().

00412                                                           {
00413   
00414         int cnt = scroll_box_contents.cnt;
00415         int i;
00416 
00417         if (cnt >= SCROLL_MAX_LINES) return;
00418 
00419         for (i = 0; i < cnt; i++) {
00420                 if (strncmp(str, scroll_box_contents.lines[i], len) == 0) {
00421                         return;
00422                 }
00423         }
00424 
00425         if (len >= sizeof scroll_box_contents.lines[cnt]) {
00426                 len = sizeof scroll_box_contents.lines[cnt] - 1;
00427         }
00428         strncpy(scroll_box_contents.lines[cnt], str, len);
00429         scroll_box_contents.cnt++;
00430         mod = 1;
00431 }

void gui_clear_infobox ( short  color  ) 

Definition at line 541 of file gui.c.

References infobox_contents.

Referenced by gui_status_up_cb().

00542 {
00543         memset(&infobox_contents, 0, sizeof infobox_contents);
00544         infobox_contents.bg_color = color;
00545 }

void gui_clear_scroll_box ( void   ) 

Definition at line 333 of file gui.c.

References scroll_box_contents.

Referenced by gui_scan_cb(), and gui_start().

00334 {
00335   
00336         memset(&scroll_box_contents, 0, sizeof scroll_box_contents);
00337         scroll_box_contents.dispstart = 0;
00338 }

void gui_dec_scroll_cursor ( void   ) 

Definition at line 371 of file gui.c.

References printk(), scroll_box_contents, and SCROLL_DISP_LINES.

Referenced by gui_start().

00372 {
00373 #ifdef DEBUG
00374         printk("dec1: cur:%d,dstrt=%d\n", scroll_box_contents.cursor,
00375                scroll_box_contents.dispstart);
00376 #endif
00377         scroll_box_contents.cursor--;
00378 
00379         if (scroll_box_contents.cursor <= 0)
00380         {
00381                 scroll_box_contents.dispstart = scroll_box_contents.cnt - SCROLL_DISP_LINES;
00382                 if (scroll_box_contents.dispstart < 0) scroll_box_contents.dispstart = 0;
00383                 scroll_box_contents.cursor = scroll_box_contents.cnt - 1;
00384         }
00385         if (scroll_box_contents.cursor < scroll_box_contents.dispstart)
00386         {
00387                 scroll_box_contents.dispstart--;
00388         }
00389 #ifdef DEBUG
00390         printk("dec2: cur:%d,dstrt=%d\n", scroll_box_contents.cursor,
00391                scroll_box_contents.dispstart);
00392 #endif
00393         mod = 1;
00394 }

void gui_del_scroll_box_item ( const char *  str,
size_t  len 
)

Definition at line 435 of file gui.c.

References cnt, printk(), and scroll_box_contents.

00435                                                           {
00436   
00437         int cnt = scroll_box_contents.cnt;
00438         int i;
00439         int moving = 0;
00440 
00441         printk("Delete %s\n", str);
00442         for (i = 0; i < cnt; i++) {
00443                 if (! moving && strncmp(str, scroll_box_contents.lines[i], len) == 0) {
00444                         printk("Found it at %d\n", i);
00445                         /* Now move everything up */
00446                         moving = 1;
00447                 }
00448                 if (moving) {
00449                         if (scroll_box_contents.lines[i+1][0] == '\0') {
00450                                 memset(scroll_box_contents.lines[i], 0, sizeof scroll_box_contents.lines[i]);
00451                                 break;
00452                         }
00453                         printk("Moving \"%s\" to %i\n", scroll_box_contents.lines[i+1], i);
00454                         memcpy(scroll_box_contents.lines[i], scroll_box_contents.lines[i+1],
00455                                strlen(scroll_box_contents.lines[i+1]) + 1);
00456                         memset(scroll_box_contents.lines[i+1], 0, sizeof scroll_box_contents.lines[i+1]);
00457                 }
00458         }
00459         if (i < cnt) {
00460                 scroll_box_contents.cnt--;
00461         }
00462 
00463         mod = 1;
00464 }

void gui_display_pic ( void *  pic,
size_t  len 
)

void gui_draw ( int  force_draw  ) 

Definition at line 705 of file gui.c.

References BUTTON_BG_COLOR, button_contents, BUTTON_FG_COLOR, BUTTON_H, BUTTON_W, BUTTON_X, BUTTON_Y, CURSOR_BG_COLOR, display_mode, gui_display_getstring(), gui_display_infobox(), GUI_GETSTRING, GUI_INFOBOX, GUI_LIST, NUM_BUTTONS, scroll_box_contents, SCROLL_DISP_LINES, SCROLL_FG_COLOR, SCROLL_H, SCROLL_W, SCROLL_X, SCROLL_Y, TITLE_BG_COLOR, title_contents, TITLE_FG_COLOR, TITLE_H, TITLE_W, TITLE_X, and TITLE_Y.

Referenced by gui_exec(), and gui_start().

00705                               {
00706         int i;
00707 
00708         if (! mod) {
00709                 return;
00710         }
00711         mod = 0;
00712 #if BOARD != EVK1100
00713         // Draw title box
00714         et024006_DrawFilledRect(TITLE_X, 
00715                                 TITLE_Y, 
00716                                 TITLE_W,
00717                                 TITLE_H, 
00718                                 TITLE_BG_COLOR);
00719         if (title_contents.title[0][0]) {
00720                 et024006_PrintString(title_contents.title[0],
00721                                      (const unsigned char*)&FONT8x8,
00722                                      TITLE_X + 10,
00723                                      TITLE_Y + 5, 
00724                                      TITLE_FG_COLOR, 
00725                                      TITLE_BG_COLOR);
00726                 et024006_PrintString(title_contents.title[1],
00727                                      (const unsigned char*)&FONT8x8,
00728                                      TITLE_X + 10,
00729                                      TITLE_Y + 5 + 12, 
00730                                      TITLE_FG_COLOR, 
00731                                      TITLE_BG_COLOR);
00732                 et024006_PrintString(title_contents.title[2],
00733                                      (const unsigned char*)&FONT8x8,
00734                                      TITLE_X + 10,
00735                                      TITLE_Y + 5 + 12 + 12, 
00736                                      TITLE_FG_COLOR, 
00737                                      TITLE_BG_COLOR);
00738                 
00739         }
00740 
00741         
00742         // Draw scroll box
00743         et024006_DrawFilledRect(SCROLL_X, 
00744                                 SCROLL_Y, 
00745                                 SCROLL_W,
00746                                 SCROLL_H, 
00747                                 scroll_box_contents.bg_color);
00748 
00749 #endif
00750         switch (display_mode)
00751         {
00752         case GUI_INFOBOX:
00753                 gui_display_infobox();
00754                 break;
00755 
00756         case GUI_GETSTRING:
00757                 gui_display_getstring();
00758                 break;
00759 
00760         case GUI_LIST:
00761         {
00762 #if BOARD == EVK1100
00763                 dip204_clear_display();
00764 #endif
00765                 for (i = 0; i <= SCROLL_DISP_LINES; i++) 
00766                 {
00767 
00768 #if BOARD == EVK1100
00769 
00770                         dip204_set_cursor_position(1,i+1); /* col,line */
00771 
00772                         dip204_write_string(scroll_box_contents.lines[i+scroll_box_contents.dispstart]);
00773                   
00774 #else
00775 
00776                         if ((scroll_box_contents.cursor == i + scroll_box_contents.dispstart) &&
00777                             scroll_box_contents.cursor != 0)
00778                         {
00779                                 /* Print cursor line. */
00780                                 et024006_PrintString(scroll_box_contents.lines[i+scroll_box_contents.dispstart],
00781                                                      (const unsigned char*)&FONT8x8,
00782                                                      SCROLL_X + 10,
00783                                                      (i+1)*12+SCROLL_Y,
00784                                                      scroll_box_contents.bg_color, 
00785                                                      CURSOR_BG_COLOR);
00786                         } 
00787                         else
00788                         {
00789                                 et024006_PrintString(scroll_box_contents.lines[i+scroll_box_contents.dispstart],
00790                                                      (const unsigned char*)&FONT8x8,
00791                                                      SCROLL_X + 10,
00792                                                      (i+1)*12+SCROLL_Y,
00793                                                      SCROLL_FG_COLOR,
00794                                                      scroll_box_contents.bg_color);
00795                         }
00796 #endif
00797                 }
00798 #if BOARD == EVK1100
00799                 dip204_set_cursor_position(1, scroll_box_contents.cursor - scroll_box_contents.dispstart+1);
00800                 dip204_show_cursor();
00801 #endif        
00802         }
00803         } /* switch */
00804         // Draw buttons 
00805 #if BOARD != EVK1100
00806         et024006_DrawFilledRect(BUTTON_X, 
00807                                 BUTTON_Y, 
00808                                 BUTTON_W,
00809                                 BUTTON_H, 
00810                                 BUTTON_BG_COLOR);
00811         for (i = 0; i < NUM_BUTTONS-1; i++) {
00812                 et024006_DrawVertLine(i*BUTTON_W/NUM_BUTTONS,
00813                                       BUTTON_Y,
00814                                       BUTTON_H,
00815                                       BUTTON_FG_COLOR);
00816                 // Display button labels
00817                 if (button_contents.labels[i]) {
00818                         et024006_PrintString(button_contents.labels[i],
00819                                              (const unsigned char*)&FONT8x8,
00820                                              i*BUTTON_W/NUM_BUTTONS + 5, 
00821                                              BUTTON_Y + 10, 
00822                                              BUTTON_FG_COLOR, 
00823                                              BUTTON_BG_COLOR);
00824                 }
00825         }
00826 #endif
00827 }

void gui_exec ( uint32_t  ticks  ) 

Definition at line 665 of file gui.c.

References button_contents, CMD_INPROGRESS, gui_draw(), gui_getstring(), and poll_button().

Referenced by poll().

00665                              {
00666   
00667         int i;
00668         static int pressed_button;
00669         static enum { INPUT, RUN } state = INPUT;
00670 
00671         switch (state) 
00672         {
00673         case INPUT:
00674         {
00675                 i = poll_button(tick);
00676                 if ( i < 0 ) { // No action required
00677                         break;
00678                 }
00679                 else {
00680                         if (button_contents.cbs[i]) {
00681                                 pressed_button = i;
00682                                 state = RUN;
00683                         }
00684                 }
00685         }
00686         break;
00687         
00688         case RUN:
00689         {
00690 #ifdef GUI_COMPAT
00691                 if (button_contents.cbs[pressed_button]() == CMD_INPROGRESS)
00692                         return;
00693 #else
00694                 button_contents.cbs[pressed_button]();
00695 #endif
00696                 state = INPUT;
00697                 pressed_button = -1;
00698         }
00699         } /* case */
00700         // Poll gui_getstring
00701         gui_getstring(NULL, NULL); 
00702         gui_draw(1);
00703 }

int gui_get_scroll_box_focused_item ( char **  str,
size_t *  len 
)

Definition at line 401 of file gui.c.

References FALSE, scroll_box_contents, and TRUE.

00401                                                              {
00402         if (scroll_box_contents.cursor <= 0) {
00403                 return FALSE;
00404         }
00405         *str = scroll_box_contents.lines[scroll_box_contents.cursor];
00406         *len = strlen(*str);
00407 
00408         return TRUE;
00409 }

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 }

void gui_getstring_onoff ( int  state  ) 

Definition at line 645 of file gui.c.

References display_mode, GUI_GETSTRING, and GUI_LIST.

Referenced by gui_getstring().

00646 {
00647         if (state)
00648                 display_mode = GUI_GETSTRING;
00649         else
00650                 display_mode = GUI_LIST;
00651         //  display_infobox = state;
00652         mod = 1;
00653 }

void gui_inc_scroll_cursor ( void   ) 

Definition at line 345 of file gui.c.

References printk(), scroll_box_contents, and SCROLL_DISP_LINES.

Referenced by gui_scan_cb(), and gui_start().

00346 {
00347 
00348 #ifdef DEBUG
00349         printk("inc1: cur=%d, dstrt=%d\n", scroll_box_contents.cursor,
00350                scroll_box_contents.dispstart);
00351 #endif
00352         scroll_box_contents.cursor++;
00353         if (scroll_box_contents.cursor > (scroll_box_contents.dispstart 
00354                                           + SCROLL_DISP_LINES))
00355         {
00356                 scroll_box_contents.dispstart++;
00357         }
00358         if (scroll_box_contents.cursor >= scroll_box_contents.cnt)
00359         {
00360                 scroll_box_contents.dispstart = 0;
00361                 scroll_box_contents.cursor = 1;
00362         }
00363 #ifdef DEBUG
00364         printk("inc2: cur=%d, dstrt=%d\n", scroll_box_contents.cursor,
00365                scroll_box_contents.dispstart);
00366 #endif
00367         mod = 1;
00368 }

void gui_infobox_onoff ( int  state  ) 

Definition at line 526 of file gui.c.

References display_mode, GUI_INFOBOX, and GUI_LIST.

Referenced by gui_status_up_cb().

00527 {
00528         if (state)
00529                 display_mode = GUI_INFOBOX;
00530         else
00531                 display_mode = GUI_LIST;
00532         //  display_infobox = state;
00533         mod = 1;
00534 }

int gui_infobox_state ( void   ) 

Definition at line 536 of file gui.c.

References display_mode, and GUI_INFOBOX.

00536                             {
00537         return (GUI_INFOBOX == display_mode);
00538 }

void gui_init ( const pm_freq_param_t *  pm_freq_param  ) 

Definition at line 233 of file gui.c.

References button_contents, FPBA_HZ, info_bitmap, infobox_contents, qt60168_resources_init(), scroll_box_contents, title_contents, and TRUE.

Referenced by gui_start().

00233                                                     {
00234 #if BOARD == EVK1100
00235         static const gpio_map_t DIP204_SPI_GPIO_MAP =
00236                 {
00237                         {DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
00238                         {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
00239                         {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
00240                         {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
00241                 };
00242         spi_options_t spiOptions =
00243                 {
00244                         .reg          = DIP204_SPI_NPCS,
00245                         .baudrate     = 1000000,
00246                         .bits         = 8,
00247                         .spck_delay   = 0,
00248                         .trans_delay  = 0,
00249                         .stay_act     = 1,
00250                         .spi_mode     = 3,
00251                         .modfdis      = 1
00252                 };
00253 #endif
00254 
00255         memset(&scroll_box_contents, 0, sizeof scroll_box_contents);
00256         memset(&title_contents, 0, sizeof title_contents);
00257         memset(&button_contents, 0, sizeof button_contents);
00258         memset(&infobox_contents, 0, sizeof infobox_contents);
00259         memset(&info_bitmap, 0, sizeof info_bitmap);
00260 #if BOARD == EVK1104
00261         // Init touch sensor resources: GPIO, SPI and QT60168.
00262         qt60168_resources_init(pm_freq_param);
00263         // Initialize QT60168 component.
00264         qt60168_init(pm_freq_param->cpu_f);
00265 #endif
00266 #if BOARD == EVK1100
00267         // Assign I/Os to SPI
00268         gpio_enable_module(DIP204_SPI_GPIO_MAP,
00269                            sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));
00270 #if 0
00271         // Initialize as master
00272         spi_initMaster(DIP204_SPI, &spiOptions);
00273 
00274         // Set selection mode: variable_ps, pcs_decode, delay
00275         spi_selectionMode(DIP204_SPI, 0, 0, 0);
00276 
00277         // Enable SPI
00278         spi_enable(DIP204_SPI);
00279 #endif
00280         // setup chip registers
00281         spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);
00282 
00283         // initialize delay driver
00284         delay_init( FPBA_HZ );
00285 
00286         // initialize LCD
00287         dip204_init(backlight_PWM, TRUE);
00288         dip204_set_cursor_position(1,1);
00289         dip204_write_string("http server demo!");
00290 #else
00291         // Init display
00292         et024006_Init(  pm_freq_param->cpu_f, pm_freq_param->cpu_f /*HSB*/);
00293         // Turn on the display backlight
00294         gpio_set_gpio_pin(ET024006DHU_BL_PIN);
00295 #endif
00296         mod = 1;
00297 }

void gui_restore_buttons ( void   ) 

Definition at line 660 of file gui.c.

References button_contents.

Referenced by gui_getstring().

00661 {
00662         memcpy(&button_contents, &saved_buttons, sizeof button_contents);
00663 }

void gui_save_buttons ( void   ) 

Definition at line 655 of file gui.c.

References button_contents.

Referenced by gui_getstring(), and gui_status_up_cb().

00656 {
00657         memcpy(&saved_buttons, &button_contents, sizeof button_contents);
00658 }

int gui_scroll_idx ( void   ) 

Definition at line 396 of file gui.c.

References scroll_box_contents.

Referenced by gui_connect_cb().

00397 {
00398         return scroll_box_contents.cursor;
00399 }

void gui_set_bg_color ( short  color  ) 

Definition at line 340 of file gui.c.

References scroll_box_contents.

Referenced by gui_scan_cb(), and gui_start().

00341 {
00342         scroll_box_contents.bg_color = color;
00343 }

int gui_set_button ( short  id,
const char *  label,
size_t  len,
button_cb_t  cb 
)

Definition at line 317 of file gui.c.

References button_contents, and NUM_BUTTONS.

Referenced by gui_getstring(), gui_start(), and gui_status_up_cb().

00318 {
00319   
00320         if (id >= NUM_BUTTONS) {
00321                 return 0;
00322         }
00323         if (len >= sizeof button_contents.labels[id]) {
00324                 len = sizeof button_contents.labels[id] - 1;
00325         }
00326         button_contents.cbs[id] = cb;
00327         strncpy(button_contents.labels[id], label, len);
00328         mod = 1;
00329 
00330         return 1;
00331 }

void gui_set_title ( const char *  str,
unsigned char  line 
)

Definition at line 300 of file gui.c.

References title_contents.

Referenced by gs_button_4(), and gui_getstring().

00301 {
00302         int len;
00303 
00304         Assert(line < 3);
00305 
00306         memset(&title_contents.title[line], 0, sizeof title_contents.title[0]);
00307         len = strlen(str);
00308 
00309         if (len >= sizeof title_contents.title[0]) {
00310                 len = sizeof title_contents.title[0] - 1;
00311         }
00312         strncpy(title_contents.title[line], str, len);
00313 
00314         mod = 1;
00315 }


Generated on Fri Feb 19 02:24:08 2010 for AVR32 - H&D by  doxygen 1.5.5