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)

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)
Bool gui_getstring (char *string, int max_len)
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.


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 703 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(), gui_getstring(), and gui_start().

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

void gui_exec ( uint32_t  ticks  ) 

Definition at line 665 of file gui.c.

References button_contents, CMD_INPROGRESS, gui_draw(), 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         gui_draw(1);
00701 }

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 }

Bool gui_getstring ( char *  string,
int  max_len 
)

Definition at line 245 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(), gs_max_len, gui_draw(), gui_getstring_onoff(), gui_restore_buttons(), gui_save_buttons(), gui_set_button(), gui_set_title(), poll(), redisplay, and TRUE.

Referenced by gui_connect_cb().

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 }

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_connect_cb(), and 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 Thu Dec 17 19:57:54 2009 for AVR32 - H&D by  doxygen 1.5.5