/* set the background image */ void gui_set_bg(const char *path) { int fd; uint16_t w, h; fd = vfs_open(path); if (fd < 0) return; w = h = 0; (void)file_read(fd, &w, sizeof(w)); (void)file_read(fd, &h, sizeof(h)); if (w != GUI_WIDTH || h != GUI_HEIGHT) return; (void)file_read(fd, gui_bg_buffer, sizeof(gui_bg_buffer)); (void)file_close(fd); gui_redraw(); }
void gui_redraw_all() { gui_redraw(gBottomElement, 0); gui_redraw(gMenuBar, 0); }
void gui_main_loop(WIDGET *base/*,int resx,int resy*/) { SDL_Event event; Uint8 gui_done=0; Uint32 nb_event; WIDGET *mouse_focused=NULL; /* mouse focus */ static WIDGET *key_focused=NULL; /* key focus */ if (base==NULL) return; SDL_BlitSurface(desk_buf,NULL,desk_save,NULL); gui_redraw(base,SDL_TRUE); SDL_EnableUNICODE(1); mouse_focused=base->widget_at_pos(base,mouse_x,mouse_y); if (base->key_focus) key_focused=base->key_focus->data; else key_focused = NULL; if (!key_focused) key_focused=update_key_focus(base,NULL); /* key_focused=gui_widget_get_next_keyfocus(base); if (key_focused) { key_focused->flags|=FLAG_FOCUS; } */ while (gui_done!=1) { if (SDL_WaitEvent(&event) /*&& gui_done!=1*/) { if (event.type == SDL_QUIT) { //printf("QUIIT\n"); gui_exit_app(); exit(0); } nb_event=0; while(SDL_PollEvent(&event)) { if (event.type!=SDL_MOUSEMOTION) break; } switch (event.type) { case SDL_VIDEORESIZE: if (resize_display) resize_display(event.resize.w, event.resize.h); break; case SDL_KEYDOWN: if (event.key.keysym.sym==SDLK_ESCAPE) { gui_done=1; break; } if ( event.key.keysym.sym==SDLK_TAB) { key_focused=update_key_focus(base,key_focused); break; } if (key_focused) { WIDGET *t=key_focused; int e=PASS_EVENT; while(t && ((e=t->key(t,&event.key))==PASS_EVENT)) t=t->father; //printf("Res: %d\n",e); if (e==QUIT_EVENT) gui_done=1; } else { /* if no key focus list was setup, we use mouse focus */ WIDGET *t=mouse_focused; int e=PASS_EVENT; while(t && ((e=t->key(t,&event.key))==PASS_EVENT)) t=t->father; if (e==QUIT_EVENT) gui_done=1; } break; case SDL_MOUSEMOTION: { WIDGET *wid; WIDGET *t=mouse_focused; int e=PASS_EVENT; /* if (event.motion.x>=desk_buf->w) SDL_WarpMouse(desk_buf->w,event.motion.y); if (event.motion.y>=desk_buf->h) SDL_WarpMouse(event.motion.x,desk_buf->h); */ /* recalc relative mouse movement since we don't handle all the event. */ event.motion.xrel=event.motion.x-mouse_x; event.motion.yrel=event.motion.y-mouse_y; /*curs_rect.x=*/mouse_x=(event.motion.x);//*desk_buf->w)/(float)resx; /*curs_rect.y=*/mouse_y=(event.motion.y);//*desk_buf->h)/(float)resy; //printf("mouse: %d %d\n",mouse_x,mouse_y); event.motion.x=mouse_x; event.motion.y=mouse_y; //event.motion.xrel=(event.motion.xrel*desk_buf->w)/(float)resx; //event.motion.yrel=(event.motion.yrel*desk_buf->h)/(float)resy; while(t && ((e=t->mouse(t,&event.motion))==PASS_EVENT)) t=t->father; if (e==QUIT_EVENT) gui_done=1; /* don't change the focus if a button is pressed */ if (mouse_focused && WID_HAS_MOUSECLICK(mouse_focused)) break; mouse_focused=update_mouse_focus(base,mouse_focused,mouse_x,mouse_y); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { WIDGET *t=mouse_focused; int e=PASS_EVENT; /* recalc focus */ mouse_focused=update_mouse_focus(base,mouse_focused,mouse_x,mouse_y); event.button.x=mouse_x; event.button.y=mouse_y; if (event.type==SDL_MOUSEBUTTONUP && first_clicked==event.button.button) { while(t && ((e=t->double_click(t,&event.button))==PASS_EVENT)) t=t->father; first_clicked=0; } else { while(t && ((e=t->click(t,&event.button))==PASS_EVENT)) t=t->father; if (event.type==SDL_MOUSEBUTTONUP) first_clicked=event.button.button; SDL_AddTimer(450,double_click_timer,NULL); } if (t) { if (event.button.state == SDL_PRESSED) t->flags|=FLAG_MOUSECLICK; else t->flags&=(~FLAG_MOUSECLICK); /* Uint8 state=t->m_state; switch (event.button.button) { case SDL_BUTTON_LEFT: if (event.button.state == SDL_PRESSED) state|=0x1; else state&=(~0x1); break; case SDL_BUTTON_MIDDLE: if (event.button.state == SDL_PRESSED) state|=0x2; else state&=(~0x2); break; case SDL_BUTTON_RIGHT: if (event.button.state == SDL_PRESSED) state|=0x4; else state&=(~0x4); break; } //printf("state=%d\n",state); t->m_state=state; */ } if (e==QUIT_EVENT) gui_done=1; } break; } /* Redraw.. */ gui_redraw(base,SDL_TRUE); } } SDL_EnableUNICODE(0); }
void core_spytask() { int cnt = 1; int i=0; // Init camera_info bits that can't be done statically camera_info_init(); spytask_can_start=0; #ifdef OPT_EXMEM_MALLOC extern void exmem_malloc_init(void); exmem_malloc_init(); #endif #ifdef CAM_CHDK_PTP extern void init_chdk_ptp_task(); init_chdk_ptp_task(); #endif while((i++<400) && !spytask_can_start) msleep(10); started(); msleep(50); finished(); #if !CAM_DRYOS drv_self_unhide(); #endif conf_restore(); extern void gui_init(); gui_init(); #if CAM_CONSOLE_LOG_ENABLED extern void cam_console_init(); cam_console_init(); #endif mkdir("A/CHDK"); mkdir("A/CHDK/FONTS"); mkdir("A/CHDK/SYMBOLS"); mkdir("A/CHDK/SCRIPTS"); mkdir("A/CHDK/LANG"); mkdir("A/CHDK/BOOKS"); mkdir("A/CHDK/MODULES"); mkdir("A/CHDK/MODULES/CFG"); mkdir("A/CHDK/GRIDS"); mkdir("A/CHDK/CURVES"); mkdir("A/CHDK/DATA"); mkdir("A/CHDK/LOGS"); mkdir("A/CHDK/EDGE"); // Calculate the value of get_tick_count() when the clock ticks over to the next second // Used to calculate the SubSecondTime value when saving DNG files. long t1, t2; t2 = time(0); do { t1 = t2; camera_info.tick_count_offset = get_tick_count(); t2 = time(0); msleep(10); } while (t1 != t2); camera_info.tick_count_offset = camera_info.tick_count_offset % 1000; // remote autostart if (conf.script_startup==1) { script_autostart(); } else if (conf.script_startup==2) { conf.script_startup=0; conf_save(); script_autostart(); } shooting_init(); while (1) { if ( memdmptick && (get_tick_count() >= memdmptick) ) { memdmptick = 0; dump_memory(); } // Change ALT mode if the KBD task has flagged a state change gui_activate_alt_mode(); #ifdef CAM_LOAD_CUSTOM_COLORS // Color palette function extern void load_chdk_palette(); load_chdk_palette(); #endif if (raw_data_available) { raw_process(); extern void hook_raw_save_complete(); hook_raw_save_complete(); raw_data_available = 0; #ifdef CAM_HAS_GPS if( (int)conf.gps_waypoint_save == 1 ) wegpunkt(); #endif continue; } if ((camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) || recreview_hold) { if (((cnt++) & 3) == 0) gui_redraw(); } if (camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) { if (conf.show_histo) histogram_process(); #ifdef OPT_EDGEOVERLAY if(((gui_get_mode()==GUI_MODE_NONE) || (gui_get_mode()==GUI_MODE_ALT)) && conf.edge_overlay_thresh && conf.edge_overlay_enable) { // We need to skip first tick because stability static int skip_counter=1; if (skip_counter>0) { skip_counter--; } else { libedgeovr->edge_overlay(); } } #endif } if ((camera_info.state.state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) { camera_info.state.state_shooting_progress = SHOOTING_PROGRESS_DONE; } i = 0; #ifdef DEBUG_PRINT_TO_LCD sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display draw_txt_string(1, i++, osd_buf, conf.osd_color); #endif if (camera_info.perf.md_af_tuning) { sprintf(osd_buf, "MD last %-4d min %-4d max %-4d avg %-4d", camera_info.perf.af_led.last, camera_info.perf.af_led.min, camera_info.perf.af_led.max, (camera_info.perf.af_led.count>0)?camera_info.perf.af_led.sum/camera_info.perf.af_led.count:0); draw_txt_string(1, i++, osd_buf, conf.osd_color); } // Process async module unload requests module_tick_unloader(); msleep(20); chdk_started_flag=1; } }
/* ...surround-view scene rendering */ static void sview_redraw(display_data_t *display, void *data) { app_data_t *app = data; window_data_t *window = app->window; int W = window_get_width(window); int H = window_get_height(window); GstBuffer *buffers[CAMERAS_NUMBER]; texture_data_t *texture[CAMERAS_NUMBER]; GLuint tex[CAMERAS_NUMBER]; void *planes[CAMERAS_NUMBER]; s64 ts; /* ...try to get buffers */ while(sview_pop_buffers(app, buffers, texture, tex, planes, &ts)) { float fps = window_frame_rate_update(window); cairo_t *cr; /* ...ready for rendering; clear surface content */ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); /* ...specify a GL-viewport for an image */ if (0) glViewport(0, 0, W, H); /* ...draw graphics on top of the scene */ cr = window_get_cairo(window); /* ...generate a single scene; acquire engine access lock */ pthread_mutex_lock(&app->access); sview_engine_process(app->sv, tex, planes, cr, ts); pthread_mutex_unlock(&app->access); /* ...output frame-rate in the upper-left corner */ if(app->flags & APP_FLAG_DEBUG) { cairo_set_source_rgba(cr, 1, 1, 1, 0.5); cairo_move_to(cr, 40, 80); draw_string(cr, "%.1f FPS", fps); } else { TRACE(DEBUG, _b("main-window fps: %.1f"), fps); } /* ...output GUI graphics as needed */ gui_redraw(app->gui, cr); /* ...release cairo interface */ window_put_cairo(window, cr); /* ...submit window to a compositor */ window_draw(window); /* ...release buffers collected */ sview_release_buffers(app, buffers); } TRACE(DEBUG, _b("surround-view drawing complete")); }
/* ...redraw main application window */ static void objdet_redraw(display_data_t *display, void *data) { app_data_t *app = data; window_data_t *window = app->window; GstBuffer *buffer; /* ...retrieve pending buffer from rendering queue */ while ((buffer = objdet_pop_buffer(app)) != NULL) { vsink_meta_t *vmeta = gst_buffer_get_vsink_meta(buffer); objdet_meta_t *ometa = gst_buffer_get_objdet_meta(buffer); texture_data_t *texture = vmeta->priv; float fps = window_frame_rate_update(window); cairo_t *cr; /* ...add some performance monitors here - tbd */ TRACE(INFO, _b("redraw frame: %u"), app->frame_num++); /* ...clear buffer before drawing anything */ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); /* ...output buffer on screen */ texture_draw(texture, &app->view, NULL, 1.0); /* ...get cairo drawing context */ cr = window_get_cairo(window); /* ...set cairo transformation matrix for a given view-port - tbd */ cairo_save(cr); /* ...apply visualization matrix */ cairo_set_matrix(cr, &app->matrix); /* ...visualize detection data as required */ objdet_engine_ldw_draw(app->od, &ometa->scene, cr); /* ...restore transformation matrix */ cairo_restore(cr); /* ...output current vehicle status? - use unprocessed frame, maybe... */ if (app->flags & APP_FLAG_DEBUG) { /* ...output frame-rate in the upper-left corner */ cairo_set_source_rgba(cr, 1, 1, 1, 0.5); cairo_move_to(cr, 40, 80); draw_string(cr, "%.1f FPS", fps); } else { TRACE(DEBUG, _b("fps: %.2f"), fps); } /* ...output GUI graphics as needed */ gui_redraw(app->gui, cr); /* ...release cairo drawing context */ window_put_cairo(window, cr); /* ...submit window to composer */ window_draw(window); /* ...return buffer to the pool */ gst_buffer_unref(buffer); } TRACE(DEBUG, _b("frontal camera drawing complete..")); }
void core_spytask() { int cnt = 1; int i=0; #ifdef CAM_HAS_GPS int gps_delay_timer = 200 ; int gps_state = -1 ; #endif #if (OPT_DISABLE_CAM_ERROR) extern void DisableCamError(); int dce_cnt=0; int dce_prevmode=0; int dce_nowmode; #endif parse_version(&chdk_version, BUILD_NUMBER, BUILD_SVNREV); // Init camera_info bits that can't be done statically camera_info_init(); spytask_can_start=0; extern void aram_malloc_init(void); aram_malloc_init(); extern void exmem_malloc_init(void); exmem_malloc_init(); #ifdef CAM_CHDK_PTP extern void init_chdk_ptp_task(); init_chdk_ptp_task(); #endif while((i++<400) && !spytask_can_start) msleep(10); started(); msleep(50); finished(); #if !CAM_DRYOS drv_self_unhide(); #endif conf_restore(); extern void gui_init(); gui_init(); #if CAM_CONSOLE_LOG_ENABLED extern void cam_console_init(); cam_console_init(); #endif static char *chdk_dirs[] = { "A/CHDK", "A/CHDK/FONTS", "A/CHDK/SYMBOLS", "A/CHDK/SCRIPTS", "A/CHDK/LANG", "A/CHDK/BOOKS", "A/CHDK/MODULES", "A/CHDK/MODULES/CFG", "A/CHDK/GRIDS", "A/CHDK/CURVES", "A/CHDK/DATA", "A/CHDK/LOGS", "A/CHDK/EDGE", }; for (i = 0; i < sizeof(chdk_dirs) / sizeof(char*); i++) mkdir_if_not_exist(chdk_dirs[i]); no_modules_flag = stat("A/CHDK/MODULES/FSELECT.FLT",0) ? 1 : 0 ; // Calculate the value of get_tick_count() when the clock ticks over to the next second // Used to calculate the SubSecondTime value when saving DNG files. long t1, t2; t2 = time(0); do { t1 = t2; camera_info.tick_count_offset = get_tick_count(); t2 = time(0); msleep(10); } while (t1 != t2); camera_info.tick_count_offset = camera_info.tick_count_offset % 1000; // remote autostart if (conf.script_startup==SCRIPT_AUTOSTART_ALWAYS) { script_autostart(); } else if (conf.script_startup==SCRIPT_AUTOSTART_ONCE) { conf.script_startup=SCRIPT_AUTOSTART_NONE; conf_save(); script_autostart(); } shooting_init(); while (1) { // Set up camera mode & state variables mode_get(); // update HDMI power override based on mode and remote settings #ifdef CAM_REMOTE_HDMI_POWER_OVERRIDE extern void update_hdmi_power_override(void); update_hdmi_power_override(); #endif extern void set_palette(); set_palette(); #if (OPT_DISABLE_CAM_ERROR) dce_nowmode = camera_info.state.mode_play; if (dce_prevmode==dce_nowmode) { //no mode change dce_cnt++; // overflow is not a concern here } else { //mode has changed dce_cnt=0; } if (dce_cnt==100) { // 1..2s past play <-> rec mode change DisableCamError(); } dce_prevmode=dce_nowmode; #endif if ( memdmptick && (get_tick_count() >= memdmptick) ) { memdmptick = 0; dump_memory(); } #ifdef CAM_HAS_GPS if ( --gps_delay_timer == 0 ) { gps_delay_timer = 50 ; if ( gps_state != (int)conf.gps_on_off ) { gps_state = (int)conf.gps_on_off ; init_gps_startup(!gps_state) ; } } #endif // Change ALT mode if the KBD task has flagged a state change gui_activate_alt_mode(); #ifdef CAM_LOAD_CUSTOM_COLORS // Color palette function extern void load_chdk_palette(); load_chdk_palette(); #endif if (raw_data_available) { raw_process(); extern void hook_raw_save_complete(); hook_raw_save_complete(); raw_data_available = 0; #ifdef CAM_HAS_GPS if (((int)conf.gps_on_off == 1) && ((int)conf.gps_waypoint_save == 1)) gps_waypoint(); #endif #if defined(CAM_CALC_BLACK_LEVEL) // Reset to default in case used by non-RAW process code (e.g. raw merge) camera_sensor.black_level = CAM_BLACK_LEVEL; #endif continue; } if ((camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) || recreview_hold) { if (((cnt++) & 3) == 0) gui_redraw(); } if (camera_info.state.state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) { if (conf.show_histo) libhisto->histogram_process(); if ((camera_info.state.gui_mode_none || camera_info.state.gui_mode_alt) && conf.edge_overlay_thresh && conf.edge_overlay_enable) { // We need to skip first tick because stability if (chdk_started_flag) { libedgeovr->edge_overlay(); } } } if ((camera_info.state.state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) { camera_info.state.state_shooting_progress = SHOOTING_PROGRESS_DONE; } i = 0; #ifdef DEBUG_PRINT_TO_LCD sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display draw_txt_string(1, i++, osd_buf, user_color(conf.osd_color)); #endif #if defined(OPT_FILEIO_STATS) sprintf(osd_buf, "%3d %3d %3d %3d %3d %3d %3d %4d", camera_info.fileio_stats.fileio_semaphore_errors, camera_info.fileio_stats.close_badfile_count, camera_info.fileio_stats.write_badfile_count, camera_info.fileio_stats.open_count, camera_info.fileio_stats.close_count, camera_info.fileio_stats.open_fail_count, camera_info.fileio_stats.close_fail_count, camera_info.fileio_stats.max_semaphore_timeout); draw_txt_string(1, i++, osd_buf,user_color( conf.osd_color)); #endif if (camera_info.perf.md_af_tuning) { sprintf(osd_buf, "MD last %-4d min %-4d max %-4d avg %-4d", camera_info.perf.af_led.last, camera_info.perf.af_led.min, camera_info.perf.af_led.max, (camera_info.perf.af_led.count>0)?camera_info.perf.af_led.sum/camera_info.perf.af_led.count:0); draw_txt_string(1, i++, osd_buf, user_color(conf.osd_color)); } // Process async module unload requests module_tick_unloader(); msleep(20); chdk_started_flag=1; } }
void core_spytask() { int cnt = 1; int i=0; raw_need_postprocess = 0; spytask_can_start=0; while((i++<400) && !spytask_can_start) msleep(10); started(); msleep(50); finished(); drv_self_unhide(); conf_restore(); gui_init(); #if CAM_CONSOLE_LOG_ENABLED console_init(); #endif mkdir("A/CHDK"); mkdir("A/CHDK/FONTS"); mkdir("A/CHDK/SYMBOLS"); mkdir("A/CHDK/SCRIPTS"); mkdir("A/CHDK/LANG"); mkdir("A/CHDK/BOOKS"); mkdir("A/CHDK/GRIDS"); #ifdef OPT_CURVES mkdir("A/CHDK/CURVES"); #endif mkdir("A/CHDK/DATA"); mkdir("A/CHDK/LOGS"); #ifdef OPT_EDGEOVERLAY mkdir("A/CHDK/EDGE"); #endif auto_started = 0; if (conf.script_startup==1) script_autostart(); // remote autostart if (conf.script_startup==2) { conf.script_startup=0; conf_save(); script_autostart(); } while (1) { if (raw_data_available) { raw_need_postprocess = raw_savefile(); hook_raw_save_complete(); raw_data_available = 0; continue; } if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) { if (((cnt++) & 3) == 0) gui_redraw(); histogram_process(); #ifdef OPT_EDGEOVERLAY if(conf.edge_overlay_thresh && conf.edge_overlay_enable) edge_overlay(); #endif } if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) { state_shooting_progress = SHOOTING_PROGRESS_DONE; if (raw_need_postprocess) raw_postprocess(); } msleep(20); } }