| 1 | #include "camera.h" |
|---|
| 2 | #include "lolevel.h" |
|---|
| 3 | #include "platform.h" |
|---|
| 4 | #include "conf.h" |
|---|
| 5 | #include "math.h" |
|---|
| 6 | |
|---|
| 7 | #if CAM_DRYOS |
|---|
| 8 | #define _U 0x01 /* upper */ |
|---|
| 9 | #define _L 0x02 /* lower */ |
|---|
| 10 | #define _D 0x04 /* digit */ |
|---|
| 11 | #define _C 0x08 /* cntrl */ |
|---|
| 12 | #define _P 0x10 /* punct */ |
|---|
| 13 | #define _S 0x20 /* white space (space/lf/tab) */ |
|---|
| 14 | #define _X 0x40 /* hex digit */ |
|---|
| 15 | #define _SP 0x80 /* hard space (0x20) */ |
|---|
| 16 | unsigned char _ctype[] = { |
|---|
| 17 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
|---|
| 18 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
|---|
| 19 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
|---|
| 20 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
|---|
| 21 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
|---|
| 22 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
|---|
| 23 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
|---|
| 24 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
|---|
| 25 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
|---|
| 26 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
|---|
| 27 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
|---|
| 28 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
|---|
| 29 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
|---|
| 30 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
|---|
| 31 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
|---|
| 32 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
|---|
| 33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
|---|
| 34 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
|---|
| 35 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160-175 */ |
|---|
| 36 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176-191 */ |
|---|
| 37 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192-207 */ |
|---|
| 38 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208-223 */ |
|---|
| 39 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224-239 */ |
|---|
| 40 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* 240-255 */ |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | void msleep(long msec) |
|---|
| 44 | { |
|---|
| 45 | _SleepTask(msec); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | #ifndef CAM_DRYOS |
|---|
| 49 | void task_lock() |
|---|
| 50 | { |
|---|
| 51 | _taskLock(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void task_unlock() |
|---|
| 55 | { |
|---|
| 56 | _taskUnlock(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | const char *task_name(int id) |
|---|
| 60 | { |
|---|
| 61 | return _taskName(id); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | int task_id_list_get(int *idlist,int size) |
|---|
| 65 | { |
|---|
| 66 | return _taskIdListGet(idlist,size); |
|---|
| 67 | } |
|---|
| 68 | #endif |
|---|
| 69 | |
|---|
| 70 | long get_property_case(long id, void *buf, long bufsize) |
|---|
| 71 | { |
|---|
| 72 | return _GetPropertyCase(id, buf, bufsize); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | long set_property_case(long id, void *buf, long bufsize) |
|---|
| 76 | { |
|---|
| 77 | return _SetPropertyCase(id, buf, bufsize); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void remount_filesystem() |
|---|
| 81 | { |
|---|
| 82 | _Unmount_FileSystem(); |
|---|
| 83 | _Mount_FileSystem(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void mark_filesystem_bootable() |
|---|
| 87 | { |
|---|
| 88 | _UpdateMBROnFlash(0, 0x40, "BOOTDISK"); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void __attribute__((weak)) vid_bitmap_refresh() |
|---|
| 92 | { |
|---|
| 93 | _RefreshPhysicalScreen(1); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | long get_parameter_data(long id, void *buf, long bufsize) |
|---|
| 98 | { |
|---|
| 99 | return _GetParameterData(id|0x4000, buf, bufsize); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | long set_parameter_data(long id, void *buf, long bufsize) |
|---|
| 103 | { |
|---|
| 104 | return _SetParameterData(id|0x4000, buf, bufsize); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | long lens_get_zoom_pos() |
|---|
| 108 | { |
|---|
| 109 | return _GetZoomLensCurrentPosition(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void lens_set_zoom_pos(long newpos) |
|---|
| 113 | { |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | long lens_get_zoom_point() |
|---|
| 117 | { |
|---|
| 118 | return _GetZoomLensCurrentPoint(); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | void lens_set_zoom_point(long newpt) |
|---|
| 122 | { |
|---|
| 123 | if (newpt < 0) { |
|---|
| 124 | newpt = 0; |
|---|
| 125 | } else if (newpt >= zoom_points) { |
|---|
| 126 | newpt = zoom_points-1; |
|---|
| 127 | } |
|---|
| 128 | #if defined(CAMERA_sx30) |
|---|
| 129 | // SX30 - Can't find zoom_status, _MoveZoomLensWithPoint crashes camera |
|---|
| 130 | extern void _PT_MoveOpticalZoomAt(long*); |
|---|
| 131 | if (lens_get_zoom_point() != newpt) |
|---|
| 132 | _PT_MoveOpticalZoomAt(&newpt); |
|---|
| 133 | #elif defined(CAMERA_g12) |
|---|
| 134 | // G12 - Can't find zoom_status, _MoveZoomLensWithPoint works anyway, and updates PROPCASE_OPTICAL_ZOOM_POSITION; but doesn't wait for zoom to finish |
|---|
| 135 | if (lens_get_zoom_point() != newpt) |
|---|
| 136 | _MoveZoomLensWithPoint((short*)&newpt); |
|---|
| 137 | #else |
|---|
| 138 | _MoveZoomLensWithPoint((short*)&newpt); |
|---|
| 139 | while (zoom_busy); |
|---|
| 140 | if (newpt==0) zoom_status=ZOOM_OPTICAL_MIN; |
|---|
| 141 | else if (newpt >= zoom_points) zoom_status=ZOOM_OPTICAL_MAX; |
|---|
| 142 | else zoom_status=ZOOM_OPTICAL_MEDIUM; |
|---|
| 143 | _SetPropertyCase(PROPCASE_OPTICAL_ZOOM_POSITION, &newpt, sizeof(newpt)); |
|---|
| 144 | #endif |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | void lens_set_zoom_speed(long newspd) |
|---|
| 148 | { |
|---|
| 149 | if (newspd < 5) { |
|---|
| 150 | newspd = 5; |
|---|
| 151 | } else if (newspd > 100) { |
|---|
| 152 | newspd = 100; |
|---|
| 153 | } |
|---|
| 154 | _SetZoomActuatorSpeedPercent((short*)&newspd); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | void lens_set_focus_pos(long newpos) |
|---|
| 158 | { |
|---|
| 159 | _MoveFocusLensToDistance((short*)&newpos); |
|---|
| 160 | //while (focus_busy); |
|---|
| 161 | while ((shooting_is_flash_ready()!=1) || (focus_busy)); |
|---|
| 162 | newpos = _GetFocusLensSubjectDistance(); |
|---|
| 163 | _SetPropertyCase(PROPCASE_SUBJECT_DIST1, &newpos, sizeof(newpos)); |
|---|
| 164 | _SetPropertyCase(PROPCASE_SUBJECT_DIST2, &newpos, sizeof(newpos)); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | void play_sound(unsigned sound) |
|---|
| 168 | { |
|---|
| 169 | static const int sounds[]={ 0x2001, //startup sound |
|---|
| 170 | 0x2002, //shutter sound |
|---|
| 171 | 0x2003, //button press sound |
|---|
| 172 | 0x2004, //self-timer sound |
|---|
| 173 | 0xC211, //short beep |
|---|
| 174 | 50000, // AF confirmation |
|---|
| 175 | 0xC507, // error beep imo |
|---|
| 176 | 0x400D, // LONG ERROR BEEP CONTINIUOUS- warning, cannot be stopped (yet) |
|---|
| 177 | }; |
|---|
| 178 | if(sound >= sizeof(sounds)/sizeof(sounds[0])) |
|---|
| 179 | return; |
|---|
| 180 | |
|---|
| 181 | _PT_PlaySound(sounds[sound], 0); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | long stat_get_vbatt() |
|---|
| 185 | { |
|---|
| 186 | return _VbattGet(); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | int get_battery_temp() |
|---|
| 190 | { |
|---|
| 191 | return _GetBatteryTemperature(); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | int get_ccd_temp() |
|---|
| 195 | { |
|---|
| 196 | return _GetCCDTemperature(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | int get_optical_temp() |
|---|
| 200 | { |
|---|
| 201 | return _GetOpticalTemperature(); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | long get_tick_count() |
|---|
| 205 | { |
|---|
| 206 | long t; |
|---|
| 207 | #if !CAM_DRYOS |
|---|
| 208 | _GetSystemTime(&t); |
|---|
| 209 | return t; |
|---|
| 210 | #else |
|---|
| 211 | return (int)_GetSystemTime(&t); |
|---|
| 212 | #endif |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | /*int creat (const char *name, int flags) |
|---|
| 216 | { |
|---|
| 217 | return _creat(name, flags); |
|---|
| 218 | }*/ |
|---|
| 219 | int open (const char *name, int flags, int mode ) |
|---|
| 220 | { |
|---|
| 221 | #ifdef CAM_DRYOS_2_3_R39 |
|---|
| 222 | if(name[0]!='A')return -1; |
|---|
| 223 | #endif |
|---|
| 224 | return _Open(name, flags, mode); |
|---|
| 225 | } |
|---|
| 226 | int close (int fd) |
|---|
| 227 | { |
|---|
| 228 | return _Close(fd); |
|---|
| 229 | } |
|---|
| 230 | int write (int fd, void *buffer, long nbytes) |
|---|
| 231 | { |
|---|
| 232 | return _Write(fd, buffer, nbytes); |
|---|
| 233 | } |
|---|
| 234 | int read (int fd, void *buffer, long nbytes) |
|---|
| 235 | { |
|---|
| 236 | return _Read(fd, buffer, nbytes); |
|---|
| 237 | } |
|---|
| 238 | int lseek (int fd, long offset, int whence) |
|---|
| 239 | { |
|---|
| 240 | return _lseek(fd, offset, whence); /* yes, it's lower-case lseek here since Lseek calls just lseek (A610) */ |
|---|
| 241 | } |
|---|
| 242 | long mkdir(const char *dirname) |
|---|
| 243 | { |
|---|
| 244 | return _mkdir(dirname); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | int remove(const char *name) { |
|---|
| 248 | return _Remove(name); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | int errnoOfTaskGet(int tid) { |
|---|
| 252 | #if !CAM_DRYOS |
|---|
| 253 | return _errnoOfTaskGet(tid); |
|---|
| 254 | #else |
|---|
| 255 | return 0; |
|---|
| 256 | #endif |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | int isdigit(int c) { |
|---|
| 260 | #if !CAM_DRYOS |
|---|
| 261 | return _isdigit(c); |
|---|
| 262 | #else |
|---|
| 263 | return _ctype[c]&_D; |
|---|
| 264 | #endif |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | int isspace(int c) { |
|---|
| 268 | #if !CAM_DRYOS |
|---|
| 269 | return _isspace(c); |
|---|
| 270 | #else |
|---|
| 271 | return _ctype[c]&_S; |
|---|
| 272 | #endif |
|---|
| 273 | |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | int isalpha(int c) { |
|---|
| 277 | #if !CAM_DRYOS |
|---|
| 278 | return _isalpha(c); |
|---|
| 279 | #else |
|---|
| 280 | return _ctype[c]&(_U|_L); |
|---|
| 281 | #endif |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | int isupper(int c) { |
|---|
| 285 | #if !CAM_DRYOS |
|---|
| 286 | return _isupper(c); |
|---|
| 287 | #else |
|---|
| 288 | return _ctype[c]&_U; |
|---|
| 289 | #endif |
|---|
| 290 | |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | int islower(int c) { |
|---|
| 294 | #if !CAM_DRYOS |
|---|
| 295 | return _islower(c); |
|---|
| 296 | #else |
|---|
| 297 | return _ctype[c]&_L; |
|---|
| 298 | #endif |
|---|
| 299 | |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | int ispunct(int c) { |
|---|
| 303 | #if !CAM_DRYOS |
|---|
| 304 | return _ispunct(c); |
|---|
| 305 | #else |
|---|
| 306 | return _ctype[c]&_P; |
|---|
| 307 | #endif |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | int isxdigit(int c) { |
|---|
| 311 | #if !CAM_DRYOS |
|---|
| 312 | return _isxdigit(c); |
|---|
| 313 | #else |
|---|
| 314 | return _ctype[c]&(_X|_D); |
|---|
| 315 | #endif |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | long strlen(const char *s) { |
|---|
| 319 | return _strlen(s); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | int strcmp(const char *s1, const char *s2) { |
|---|
| 323 | return _strcmp(s1, s2); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | int strncmp(const char *s1, const char *s2, long n) { |
|---|
| 327 | return _strncmp(s1, s2, n); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | char *strchr(const char *s, int c) { |
|---|
| 331 | return _strchr(s, c); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | char *strcpy(char *dest, const char *src) { |
|---|
| 335 | return _strcpy(dest, src); |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | char *strncpy(char *dest, const char *src, long n) { |
|---|
| 339 | return _strncpy(dest, src, n); |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | char *strcat(char *dest, const char *app) { |
|---|
| 343 | return _strcat(dest, app); |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | char *strrchr(const char *s, int c) { |
|---|
| 347 | return _strrchr(s, c); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | long strtol(const char *nptr, char **endptr, int base) { |
|---|
| 351 | return _strtol(nptr, endptr, base); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | unsigned long strtoul(const char *nptr, char **endptr, int base) { |
|---|
| 355 | #if CAM_DRYOS |
|---|
| 356 | return (unsigned long)_strtolx(nptr, endptr, base, 0); |
|---|
| 357 | #else |
|---|
| 358 | return _strtoul(nptr, endptr, base); |
|---|
| 359 | #endif |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | char *strpbrk(const char *s, const char *accept) { |
|---|
| 363 | #if !CAM_DRYOS |
|---|
| 364 | return _strpbrk(s, accept); |
|---|
| 365 | #else |
|---|
| 366 | const char *sc1,*sc2; |
|---|
| 367 | |
|---|
| 368 | for( sc1 = s; *sc1 != '\0'; ++sc1) { |
|---|
| 369 | for( sc2 = accept; *sc2 != '\0'; ++sc2) { |
|---|
| 370 | if (*sc1 == *sc2) return (char *) sc1; |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | return (void*)0; |
|---|
| 374 | #endif |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | long sprintf(char *s, const char *st, ...) |
|---|
| 378 | { |
|---|
| 379 | long res; |
|---|
| 380 | __builtin_va_list va; |
|---|
| 381 | __builtin_va_start(va, st); |
|---|
| 382 | res = _vsprintf(s, st, va); |
|---|
| 383 | __builtin_va_end(va); |
|---|
| 384 | return res; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | // strerror exists on vxworks cams, |
|---|
| 388 | // but it does about the same thing as this |
|---|
| 389 | const char *strerror(int en) { |
|---|
| 390 | #if !CAM_DRYOS |
|---|
| 391 | static char msg[20]; |
|---|
| 392 | sprintf(msg,"errno 0x%X",en); |
|---|
| 393 | return msg; |
|---|
| 394 | #else |
|---|
| 395 | return "error"; |
|---|
| 396 | #endif |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | int tolower(int c) { |
|---|
| 400 | #if !CAM_DRYOS |
|---|
| 401 | return _tolower(c); |
|---|
| 402 | #else |
|---|
| 403 | return isupper(c) ? c - 'A' + 'a' : c; |
|---|
| 404 | #endif |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | int toupper(int c) { |
|---|
| 408 | #if !CAM_DRYOS |
|---|
| 409 | return _toupper(c); |
|---|
| 410 | #else |
|---|
| 411 | return islower(c) ? c - 'a' + 'A' : c; |
|---|
| 412 | #endif |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | unsigned long time(unsigned long *timer) { |
|---|
| 416 | return _time(timer); |
|---|
| 417 | } |
|---|
| 418 | |
|---|
| 419 | int utime(char *file, void *newTimes) { |
|---|
| 420 | #if !CAM_DRYOS |
|---|
| 421 | return _utime(file, newTimes); |
|---|
| 422 | #else |
|---|
| 423 | int res=0; |
|---|
| 424 | int fd; |
|---|
| 425 | fd = _open(file, 0, 0); |
|---|
| 426 | |
|---|
| 427 | #ifdef CAM_DRYOS_2_3_R39 |
|---|
| 428 | if (fd>=0) { |
|---|
| 429 | _close(fd); |
|---|
| 430 | res=_SetFileTimeStamp(file, ((int*)newTimes)[0] , ((int*)newTimes)[1]); |
|---|
| 431 | } |
|---|
| 432 | #else |
|---|
| 433 | if (fd>=0) { |
|---|
| 434 | res=_SetFileTimeStamp(fd, ((int*)newTimes)[0] , ((int*)newTimes)[1]); |
|---|
| 435 | _close(fd); |
|---|
| 436 | } |
|---|
| 437 | // return value compatibe with utime: ok=0 fail=-1 |
|---|
| 438 | #endif |
|---|
| 439 | return (res)?0:-1; |
|---|
| 440 | #endif |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | void *localtime(const unsigned long *_tod) { |
|---|
| 444 | #if !CAM_DRYOS |
|---|
| 445 | return _localtime(_tod); |
|---|
| 446 | #else |
|---|
| 447 | // for DRYOS cameras do something with this! - sizeof(x[]) must be >= sizeof(struct tm) : 'static int x[9];' |
|---|
| 448 | static int x[9]; |
|---|
| 449 | return _LocalTime(_tod, &x); |
|---|
| 450 | #endif |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | long strftime(char *s, unsigned long maxsize, const char *format, /*const struct tm*/ void *timp) { |
|---|
| 454 | return _strftime(s,maxsize,format,timp); |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | /*time_t*/ long mktime(/*struct tm*/ void *timp) { |
|---|
| 458 | #if !CAM_DRYOS |
|---|
| 459 | return _mktime(timp); |
|---|
| 460 | #else |
|---|
| 461 | int timp_ext[10]; // struct tm + a ptr |
|---|
| 462 | _memcpy(timp_ext,timp,9*sizeof(int)); |
|---|
| 463 | timp_ext[9]=0; |
|---|
| 464 | long retval = _mktime_ext(&timp_ext); |
|---|
| 465 | _memcpy(timp,timp_ext,9*sizeof(int)); |
|---|
| 466 | return retval; |
|---|
| 467 | #endif |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | double _log(double x) { |
|---|
| 471 | return __log(x); |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | double _log10(double x) { |
|---|
| 475 | return __log10(x); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | double _pow(double x, double y) { |
|---|
| 479 | return __pow(x, y); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | double _sqrt(double x) { |
|---|
| 483 | return __sqrt(x); |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | #ifdef OPT_EXMEM_MALLOC |
|---|
| 487 | // I set this up to 16 mb and it still booted... |
|---|
| 488 | #define EXMEM_HEAP_SIZE (1024*1024*2) |
|---|
| 489 | // these aren't currently needed elsewhere |
|---|
| 490 | /* |
|---|
| 491 | void * exmem_alloc(unsigned pool_id, unsigned size) |
|---|
| 492 | { |
|---|
| 493 | return _exmem_alloc(pool_id,size,0); |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | void exmem_free(unsigned pool_id) |
|---|
| 497 | { |
|---|
| 498 | _exmem_free(pool_id); |
|---|
| 499 | } |
|---|
| 500 | */ |
|---|
| 501 | |
|---|
| 502 | static void *exmem_heap; |
|---|
| 503 | |
|---|
| 504 | void *suba_init(void *heap, unsigned size, unsigned rst, unsigned mincell); |
|---|
| 505 | void *suba_alloc(void *heap, unsigned size, unsigned zero); |
|---|
| 506 | int suba_free(void *heap, void *p); |
|---|
| 507 | |
|---|
| 508 | void exmem_malloc_init() { |
|---|
| 509 | // pool zero is EXMEM_RAMDISK on d10 |
|---|
| 510 | void *mem = _exmem_alloc(0,EXMEM_HEAP_SIZE,0); |
|---|
| 511 | if(mem) { |
|---|
| 512 | exmem_heap = suba_init(mem,EXMEM_HEAP_SIZE,1,1024); |
|---|
| 513 | } |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | void *malloc(unsigned size) { |
|---|
| 517 | if(exmem_heap) |
|---|
| 518 | return suba_alloc(exmem_heap,size,0); |
|---|
| 519 | else |
|---|
| 520 | return _malloc(size); |
|---|
| 521 | } |
|---|
| 522 | void free(void *p) { |
|---|
| 523 | if(exmem_heap) |
|---|
| 524 | suba_free(exmem_heap,p); |
|---|
| 525 | else |
|---|
| 526 | _free(p); |
|---|
| 527 | } |
|---|
| 528 | // regular malloc |
|---|
| 529 | #else |
|---|
| 530 | void *malloc(long size) { |
|---|
| 531 | return _malloc(size); |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | void free(void *p) { |
|---|
| 535 | return _free(p); |
|---|
| 536 | } |
|---|
| 537 | #endif |
|---|
| 538 | |
|---|
| 539 | void *memcpy(void *dest, const void *src, long n) { |
|---|
| 540 | return _memcpy(dest, src, n); |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | void *memset(void *s, int c, int n) { |
|---|
| 544 | return _memset(s, c, n); |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | int memcmp(const void *s1, const void *s2, long n) { |
|---|
| 548 | return _memcmp(s1, s2, n); |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | void *memchr(const void *s, int c, int n) { |
|---|
| 552 | #if !CAM_DRYOS |
|---|
| 553 | return _memchr(s,c,n); |
|---|
| 554 | #else |
|---|
| 555 | while (n-- > 0) { |
|---|
| 556 | if (*(char *)s == c) |
|---|
| 557 | return (void *)s; |
|---|
| 558 | s++; |
|---|
| 559 | } |
|---|
| 560 | return (void *)0; |
|---|
| 561 | #endif |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | int rand(void) { |
|---|
| 565 | return _rand(); |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | void *srand(unsigned int seed) { |
|---|
| 569 | return _srand(seed); |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | void qsort(void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2)) { |
|---|
| 573 | _qsort(__base, __nelem, __size, __cmp); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | void *opendir(const char* name) { |
|---|
| 577 | return _opendir(name); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | void* readdir(void *d) { |
|---|
| 581 | # if !CAM_DRYOS |
|---|
| 582 | return _readdir(d); |
|---|
| 583 | #else |
|---|
| 584 | // for DRYOS cameras A650, A720 do something with this! - sizeof(de[]) must be >= sizeof(struct dirent): 'static char de[40];' |
|---|
| 585 | static char de[40]; |
|---|
| 586 | _ReadFastDir(d, &de); |
|---|
| 587 | return de[0]? &de : (void*)0; |
|---|
| 588 | #endif |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | int closedir(void *d) { |
|---|
| 592 | return _closedir(d); |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | void rewinddir(void *d) { |
|---|
| 596 | return _rewinddir(d); |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | int stat(char *name, void *pStat) { |
|---|
| 600 | return _stat(name, pStat); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | void *umalloc(long size) { |
|---|
| 604 | return _AllocateUncacheableMemory(size); |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | void ufree(void *p) { |
|---|
| 608 | return _FreeUncacheableMemory(p); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | static int shutdown_disabled = 0; |
|---|
| 612 | void disable_shutdown() { |
|---|
| 613 | if (!shutdown_disabled) { |
|---|
| 614 | _LockMainPower(); |
|---|
| 615 | shutdown_disabled = 1; |
|---|
| 616 | } |
|---|
| 617 | } |
|---|
| 618 | |
|---|
| 619 | void enable_shutdown() { |
|---|
| 620 | if (shutdown_disabled) { |
|---|
| 621 | _UnlockMainPower(); |
|---|
| 622 | shutdown_disabled = 0; |
|---|
| 623 | } |
|---|
| 624 | } |
|---|
| 625 | void camera_shutdown_in_a_second(void){ |
|---|
| 626 | int i; |
|---|
| 627 | //#if CAM_DRYOS |
|---|
| 628 | //#else |
|---|
| 629 | _SetAutoShutdownTime(1); // 1 sec |
|---|
| 630 | for (i=0;i<200;i++) _UnlockMainPower(); // set power unlock counter to 200 or more, because every keyboard function call try to lock power again ( if "Disable LCD off" menu is "alt" or "script"). |
|---|
| 631 | //#endif |
|---|
| 632 | } |
|---|
| 633 | long MakeDirectory_Fut(const char *dirname) { |
|---|
| 634 | return _MakeDirectory_Fut(dirname,-1); // meaning of second arg is not clear, firmware seems to use -1 |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | long Fopen_Fut(const char *filename, const char *mode){ |
|---|
| 638 | return _Fopen_Fut(filename,mode); |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | long Fclose_Fut(long file){ |
|---|
| 642 | return _Fclose_Fut(file); |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | long Fread_Fut(void *buf, long elsize, long count, long f){ |
|---|
| 646 | return _Fread_Fut(buf, elsize, count, f); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | long Fwrite_Fut(const void *buf, long elsize, long count, long f){ |
|---|
| 650 | return _Fwrite_Fut(buf, elsize, count, f); |
|---|
| 651 | } |
|---|
| 652 | |
|---|
| 653 | long Fseek_Fut(long file, long offset, long whence){ |
|---|
| 654 | return _Fseek_Fut(file, offset, whence); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | long Feof_Fut(long file) { |
|---|
| 658 | return _Feof_Fut(file); |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | long Fflush_Fut(long file) { |
|---|
| 662 | return _Fflush_Fut(file); |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | char *Fgets_Fut(char *buf, int n, long f) { |
|---|
| 666 | return _Fgets_Fut(buf,n,f); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | long RenameFile_Fut(const char *oldname, const char *newname) { |
|---|
| 670 | return _RenameFile_Fut(oldname, newname); |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | int rename(const char *oldname, const char *newname){ |
|---|
| 674 | // doesn't appear to work on a540 |
|---|
| 675 | return _rename(oldname, newname); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | long DeleteFile_Fut(const char *name) { |
|---|
| 679 | return _DeleteFile_Fut(name); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | unsigned int GetFreeCardSpaceKb(void){ |
|---|
| 683 | return (_GetDrive_FreeClusters(0)*(_GetDrive_ClusterSize(0)>>9))>>1; |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | unsigned int GetTotalCardSpaceKb(void){ |
|---|
| 687 | return (_GetDrive_TotalClusters(0)*(_GetDrive_ClusterSize(0)>>9))>>1; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | unsigned int GetJpgCount(void){ |
|---|
| 692 | |
|---|
| 693 | return strtol(camera_jpeg_count_str(),((void*)0),0); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | unsigned int GetRawCount(void){ |
|---|
| 697 | return GetFreeCardSpaceKb()/((hook_raw_size() / 1024)+GetFreeCardSpaceKb()/GetJpgCount()); |
|---|
| 698 | |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | void EnterToCompensationEVF(void) |
|---|
| 702 | { |
|---|
| 703 | _EnterToCompensationEVF(); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | void ExitFromCompensationEVF() |
|---|
| 707 | { |
|---|
| 708 | _ExitFromCompensationEVF(); |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | void TurnOnBackLight(void) |
|---|
| 712 | { |
|---|
| 713 | _TurnOnBackLight(); |
|---|
| 714 | } |
|---|
| 715 | |
|---|
| 716 | void TurnOffBackLight(void) |
|---|
| 717 | { |
|---|
| 718 | _TurnOffBackLight(); |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | void DoAFLock(void) |
|---|
| 722 | { |
|---|
| 723 | _DoAFLock(); |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | void UnlockAF(void) |
|---|
| 727 | { |
|---|
| 728 | _UnlockAF(); |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | #if CAM_MULTIPART |
|---|
| 732 | |
|---|
| 733 | #define SECTOR_SIZE 512 |
|---|
| 734 | static char *mbr_buf=(void*)0; |
|---|
| 735 | static unsigned long drive_sectors; |
|---|
| 736 | |
|---|
| 737 | int is_mbr_loaded() |
|---|
| 738 | { |
|---|
| 739 | return (mbr_buf == (void*)0) ? 0 : 1; |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | #ifndef CAM_DRYOS |
|---|
| 743 | |
|---|
| 744 | int mbr_read(char* mbr_sector, unsigned long drive_total_sectors, unsigned long *part_start_sector, unsigned long *part_length){ |
|---|
| 745 | // return value: 1 - success, 0 - fail |
|---|
| 746 | // called only in VxWorks |
|---|
| 747 | |
|---|
| 748 | int offset=0x10; // points to partition #2 |
|---|
| 749 | int valid; |
|---|
| 750 | |
|---|
| 751 | if ((mbr_sector[0x1FE]!=0x55) || (mbr_sector[0x1FF]!=0xAA)) return 0; // signature check |
|---|
| 752 | |
|---|
| 753 | mbr_buf=_AllocateUncacheableMemory(SECTOR_SIZE); |
|---|
| 754 | _memcpy(mbr_buf,mbr_sector,SECTOR_SIZE); |
|---|
| 755 | drive_sectors=drive_total_sectors; |
|---|
| 756 | |
|---|
| 757 | while(offset>=0) { |
|---|
| 758 | |
|---|
| 759 | *part_start_sector=(*(unsigned short*)(mbr_sector+offset+0x1C8)<<16) | *(unsigned short*)(mbr_sector+offset+0x1C6); |
|---|
| 760 | *part_length=(*(unsigned short*)(mbr_sector+offset+0x1CC)<<16) | *(unsigned short*)(mbr_sector+offset+0x1CA); |
|---|
| 761 | |
|---|
| 762 | valid= (*part_start_sector) && (*part_length) && |
|---|
| 763 | (*part_start_sector<=drive_total_sectors) && |
|---|
| 764 | (*part_start_sector+*part_length<=drive_total_sectors) && |
|---|
| 765 | ((mbr_sector[offset+0x1BE]==0) || (mbr_sector[offset+0x1BE]==0x80)); // status: 0x80 (active) or 0 (non-active) |
|---|
| 766 | |
|---|
| 767 | if (valid && ((mbr_sector[0x1C2+offset]==0x0B) || (mbr_sector[0x1C2+offset]==0x0C))) break; // FAT32 secondary partition |
|---|
| 768 | |
|---|
| 769 | offset-=0x10; |
|---|
| 770 | |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | return valid; |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | #else |
|---|
| 777 | |
|---|
| 778 | int mbr_read_dryos(unsigned long drive_total_sectors, char* mbr_sector ){ |
|---|
| 779 | // Called only in DRYOS |
|---|
| 780 | mbr_buf=_AllocateUncacheableMemory(SECTOR_SIZE); |
|---|
| 781 | _memcpy(mbr_buf,mbr_sector,SECTOR_SIZE); |
|---|
| 782 | drive_sectors=drive_total_sectors; |
|---|
| 783 | return drive_total_sectors; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | #endif |
|---|
| 787 | |
|---|
| 788 | int get_part_count(void){ |
|---|
| 789 | unsigned long part_start_sector, part_length; |
|---|
| 790 | char part_status, part_type; |
|---|
| 791 | int i; |
|---|
| 792 | int count=0; |
|---|
| 793 | if (is_mbr_loaded()) |
|---|
| 794 | { |
|---|
| 795 | for (i=0; i<=1;i++){ |
|---|
| 796 | part_start_sector=(*(unsigned short*)(mbr_buf+i*16+0x1C8)<<16) | *(unsigned short*)(mbr_buf+i*16+0x1C6); |
|---|
| 797 | part_length=(*(unsigned short*)(mbr_buf+i*16+0x1CC)<<16) | *(unsigned short*)(mbr_buf+i*16+0x1CA); |
|---|
| 798 | part_status=mbr_buf[i*16+0x1BE]; |
|---|
| 799 | part_type=mbr_buf[0x1C2+i*16]; |
|---|
| 800 | if ( part_start_sector && part_length && part_type && ((part_status==0) || (part_status==0x80)) ) count++; |
|---|
| 801 | } |
|---|
| 802 | } |
|---|
| 803 | return count; |
|---|
| 804 | } |
|---|
| 805 | |
|---|
| 806 | void swap_partitions(void){ |
|---|
| 807 | if (is_mbr_loaded()) |
|---|
| 808 | { |
|---|
| 809 | int i; |
|---|
| 810 | char c; |
|---|
| 811 | for(i=0;i<16;i++){ |
|---|
| 812 | c=mbr_buf[i+0x1BE]; |
|---|
| 813 | mbr_buf[i+0x1BE]=mbr_buf[i+0x1CE]; |
|---|
| 814 | mbr_buf[i+0x1CE]=c; |
|---|
| 815 | } |
|---|
| 816 | _WriteSDCard(0,0,1,mbr_buf); |
|---|
| 817 | } |
|---|
| 818 | } |
|---|
| 819 | |
|---|
| 820 | void create_partitions(void){ |
|---|
| 821 | if (is_mbr_loaded()) |
|---|
| 822 | { |
|---|
| 823 | unsigned long start, length; |
|---|
| 824 | char type; |
|---|
| 825 | |
|---|
| 826 | _memset(mbr_buf,0,SECTOR_SIZE); |
|---|
| 827 | |
|---|
| 828 | start=1; length=2*1024*1024/SECTOR_SIZE; //2 Mb |
|---|
| 829 | type=1; // FAT primary |
|---|
| 830 | mbr_buf[0x1BE + 4]=type; |
|---|
| 831 | mbr_buf[0x1BE + 8]=start; mbr_buf[0x1BE + 9]=start>>8; mbr_buf[0x1BE + 10]=start>>16; mbr_buf[0x1BE + 11]=start>>24; |
|---|
| 832 | mbr_buf[0x1BE + 12]=length; mbr_buf[0x1BE + 13]=length>>8; mbr_buf[0x1BE + 14]=length>>16; mbr_buf[0x1BE + 15]=length>>24; |
|---|
| 833 | |
|---|
| 834 | start=start+length; length=drive_sectors-start-1; |
|---|
| 835 | type=0x0B; //FAT32 primary; |
|---|
| 836 | mbr_buf[0x1CE + 4]=type; |
|---|
| 837 | mbr_buf[0x1CE + 8]=start; mbr_buf[0x1CE + 9]=start>>8; mbr_buf[0x1CE + 10]=start>>16; mbr_buf[0x1CE + 11]=start>>24; |
|---|
| 838 | mbr_buf[0x1CE + 12]=length; mbr_buf[0x1CE + 13]=length>>8; mbr_buf[0x1CE + 14]=length>>16; mbr_buf[0x1CE + 15]=length>>24; |
|---|
| 839 | |
|---|
| 840 | mbr_buf[0x1FE]=0x55; mbr_buf[0x1FF]=0xAA; // signature; |
|---|
| 841 | |
|---|
| 842 | _WriteSDCard(0,0,1,mbr_buf); |
|---|
| 843 | } |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | #endif |
|---|
| 847 | |
|---|
| 848 | int mute_on_zoom(int x){ |
|---|
| 849 | static int old_busy=0; |
|---|
| 850 | int busy=zoom_busy||focus_busy; |
|---|
| 851 | if (old_busy!=busy) { |
|---|
| 852 | if (busy) { |
|---|
| 853 | #if CAM_CAN_MUTE_MICROPHONE |
|---|
| 854 | if (conf.mute_on_zoom) _TurnOffMic(); |
|---|
| 855 | #endif |
|---|
| 856 | } |
|---|
| 857 | else { |
|---|
| 858 | #if CAM_CAN_MUTE_MICROPHONE |
|---|
| 859 | if (conf.mute_on_zoom) _TurnOnMic(); |
|---|
| 860 | #endif |
|---|
| 861 | #if CAM_EV_IN_VIDEO |
|---|
| 862 | if (get_ev_video_avail()) set_ev_video_avail(0); |
|---|
| 863 | #endif |
|---|
| 864 | } |
|---|
| 865 | old_busy=busy; |
|---|
| 866 | } |
|---|
| 867 | return x; // preserve R0 if called from assembler |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | #if CAM_AF_SCAN_DURING_VIDEO_RECORD |
|---|
| 872 | void MakeAFScan(void){ |
|---|
| 873 | int a=0, save; |
|---|
| 874 | if (zoom_busy || focus_busy) return; |
|---|
| 875 | save=some_flag_for_af_scan; |
|---|
| 876 | some_flag_for_af_scan=0; |
|---|
| 877 | #if CAM_AF_SCAN_DURING_VIDEO_RECORD == 2 |
|---|
| 878 | parameter_for_af_scan=3; |
|---|
| 879 | #endif |
|---|
| 880 | _MakeAFScan(&a, 3); |
|---|
| 881 | some_flag_for_af_scan=save; |
|---|
| 882 | _ExpCtrlTool_StartContiAE(0,0); |
|---|
| 883 | } |
|---|
| 884 | #endif |
|---|
| 885 | |
|---|
| 886 | long __attribute__((weak)) get_jogdial_direction(void){ |
|---|
| 887 | return 0; |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | #if defined (DNG_EXT_FROM) |
|---|
| 891 | |
|---|
| 892 | #define DNG_EXT_TO ".DNG" |
|---|
| 893 | |
|---|
| 894 | typedef int(*p_some_f)(char*, int); |
|---|
| 895 | |
|---|
| 896 | extern p_some_f some_f_for_dng; // camera variable! |
|---|
| 897 | extern char* second_ext_for_dng; // camera variable! |
|---|
| 898 | |
|---|
| 899 | p_some_f default_some_f; |
|---|
| 900 | char * default_second_ext; |
|---|
| 901 | |
|---|
| 902 | char *_strstr (const char *s1, const char *s2) |
|---|
| 903 | { |
|---|
| 904 | const char *p = s1; |
|---|
| 905 | const int len = _strlen (s2); |
|---|
| 906 | |
|---|
| 907 | for (; (p = _strchr (p, *s2)) != 0; p++) |
|---|
| 908 | { |
|---|
| 909 | if (_strncmp (p, s2, len) == 0) |
|---|
| 910 | return (char *)p; |
|---|
| 911 | } |
|---|
| 912 | return (0); |
|---|
| 913 | } |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | int my_some_f(char *s, int x){ |
|---|
| 917 | char *f; |
|---|
| 918 | f=_strstr(s, DNG_EXT_FROM); |
|---|
| 919 | if (f) _memcpy(f, DNG_EXT_TO, sizeof(DNG_EXT_TO)-1); |
|---|
| 920 | return default_some_f(s, x); |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | void save_ext_for_dng(void){ |
|---|
| 924 | default_some_f=some_f_for_dng; |
|---|
| 925 | default_second_ext=second_ext_for_dng; |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | void change_ext_to_dng(void){ |
|---|
| 929 | some_f_for_dng=my_some_f; |
|---|
| 930 | second_ext_for_dng=DNG_EXT_TO; |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | void change_ext_to_default(void){ |
|---|
| 934 | some_f_for_dng=default_some_f; |
|---|
| 935 | second_ext_for_dng=default_second_ext; |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | #endif |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | static long drv_struct[16]; |
|---|
| 942 | |
|---|
| 943 | long dh_err() |
|---|
| 944 | { |
|---|
| 945 | return -1; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | void drv_self_hide() |
|---|
| 949 | { |
|---|
| 950 | #if !CAM_DRYOS |
|---|
| 951 | long drvnum; |
|---|
| 952 | |
|---|
| 953 | drvnum = _iosDrvInstall(dh_err,dh_err,dh_err,dh_err,dh_err,dh_err,dh_err); |
|---|
| 954 | if (drvnum >= 0) |
|---|
| 955 | _iosDevAdd(drv_struct, "A/DISKBOOT.BIN", drvnum); |
|---|
| 956 | #endif |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | void drv_self_unhide(){ |
|---|
| 960 | #if !CAM_DRYOS |
|---|
| 961 | _iosDevDelete(drv_struct); |
|---|
| 962 | #endif |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | int apex2us(int apex_tv){ |
|---|
| 966 | #if CAM_EXT_TV_RANGE |
|---|
| 967 | /* |
|---|
| 968 | Extended Tv, by barberofcivil, http://chdk.setepontos.com/index.php/topic,4392.0.html |
|---|
| 969 | Explanation by reyalP: |
|---|
| 970 | In every port, the original shutter overrides (as opposed to super long exposure) worked by |
|---|
| 971 | setting the propcase values at some point after auto-exposure has happened (except in manual |
|---|
| 972 | modes, where the manual control propcases may be used instead). The Canon code previously took |
|---|
| 973 | these values unchanged for short exposures. In newer cameras, like on the SX10 / SD980, the value |
|---|
| 974 | is changed, apparently some time after it has been retrieved from the propcase. We know this is |
|---|
| 975 | the case, because the propcase value itself doesn't get clamped to the allowed range (if it did, |
|---|
| 976 | barberofcivil's code wouldn't work). |
|---|
| 977 | */ |
|---|
| 978 | short tv; |
|---|
| 979 | tv = shooting_get_tv96(); |
|---|
| 980 | if (tv<-576 || tv!=apex_tv) return 1000000.0*pow(2.0, -tv/96.0); |
|---|
| 981 | else return _apex2us(apex_tv); |
|---|
| 982 | #else |
|---|
| 983 | return 0; |
|---|
| 984 | #endif |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | void PostLogicalEventForNotPowerType(unsigned id, unsigned x) { |
|---|
| 988 | _PostLogicalEventForNotPowerType(id,x); |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | void PostLogicalEventToUI(unsigned id, unsigned x) { |
|---|
| 992 | _PostLogicalEventToUI(id,x); |
|---|
| 993 | } |
|---|
| 994 | |
|---|
| 995 | void SetLogicalEventActive(unsigned id, unsigned state) { |
|---|
| 996 | _SetLogicalEventActive(id, state); |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | void SetScriptMode(unsigned mode) { |
|---|
| 1000 | _SetScriptMode(mode); |
|---|
| 1001 | } |
|---|
| 1002 | |
|---|
| 1003 | // TODO this belongs lib.c, but not all cameras include it |
|---|
| 1004 | // same as bitmap width for most cameras, override in platform/sub/lib.c as needed |
|---|
| 1005 | int __attribute__((weak)) vid_get_viewport_width() { |
|---|
| 1006 | return vid_get_bitmap_screen_width(); |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | void __attribute__((weak)) vid_turn_off_updates() |
|---|
| 1010 | { |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | void __attribute__((weak)) vid_turn_on_updates() |
|---|
| 1014 | { |
|---|
| 1015 | } |
|---|
| 1016 | |
|---|
| 1017 | // use _GetFocusLensSubjectDistance for this on dryos, vx functions are basically equivlent |
|---|
| 1018 | // not used in CHDK currently for either OS |
|---|
| 1019 | #ifdef CAM_DRYOS |
|---|
| 1020 | long __attribute__((weak)) _GetCurrentTargetDistance() |
|---|
| 1021 | { |
|---|
| 1022 | return _GetFocusLensSubjectDistance(); |
|---|
| 1023 | } |
|---|
| 1024 | #endif |
|---|
| 1025 | |
|---|
| 1026 | #ifdef CAM_CHDK_PTP |
|---|
| 1027 | int add_ptp_handler(int opcode, ptp_handler handler, int unknown) |
|---|
| 1028 | { |
|---|
| 1029 | return _add_ptp_handler(opcode,handler,unknown); |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | // this would make more sense in generic/main.c but not all a cameras use it |
|---|
| 1033 | void init_chdk_ptp_task() { |
|---|
| 1034 | _CreateTask("InitCHDKPTP", 0x19, 0x2000, init_chdk_ptp, 0); |
|---|
| 1035 | }; |
|---|
| 1036 | |
|---|
| 1037 | #endif |
|---|
| 1038 | |
|---|
| 1039 | void ExitTask() |
|---|
| 1040 | { |
|---|
| 1041 | _ExitTask(); |
|---|
| 1042 | } |
|---|
| 1043 | |
|---|
| 1044 | // TODO not in sigs for vx yet |
|---|
| 1045 | #ifndef CAM_DRYOS |
|---|
| 1046 | void __attribute__((weak)) _reboot_fw_update(const char *fw_update) |
|---|
| 1047 | { |
|---|
| 1048 | return; |
|---|
| 1049 | } |
|---|
| 1050 | #endif |
|---|
| 1051 | |
|---|
| 1052 | int __attribute__((weak)) switch_mode_usb(int mode) |
|---|
| 1053 | { |
|---|
| 1054 | return 0; |
|---|
| 1055 | } |
|---|
| 1056 | /* |
|---|
| 1057 | // this wrapper isn't currently needed |
|---|
| 1058 | // 7 calls functions and sets some MMIOs, but doesn't disable caches and actually restart |
|---|
| 1059 | // 3 skips one function call on some cameras, but does restart |
|---|
| 1060 | void Restart(unsigned option) { |
|---|
| 1061 | _Restart(option); |
|---|
| 1062 | } |
|---|
| 1063 | */ |
|---|
| 1064 | |
|---|