static void handle_key_release(int keycode) { // static long idx_article = 0; static int first_time_random = 0; int mode; finger_move_speed = 0; keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW); // reset invert immediately DP(DBG_WL, ("O handle_key_release()\n")); mode = keyboard_get_mode(); if (keycode == WL_INPUT_KEY_POWER) { #ifdef INCLUDED_FROM_KERNEL if (history_list_save(HISTORY_SAVE_POWER_OFF)) { delay_us(200000); } #endif } else if (keycode == WL_INPUT_KEY_SEARCH) { article_buf_pointer = NULL; /* back to search */ if (display_mode == DISPLAY_MODE_INDEX) { toggle_soft_keyboard(); } else { search_set_selection(-1); display_mode = DISPLAY_MODE_INDEX; keyboard_set_mode(KEYBOARD_CHAR); repaint_search(); } } else if (keycode == WL_INPUT_KEY_HISTORY) { if (display_mode != DISPLAY_MODE_HISTORY) { article_buf_pointer = NULL; history_reload(); display_mode = DISPLAY_MODE_HISTORY; keyboard_set_mode(KEYBOARD_NONE); } else { if (keyboard_get_mode() == KEYBOARD_CLEAR_HISTORY) { keyboard_set_mode(KEYBOARD_NONE); guilib_fb_lock(); //keyboard_paint(); draw_clear_history(1); guilib_fb_unlock(); } else if (history_get_count() > 0) { keyboard_set_mode(KEYBOARD_CLEAR_HISTORY); guilib_fb_lock(); //keyboard_paint(); draw_clear_history(0); guilib_fb_unlock(); } } } else if (keycode == WL_INPUT_KEY_RANDOM) { if (first_time_random < 4) first_time_random++; if (first_time_random == 3) { first_time_random = 4; if (init_article_filter()) return; } article_buf_pointer = NULL; display_mode = DISPLAY_MODE_ARTICLE; last_display_mode = DISPLAY_MODE_INDEX; random_article(); } else if (display_mode == DISPLAY_MODE_INDEX) { article_buf_pointer = NULL; if (keycode == WL_KEY_RETURN) { int cur_selection = search_current_selection(); retrieve_article(cur_selection); #ifdef PROFILER_ON } else if (keycode == WL_KEY_HASH) { /* activate if you want to run performance tests */ /* perf_test(); */ malloc_status_simple(); prof_print(); #endif } else { handle_search_key(keycode); } } else if (display_mode == DISPLAY_MODE_ARTICLE) { article_buf_pointer = NULL; if (keycode == WL_KEY_BACKSPACE) { if (last_display_mode == DISPLAY_MODE_INDEX) { display_mode = DISPLAY_MODE_INDEX; repaint_search(); } else if (last_display_mode == DISPLAY_MODE_HISTORY) { display_mode = DISPLAY_MODE_HISTORY; history_reload(); } } } }
int wikilib_run(void) { int sleep; long time_now; struct wl_input_event ev; int more_events = 0; unsigned long last_event_time = 0; int rc; /* * test searching code... */ article_buf_pointer = NULL; search_init(); history_list_init(); malloc_status_simple(); print_intro(); #ifndef INCLUDED_FROM_KERNEL if (!load_init_article(idx_init_article)) { display_mode = DISPLAY_MODE_ARTICLE; last_display_mode = DISPLAY_MODE_INDEX; } #endif render_string(SUBTITLE_FONT_IDX, -1, 55, MESSAGE_TYPE_A_WORD, strlen(MESSAGE_TYPE_A_WORD), 0); for (;;) { if (more_events) sleep = 0; else sleep = 1; if (!more_events && display_mode == DISPLAY_MODE_ARTICLE && render_article_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_INDEX && render_search_result_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_HISTORY && render_history_with_pcf()) sleep = 0; if (finger_move_speed != 0) { scroll_article(); sleep = 0; } #ifdef INCLUDED_FROM_KERNEL time_now = get_time_ticks(); if(display_mode == DISPLAY_MODE_INDEX) { if (press_delete_button && get_search_string_len()>0) { sleep = 0; if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { if (!clear_search_string()) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NORMAL); } press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { if (!search_remove_char(0)) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NO_POPULATE); } last_delete_time = time_now; } } } else if (display_mode == DISPLAY_MODE_RESTRICTED) { if (press_delete_button && get_password_string_len()>0) { sleep = 0; time_now = get_time_ticks(); if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { clear_password_string(); press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { password_remove_char(); last_delete_time = time_now; } } } #endif if (!more_events && display_mode == DISPLAY_MODE_INDEX && fetch_search_result(0, 0, 0)) { sleep = 0; } if (keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_CHECK)) // check if need to reset invert sleep = 0; if (check_invert_link()) // check if need to invert link sleep = 0; if (sleep) { if (time_diff(get_time_ticks(), last_event_time) > seconds_to_ticks(15)) rc = history_list_save(HISTORY_SAVE_POWER_OFF); else rc = history_list_save(HISTORY_SAVE_NORMAL); if (rc > 0) { #ifdef INCLUDED_FROM_KERNEL delay_us(200000); // for some reason, save may not work if no delay #endif } else if (rc < 0) sleep = 0; // waiting for last_event_time timeout to save the history } wl_input_wait(&ev, sleep); more_events = 1; switch (ev.type) { case WL_INPUT_EV_TYPE_CURSOR: handle_cursor(&ev); last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_KEYBOARD: if (ev.key_event.value != 0) { b_show_scroll_bar = 0; handle_key_release(ev.key_event.keycode); } last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_TOUCH: handle_touch(&ev); last_event_time = ev.touch_event.ticks; break; default: more_events = 0; break; } } /* never reached */ return 0; }
void perf_test(void) { char *mem_src = NULL, *mem_dst = NULL, *file = NULL; int fd = -1, read; unsigned int file_size; mem_src = malloc_simple(MB, MEM_TAG_PERF_M1); if (!mem_src) { msg(MSG_INFO, "no mem_src: out of mem ?\n"); malloc_status_simple(); goto out; } mem_dst = malloc_simple(MB, MEM_TAG_PERF_M2); if (!mem_dst) { msg(MSG_INFO, "no mem_dst: out of mem ?\n"); malloc_status_simple(); goto out; } file = malloc_simple(MB, MEM_TAG_PERF_M3); if (!file) { msg(MSG_INFO, "no file: out of mem ?\n"); malloc_status_simple(); goto out; } prof_start(PROF_memset); memset(mem_src, 1, MB); prof_stop(PROF_memset); prof_start(PROF_memcpy); memcpy(mem_dst, mem_src, MB); prof_stop(PROF_memcpy); prof_start(PROF_memcmp); memcmp(mem_src, mem_dst, MB); prof_stop(PROF_memcmp); prof_start(PROF_sd_read); for (fd = 0; fd < 8; fd++) { read = disk_read(0, file + (fd * 512 * 256), fd * 255, 255); if (read != RES_OK) { prof_stop(PROF_sd_read); msg(MSG_INFO, "Could not read sd card: %i\n", read); goto out; } } prof_stop(PROF_sd_read); fd = wl_open("8dcec2", WL_O_RDONLY); if (fd < 0) { msg(MSG_INFO, "Could not read file '8dcec2': file not found\n"); goto out; } wl_fsize(fd, &file_size); if (file_size > MB) { msg(MSG_INFO, "Could not read file '8dcec2': file size bigger than %i bytes\n", MB); goto out; } prof_start(PROF_fread); read = wl_read(fd, file, file_size); prof_stop(PROF_fread); if (read != file_size) { msg(MSG_INFO, "Could not read file '8dcec2': read process aborted after %i bytes\n", read); goto out; } msg(MSG_INFO, "memcpy speed: 1MB/%dms, SD card: 1MB/%dms, fatfs: 1MB/%dms\n", (prof_container[PROF_memcpy].calls == 0 ? 0 : ((prof_container[PROF_memcpy].total_time / MCLK_MHz) / prof_container[PROF_memcpy].calls / 1000)), (prof_container[PROF_sd_read].calls == 0 ? 0 : ((prof_container[PROF_sd_read].total_time / MCLK_MHz) / prof_container[PROF_sd_read].calls / 1000)), (prof_container[PROF_fread].calls == 0 ? 0 : ((prof_container[PROF_fread].total_time / MCLK_MHz) / prof_container[PROF_fread].calls / (file_size / 100 / KB) / 100))); out: if (fd) wl_close(fd); if (file) free_simple(file, MEM_TAG_PERF_F3); if (mem_dst) free_simple(mem_dst, MEM_TAG_PERF_F4); if (mem_src) free_simple(mem_src, MEM_TAG_PERF_F5); return; }