| 1 | #include "platform.h" |
|---|
| 2 | #include "core.h" |
|---|
| 3 | #include "conf.h" |
|---|
| 4 | #include "keyboard.h" |
|---|
| 5 | #include "stdlib.h" |
|---|
| 6 | #include "gui.h" |
|---|
| 7 | #include "histogram.h" |
|---|
| 8 | #include "raw.h" |
|---|
| 9 | #ifdef OPT_EDGEOVERLAY |
|---|
| 10 | #include "edgeoverlay.h" |
|---|
| 11 | #endif |
|---|
| 12 | static int raw_need_postprocess; |
|---|
| 13 | static volatile int spytask_can_start; |
|---|
| 14 | #ifdef CAM_HAS_GPS |
|---|
| 15 | extern void wegpunkt(); |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | void core_hook_task_create(void *tcb) |
|---|
| 19 | { |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | void core_hook_task_delete(void *tcb) |
|---|
| 23 | { |
|---|
| 24 | char *name = (char*)(*(long*)((char*)tcb+0x34)); |
|---|
| 25 | if (strcmp(name,"tInitFileM")==0) core_spytask_can_start(); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | long core_get_noise_reduction_value() |
|---|
| 30 | { |
|---|
| 31 | return conf.raw_nr; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | void dump_memory() |
|---|
| 36 | { |
|---|
| 37 | int fd; |
|---|
| 38 | static int cnt=1; |
|---|
| 39 | static char fn[32]; |
|---|
| 40 | |
|---|
| 41 | started(); |
|---|
| 42 | mkdir("A/DCIM"); |
|---|
| 43 | mkdir("A/DCIM/100CANON"); |
|---|
| 44 | sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++); |
|---|
| 45 | fd = open(fn, O_WRONLY|O_CREAT, 0777); |
|---|
| 46 | if (fd) { |
|---|
| 47 | long val0 = *((long*)(0|CAM_UNCACHED_BIT)); |
|---|
| 48 | write(fd, &val0, 4); |
|---|
| 49 | write(fd, (void*)4, MAXRAMADDR-3); // MAXRAMADDR is last valid RAM location |
|---|
| 50 | close(fd); |
|---|
| 51 | } |
|---|
| 52 | vid_bitmap_refresh(); |
|---|
| 53 | finished(); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | int core_get_free_memory() { |
|---|
| 57 | #if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING) |
|---|
| 58 | // If using the exmem / suba memory allocation system then don't need |
|---|
| 59 | // to try allocating memory to find out how much is available |
|---|
| 60 | // Call function to scan free list for the largest free block available. |
|---|
| 61 | cam_meminfo camera_meminfo; |
|---|
| 62 | GetExMemInfo(&camera_meminfo); |
|---|
| 63 | return camera_meminfo.free_block_max_size; |
|---|
| 64 | #elif defined(CAM_FIRMWARE_MEMINFO) |
|---|
| 65 | // Call firmware function to fill memory info structure and return size of largest free block |
|---|
| 66 | cam_meminfo camera_meminfo; |
|---|
| 67 | GetMemInfo(&camera_meminfo); |
|---|
| 68 | return camera_meminfo.free_block_max_size; |
|---|
| 69 | #else |
|---|
| 70 | int size, l_size, d; |
|---|
| 71 | char* ptr; |
|---|
| 72 | |
|---|
| 73 | size = 16; |
|---|
| 74 | while (1) { |
|---|
| 75 | ptr= malloc(size); |
|---|
| 76 | if (ptr) { |
|---|
| 77 | free(ptr); |
|---|
| 78 | size <<= 1; |
|---|
| 79 | } else |
|---|
| 80 | break; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | l_size = size; |
|---|
| 84 | size >>= 1; |
|---|
| 85 | d=1024; |
|---|
| 86 | while (d) { |
|---|
| 87 | ptr = malloc(size); |
|---|
| 88 | if (ptr) { |
|---|
| 89 | free(ptr); |
|---|
| 90 | d = l_size-size; |
|---|
| 91 | if (d<0) d=-d; |
|---|
| 92 | l_size = size; |
|---|
| 93 | size += d>>1; |
|---|
| 94 | } else { |
|---|
| 95 | d = size-l_size; |
|---|
| 96 | if (d<0) d=-d; |
|---|
| 97 | l_size = size; |
|---|
| 98 | size -= d>>1; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | } |
|---|
| 102 | return size-1; |
|---|
| 103 | #endif |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | static volatile long raw_data_available; |
|---|
| 107 | |
|---|
| 108 | /* called from another process */ |
|---|
| 109 | void core_rawdata_available() |
|---|
| 110 | { |
|---|
| 111 | raw_data_available = 1; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | void core_spytask_can_start() { |
|---|
| 115 | spytask_can_start = 1; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | void core_spytask() |
|---|
| 119 | { |
|---|
| 120 | int cnt = 1; |
|---|
| 121 | int i=0; |
|---|
| 122 | |
|---|
| 123 | raw_need_postprocess = 0; |
|---|
| 124 | |
|---|
| 125 | spytask_can_start=0; |
|---|
| 126 | |
|---|
| 127 | #ifdef OPT_EXMEM_MALLOC |
|---|
| 128 | exmem_malloc_init(); |
|---|
| 129 | #endif |
|---|
| 130 | |
|---|
| 131 | #ifdef CAM_CHDK_PTP |
|---|
| 132 | init_chdk_ptp_task(); |
|---|
| 133 | #endif |
|---|
| 134 | |
|---|
| 135 | while((i++<400) && !spytask_can_start) msleep(10); |
|---|
| 136 | |
|---|
| 137 | started(); |
|---|
| 138 | msleep(50); |
|---|
| 139 | finished(); |
|---|
| 140 | drv_self_unhide(); |
|---|
| 141 | |
|---|
| 142 | conf_restore(); |
|---|
| 143 | gui_init(); |
|---|
| 144 | |
|---|
| 145 | #if CAM_CONSOLE_LOG_ENABLED |
|---|
| 146 | cam_console_init(); |
|---|
| 147 | #endif |
|---|
| 148 | |
|---|
| 149 | mkdir("A/CHDK"); |
|---|
| 150 | mkdir("A/CHDK/FONTS"); |
|---|
| 151 | mkdir("A/CHDK/SYMBOLS"); |
|---|
| 152 | mkdir("A/CHDK/SCRIPTS"); |
|---|
| 153 | mkdir("A/CHDK/LANG"); |
|---|
| 154 | mkdir("A/CHDK/BOOKS"); |
|---|
| 155 | mkdir("A/CHDK/GRIDS"); |
|---|
| 156 | #ifdef OPT_CURVES |
|---|
| 157 | mkdir("A/CHDK/CURVES"); |
|---|
| 158 | #endif |
|---|
| 159 | mkdir("A/CHDK/DATA"); |
|---|
| 160 | mkdir("A/CHDK/LOGS"); |
|---|
| 161 | #ifdef OPT_EDGEOVERLAY |
|---|
| 162 | mkdir("A/CHDK/EDGE"); |
|---|
| 163 | #endif |
|---|
| 164 | auto_started = 0; |
|---|
| 165 | |
|---|
| 166 | #ifdef OPT_SCRIPTING |
|---|
| 167 | if (conf.script_startup==1) script_autostart(); // remote autostart |
|---|
| 168 | if (conf.script_startup==2) { |
|---|
| 169 | conf.script_startup=0; |
|---|
| 170 | conf_save(); |
|---|
| 171 | script_autostart(); |
|---|
| 172 | } |
|---|
| 173 | #endif |
|---|
| 174 | |
|---|
| 175 | while (1){ |
|---|
| 176 | |
|---|
| 177 | #ifdef CAM_LOAD_CUSTOM_COLORS |
|---|
| 178 | load_chdk_palette(); |
|---|
| 179 | #endif |
|---|
| 180 | |
|---|
| 181 | if (raw_data_available){ |
|---|
| 182 | raw_need_postprocess = raw_savefile(); |
|---|
| 183 | hook_raw_save_complete(); |
|---|
| 184 | raw_data_available = 0; |
|---|
| 185 | #ifdef CAM_HAS_GPS |
|---|
| 186 | if( (int)conf.gps_waypoint_save == 1 ) |
|---|
| 187 | { |
|---|
| 188 | wegpunkt(); |
|---|
| 189 | } |
|---|
| 190 | #endif |
|---|
| 191 | continue; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | if ((state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) || recreview_hold) |
|---|
| 195 | { |
|---|
| 196 | if (((cnt++) & 3) == 0) |
|---|
| 197 | gui_redraw(); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | if (state_shooting_progress != SHOOTING_PROGRESS_PROCESSING) |
|---|
| 201 | { |
|---|
| 202 | histogram_process(); |
|---|
| 203 | #ifdef OPT_EDGEOVERLAY |
|---|
| 204 | if(conf.edge_overlay_thresh && conf.edge_overlay_enable) edge_overlay(); |
|---|
| 205 | #endif |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | if ((state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) && (!shooting_in_progress())) { |
|---|
| 209 | state_shooting_progress = SHOOTING_PROGRESS_DONE; |
|---|
| 210 | if (raw_need_postprocess) raw_postprocess(); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | #ifdef DEBUG_PRINT_TO_LCD |
|---|
| 214 | char osd_buf[30]; |
|---|
| 215 | sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display |
|---|
| 216 | draw_txt_string(2, 2, osd_buf, conf.osd_color); |
|---|
| 217 | #endif |
|---|
| 218 | msleep(20); |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | long ftell(FILE *file) { |
|---|
| 223 | if(!file) return -1; |
|---|
| 224 | return file->pos; |
|---|
| 225 | } |
|---|