Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch temp Excluding Merge-Ins
This is equivalent to a diff from 095cfb3932 to cf92beadf9
2013-09-17
| ||
22:43 |
Split out ITEM creation into separate func so can clean on exit
As otherwise can't free up the memory, etc. This makes clean up work Yay, pretty much done. Leaf check-in: cf92beadf9 user: base@atomicules.co.uk tags: temp, trunk | |
2013-09-15
| ||
21:25 | Ignore selection of OVER/UNDER check-in: d4b0749e89 user: base@atomicules.co.uk tags: temp, trunk | |
2013-09-12
| ||
12:02 |
For ref: That should have always been a pointer
Although this version still no worky Leaf check-in: b786f69eac user: base@atomicules.co.uk tags: temp2, trunk | |
2013-09-11
| ||
21:46 | For ref: Try separate win and menu functions check-in: 878d5d8315 user: base@atomicules.co.uk tags: temp, trunk | |
21:44 | Add debug options to Makefile check-in: 095cfb3932 user: base@atomicules.co.uk tags: temp2, trunk | |
21:41 | For ref: Wrap menu and window creation in function check-in: 284f5d1a81 user: base@atomicules.co.uk tags: temp2, trunk | |
Changes to exposurses.c.
︙ | ︙ | |||
28 29 30 31 32 33 34 | "10", "11", "12", "13", "14", "15", "16", | < < > | > < > < > > > | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | "10", "11", "12", "13", "14", "15", "16", }; char *iso_array[] = { "50", "100", "200", "400", "800", "1600", "3200", }; char *shutter_array[] = { "OVER", "1/1000", "1/500", "1/250", "1/125", "1/60", "1/30", "1/15", "1/8", "1/4", "1/2", "1", "UNDER", }; char *aperture_array[] = { "UNDER", "f/1.4", "f/2", "f/2.8", "f/4", "f/5.6", "f/8", "f/11", "f/16", "OVER", }; ITEM **exposure_items; ITEM **iso_items; ITEM **shutter_items; ITEM **aperture_items; MENU *exposure_menu; MENU *iso_menu; MENU *shutter_menu; MENU *aperture_menu; WINDOW *exposure_win; WINDOW *iso_win; WINDOW *shutter_win; WINDOW *aperture_win; void selection(char *name); void remove_menu(ITEM **items, MENU *men, int n); void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); MENU *add_menu(ITEM **items); WINDOW *add_window(int xpos, char *title); ITEM **add_item(char **array, int n); int exposure(int iso); double shutter(int exposure, double aperture); double aperture(int exposure, double shutter); int nearest_match(double x, int menu, int n_array); double fraction_to_double(char *fraction); /* No one will ever need more than 9 bytes! */ char exposure_sel[9] = ""; char iso_sel[9] = ""; char shutter_sel[9] = ""; char aperture_sel[9] = ""; int selection_counter = 1; |
︙ | ︙ | |||
124 125 126 127 128 129 130 | /* Create items */ /* Can't really avoid finding array sizes here */ n_exposure = ARRAY_SIZE(exposure_array); n_iso = ARRAY_SIZE(iso_array); n_shutter = ARRAY_SIZE(shutter_array); n_aperture = ARRAY_SIZE(aperture_array); | > > > > > > > > > > > > > > | | | | | > > > > > > > > > > > | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | /* Create items */ /* Can't really avoid finding array sizes here */ n_exposure = ARRAY_SIZE(exposure_array); n_iso = ARRAY_SIZE(iso_array); n_shutter = ARRAY_SIZE(shutter_array); n_aperture = ARRAY_SIZE(aperture_array); /* http://stackoverflow.com/a/2620158/208793 */ exposure_items = add_item(exposure_array, n_exposure); iso_items = add_item(iso_array, n_iso); aperture_items = add_item(aperture_array, n_aperture); shutter_items = add_item(shutter_array, n_shutter); exposure_menu = add_menu(exposure_items); iso_menu = add_menu(iso_items); shutter_menu = add_menu(shutter_items); aperture_menu = add_menu(aperture_items); exposure_win = add_window(4, "EV"); iso_win = add_window(45, "ISO"); shutter_win = add_window(86, "Shutter"); aperture_win = add_window(127, "Aperture"); /* Don't know how to avoid the repition below */ set_menu_win(exposure_menu, exposure_win); set_menu_win(iso_menu, iso_win); set_menu_win(shutter_menu, shutter_win); set_menu_win(aperture_menu, aperture_win); set_menu_sub(exposure_menu, derwin(exposure_win, 6, 38, 3, 1)); set_menu_sub(iso_menu, derwin(iso_win, 6, 38, 3, 1)); set_menu_sub(shutter_menu, derwin(shutter_win, 6, 38, 3, 1)); set_menu_sub(aperture_menu, derwin(aperture_win, 6, 38, 3, 1)); post_menu(exposure_menu); post_menu(iso_menu); post_menu(shutter_menu); post_menu(aperture_menu); wrefresh(exposure_win); wrefresh(iso_win); wrefresh(shutter_win); wrefresh(aperture_win); attron(COLOR_PAIR(2)); mvprintw(LINES - 2, 0, "Select EV"); /*mvprintw(LINES - 2, 0, "Select ISO and then one of Shutter/Aperture to calculate other of Shutter/Aperture");*/ mvprintw(LINES - 1, 0, "Arrow keys to navigate, Enter to select, Q to exit"); attroff(COLOR_PAIR(2)); refresh(); |
︙ | ︙ | |||
171 172 173 174 175 176 177 | void (*p)(char *); cur = current_item(*menu); p = item_userptr(cur); /* Learning notes - Don't understand this bit */ /* Is this a function pointer? */ p((char *)item_name(cur)); | | > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < > > | | | | | | | | | | | | | < > > | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > > | | > | | | | > | < > | | > | | > > > > > > > > | | | | | < | | 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | void (*p)(char *); cur = current_item(*menu); p = item_userptr(cur); /* Learning notes - Don't understand this bit */ /* Is this a function pointer? */ p((char *)item_name(cur)); /* need to igore over/under if selected, probably easier than try to prevent selection */ if (!((strcmp("OVER", shutter_sel) == 0) || (strcmp("UNDER", shutter_sel) == 0) || (strcmp("OVER", aperture_sel) == 0) || (strcmp("UNDER", aperture_sel) == 0))) { switch (selection_counter) { case 1: { /* Exposure selected */ selection_counter += 1; menu_counter += 1; move(LINES - 2, 0); clrtoeol(); mvprintw(LINES - 2, 0, "Select ISO"); refresh(); menu = &iso_menu; win = &iso_win; } break; case 2: { /* ISO Selected */ selection_counter += 1; menu_counter += 1; move(LINES - 2, 0); clrtoeol(); mvprintw(LINES - 2, 0, "Select Shutter or Aperture"); refresh(); menu = &shutter_menu; win = &shutter_win; } break; case 3: { /* Shutter or Aperture selected */ if (strcmp("", shutter_sel) == 0) { char aperture_sel_[4] = ""; strncpy(aperture_sel_, aperture_sel+2, 3); /* Using menu_driver to go up/down to force refresh and correct highlighting */ menu_driver(shutter_menu, REQ_SCR_UPAGE); menu_driver(shutter_menu, REQ_SCR_DPAGE); /* There is probably a nicer way to format the below */ set_menu_pattern( shutter_menu, shutter_array[nearest_match( shutter(exposure(atoi(iso_sel)), strtod(aperture_sel_, NULL)), 3, n_shutter )] ); menu_driver(shutter_menu, REQ_DOWN_ITEM); menu_driver(shutter_menu, REQ_UP_ITEM); wrefresh(shutter_win); } if (strcmp("", aperture_sel) == 0) { menu_driver(aperture_menu, REQ_SCR_UPAGE); menu_driver(aperture_menu, REQ_SCR_DPAGE); set_menu_pattern( aperture_menu, aperture_array[nearest_match( aperture(exposure(atoi(iso_sel)), fraction_to_double(shutter_sel)), 4, n_aperture )] ); menu_driver(aperture_menu, REQ_DOWN_ITEM); menu_driver(aperture_menu, REQ_UP_ITEM); wrefresh(aperture_win); } /* clear the selections for next time */ strcpy(iso_sel, ""); strcpy(shutter_sel, ""); strcpy(aperture_sel, ""); /* And set defaults back to start */ selection_counter = 1; menu_counter = 1; menu = &exposure_menu; win = &exposure_win; move(LINES - 2, 0); clrtoeol(); mvprintw(LINES - 2, 0, "Select EV"); refresh(); } break; } } /* If over/under need to clear selection so know which is blank * when a proper selection is made */ if ((strcmp("OVER", shutter_sel) == 0) || (strcmp("UNDER", shutter_sel) == 0)) { strcpy(shutter_sel, ""); } if ((strcmp("OVER", aperture_sel) == 0) || (strcmp("UNDER", aperture_sel) == 0)) { strcpy(aperture_sel, ""); } } break; } wrefresh(*win); } /* Unpost and free all the memory taken up */ remove_menu(exposure_items, exposure_menu, n_exposure); remove_menu(iso_items, iso_menu, n_iso); remove_menu(shutter_items, shutter_menu, n_shutter); remove_menu(aperture_items, aperture_menu, n_aperture); endwin(); } ITEM **add_item(char **array, int n) { int i; ITEM **local_items; local_items = (ITEM **)calloc(n, sizeof(ITEM *)); for(i = 0; i<n; ++i) { local_items[i] = new_item(array[i], array[i]); set_item_userptr(local_items[i], selection); } return local_items; } MENU *add_menu(ITEM **items) { MENU *local_menu; local_menu = new_menu((ITEM **)items); set_menu_format(local_menu, 5, 1); set_menu_mark(local_menu, " * "); return local_menu; } WINDOW *add_window(int xpos, char *title) { WINDOW *local_win; local_win = newwin(10, 40, 4, xpos); keypad(local_win, TRUE); box(local_win, 0, 0); print_in_middle(local_win, 1, 0, 40, title, COLOR_PAIR(1)); mvwaddch(local_win, 2, 0, ACS_LTEE); mvwhline(local_win, 2, 1, ACS_HLINE, 38); mvwaddch(local_win, 2, 39, ACS_RTEE); return local_win; } void remove_menu(ITEM **items, MENU *men, int n) { int i; unpost_menu(men); free_menu(men); |
︙ | ︙ | |||
346 347 348 349 350 351 352 | } double aperture (int exposure, double shutter) { /* EV = log2 (N^2/t) */ return sqrt(pow(2, exposure) * shutter); } | | | | < < < | | | > > | | < < < < < < < < < > > > > > > > > > > > | | > > > > > > > > > > > > > > > > | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | } double aperture (int exposure, double shutter) { /* EV = log2 (N^2/t) */ return sqrt(pow(2, exposure) * shutter); } int nearest_match (double x, int menu, int n_array) { /* Need to search array for closest match */ int n; int diff_idx = 1; char array_value_str[9]; double array_value_db; double diff; /* Need a starting value for difference */ switch(menu) { case 3: array_value_db = fraction_to_double(shutter_array[1]); break; case 4: strncpy(array_value_str, aperture_array[1]+2, 4); array_value_db = strtod(array_value_str, NULL); break; } diff = fabs(array_value_db - x); /* lots of repetition here but pointers to arrays seem to be a bad thing */ /* Could do from n = 3 (2 above) until != under/over * but also need to do something like if diff is more than twice max/min then under/over */ switch(menu) { case 3: for ( n = 2; n < n_array-1; ++n ) { array_value_db = fraction_to_double(shutter_array[n]); if (fabs(array_value_db - x) < diff) { diff_idx = n; diff = fabs(array_value_db - x); } } /* Check if at extremities and then if under/over exposed */ if (diff_idx == 1) { if (diff >= fraction_to_double(shutter_array[1])/2) { /* diff is greater than diff of next one down minus max/min */ diff_idx = 0; } } if (diff_idx == n_array-2) { if (diff >= fraction_to_double(shutter_array[n_array-2])*2) { diff_idx = n_array-1; } } break; case 4: for ( n = 2; n < n_array-1; ++n ) { strncpy(array_value_str, aperture_array[n]+2, 4); array_value_db = strtod(array_value_str, NULL); if (fabs(array_value_db - x) < diff) { diff_idx = n; diff = fabs(array_value_db - x); } } /* Apertures similarly. Although progression is fiddlier.*/ if (diff_idx == 1) { strncpy(array_value_str, aperture_array[1]+2, 4); array_value_db = strtod(array_value_str, NULL); if (diff >= array_value_db/sqrt(2.0)) { /* diff is greater than diff of next one down minus max/min */ diff_idx = 0; } } if (diff_idx == n_array-2) { strncpy(array_value_str, aperture_array[n_array-2]+2, 4); array_value_db = strtod(array_value_str, NULL); if (diff >= array_value_db*sqrt(2.0)) { diff_idx = n_array-1; } } break; } return diff_idx; } double fraction_to_double(char *fraction) { double fraction_as_db; |
︙ | ︙ |