gui_console* gui_console_init ( char* name, double x, double y, double w, double h ) { gui_console* gc = malloc(sizeof(gui_console)); gc->name = malloc(strlen(name)); strcpy(gc->name, name); gc->bounds = _gui_box_init(x, y, w, h); char tname[1024]; sprintf(tname, "%s TEXTBOX", name); gc->out = gui_textbox_init(tname,x,y,w,h,GUI_CONSOLE_TEXTPT); sprintf(tname, "%s TEXT INPUT", name); gc->in = gui_textin_init(tname, x, y, w, h); sprintf(tname, "%s SUBMIT BUTTON", name); gc->submit = gui_button_init(name, x, y, w, h); gc->settings = hashtable_init(0); return gc; }
gui_slider* gui_slider_init ( char* name, double x, double y, double w, double h ) { gui_slider* gs = malloc(sizeof(gui_slider)); gs->name = malloc(strlen(name)); strcpy(gs->name, name); char buttonname[1024]; strcpy(buttonname, name); strcat(buttonname, " CLICK BOX"); gs->clickarea = gui_button_init(buttonname, 0.0, 0.0, w, h); gs->bounds = _gui_box_init(x, y, w, h); gs->lastp = 0.0; gs->value = &gui_slider_nullvalue; return gs; }
/* Conditions: 22 Exit points: 0 M = 22 - 0 + 2 = 25 Cyclomatic complexity 25 */ void fp_test(void) { uint32_t retCode = 0; GUI_Button_t fp_start, fp_refresh, fp_close, fp_continue; TS_StateTypeDef ts; uint32_t action = 0, id = 0; gui_button_init(&fp_start); fp_start.XPosition = 20; fp_start.YPosition = 50; fp_start.Height = 50; fp_start.Width = 200; fp_start.BorderWidth = 2; fp_start.BorderColor = LCD_COLOR_BLACK; fp_start.FillColor = LCD_COLOR_WHITE; fp_start.TextColor = LCD_COLOR_BLACK; fp_start.Text = (uint8_t*)"Start"; gui_button_init(&fp_refresh); fp_refresh.XPosition = 20; fp_refresh.YPosition = 125; fp_refresh.Height = 50; fp_refresh.Width = 200; fp_refresh.BorderWidth = 2; fp_refresh.BorderColor = LCD_COLOR_BLACK; fp_refresh.FillColor = LCD_COLOR_WHITE; fp_refresh.TextColor = LCD_COLOR_BLACK; fp_refresh.Text = (uint8_t*)"Refresh"; gui_button_init(&fp_close); fp_close.XPosition = 20; fp_close.YPosition = 200; fp_close.Height = 50; fp_close.Width = 200; fp_close.BorderWidth = 2; fp_close.BorderColor = LCD_COLOR_BLACK; fp_close.FillColor = LCD_COLOR_WHITE; fp_close.TextColor = LCD_COLOR_BLACK; fp_close.Text = (uint8_t*)"Close"; gui_button_init(&fp_continue); fp_continue.XPosition = 20; fp_continue.YPosition = 250; fp_continue.Height = 50; fp_continue.Width = 200; fp_continue.BorderWidth = 2; fp_continue.BorderColor = LCD_COLOR_BLACK; fp_continue.FillColor = LCD_COLOR_WHITE; fp_continue.TextColor = LCD_COLOR_BLACK; fp_continue.Text = (uint8_t*)"Continue"; while (1) { BSP_LCD_Clear(LCD_COLOR_WHITE); gui_button_draw(&fp_start); gui_button_draw(&fp_refresh); gui_button_draw(&fp_close); action = 0; while (action == 0) { BSP_TS_GetState(&ts); if (gui_button_check_touch(&fp_start, &ts) == GUI_Button_Error_Yes) { action = 1; } else if (gui_button_check_touch(&fp_refresh, &ts) == GUI_Button_Error_Yes) { action = 2; } else if (gui_button_check_touch(&fp_close, &ts) == GUI_Button_Error_Yes) { action = 3; } else { vTaskDelay(5); } } switch (action) { case 1: id = fp_session_start(); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_DisplayStringAtLine(1, (uint8_t*)"Session start"); if (id < 20) BSP_LCD_DisplayStringAtLine(2, format_string("ID: %d", id)); else BSP_LCD_DisplayStringAtLine(2, format_string("Error code: %x", id)); gui_button_draw(&fp_continue); while (1) { BSP_TS_GetState(&ts); if (gui_button_check_touch(&fp_continue, &ts) == GUI_Button_Error_Yes) break; vTaskDelay(5); } break; case 2: retCode = fp_session_refresh(id); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_DisplayStringAtLine(1, (uint8_t*)"Session refresh"); if (retCode < 20) BSP_LCD_DisplayStringAtLine(2, format_string("ID: %d", id)); else BSP_LCD_DisplayStringAtLine(2, format_string("Error code: %x", retCode)); gui_button_draw(&fp_continue); while (1) { BSP_TS_GetState(&ts); if (gui_button_check_touch(&fp_continue, &ts) == GUI_Button_Error_Yes) break; vTaskDelay(5); } break; case 3: retCode = fp_session_close(id); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_DisplayStringAtLine(1, (uint8_t*)"Session close"); if (retCode < 20) BSP_LCD_DisplayStringAtLine(2, format_string("ID: %d", id)); else BSP_LCD_DisplayStringAtLine(2, format_string("Error code: %x", retCode)); gui_button_draw(&fp_continue); while (1) { BSP_TS_GetState(&ts); if (gui_button_check_touch(&fp_continue, &ts) == GUI_Button_Error_Yes) break; vTaskDelay(5); } break; default: id = fp_error_session_not_started; break; } } }
/* Conditions: 7 Exit points: 1 M = 7 - 1 + 2 = 8 Cyclomatic complexity 8 */ uint32_t fp_session_start(void) { uint32_t id = 0; TickType_t lastWake = 0; uint32_t action = 0; TS_StateTypeDef ts; GUI_Button_t newID, existing; gui_button_init(&newID); newID.XPosition = 20; newID.YPosition = 100; newID.Height = 75; newID.Width = 200; newID.BorderWidth = 2; newID.BorderColor = LCD_COLOR_BLACK; newID.FillColor = LCD_COLOR_WHITE; newID.TextColor = LCD_COLOR_BLACK; newID.Text = (uint8_t*)"New user"; gui_button_init(&existing); existing.XPosition = 20; existing.YPosition = 200; existing.Height = 75; existing.Width = 200; existing.BorderWidth = 2; existing.BorderColor = LCD_COLOR_BLACK; existing.FillColor = LCD_COLOR_WHITE; existing.TextColor = LCD_COLOR_BLACK; existing.Text = (uint8_t*)"Existing user"; lastWake = xTaskGetTickCount(); BSP_LCD_Clear(LCD_COLOR_WHITE); /* Display buttons to user 1. New ID 2. Existing */ BSP_LCD_DisplayStringAt(0, BSP_LCD_GetFont()->Height * 3 / 2, (uint8_t*)"Authenticate", CENTER_MODE); gui_button_draw(&newID); gui_button_draw(&existing); // Wait for user selection while (1) { // If canceled, // Abort BSP_TS_GetState(&ts); if (gui_button_check_touch(&newID, &ts) == GUI_Button_Error_Yes) { action = 1; break; } else if (gui_button_check_touch(&existing, &ts) == GUI_Button_Error_Yes) { action = 2; break; } vTaskDelayUntil(&lastWake, 100); } //__asm__("bkpt #1"); switch (action) { // On New ID, case 1: // Call fp_session_new id = fp_session_new(); break; // On Existing, case 2: // Call fp_session_open id = fp_session_open(); break; default: id = fp_error_session_not_started; break; } if (id < 20) { Session_ActivityStamps[id] = fp_get_rtc_time(); } return id; }