exposurses

Check-in [68919dca22]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Actually make it work this time. See this commit: 8d3e66b5ecffa8bcf7691c3f0600840b934beb1a I'm such an idiot. - Remove `set_top_row` when setting the shutter menu to the correct value. Leaving this in fooled me into thinking I had things working because I just happened to test on the matching ISO/Aperture values. Plonker. And then it turns out, there was loads wrong. - Need to include stdlib.h for `strtod` function, otherwise it uses some kind of stub function (no complaints in compile or use, but it just doesn't work). - Wasn't passing right kind of values to `shutter` anyway! Need to convert these to numeric - Need to use `fabs` not `abs` for doubles. - In `nearest_match` wasn't using the correct arrays, had copied over `iso_array` and forgotten to change them - Use `strstr` instead `strchr` as couldn't get the former to work and was probably the wrong one to be using - Leave some commented out stuff at the bottom that I've been using for debugging -
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 68919dca2202cbca1c44d4be3035d737ea6d88379dd4d2a36db5f83ecb300d1a
User & Date: base@atomicules.co.uk 2013-09-02 09:29:57
Context
2013-09-02
09:47
I am King of Fail I mean, just how? I think I need a few years more sleep or something check-in: 506ba48833 user: base@atomicules.co.uk tags: origin/master, trunk
09:29
Actually make it work this time. See this commit: 8d3e66b5ecffa8bcf7691c3f0600840b934beb1a I'm such an idiot. - Remove `set_top_row` when setting the shutter menu to the correct value. Leaving this in fooled me into thinking I had things working because I just happened to test on the matching ISO/Aperture values. Plonker. And then it turns out, there was loads wrong. - Need to include stdlib.h for `strtod` function, otherwise it uses some kind of stub function (no complaints in compile or use, but it just doesn't work). - Wasn't passing right kind of values to `shutter` anyway! Need to convert these to numeric - Need to use `fabs` not `abs` for doubles. - In `nearest_match` wasn't using the correct arrays, had copied over `iso_array` and forgotten to change them - Use `strstr` instead `strchr` as couldn't get the former to work and was probably the wrong one to be using - Leave some commented out stuff at the bottom that I've been using for debugging - check-in: 68919dca22 user: base@atomicules.co.uk tags: origin/master, trunk
2013-08-31
07:50
Try to standardise on a string length Since it doesn't matter if it's longer. And I'm only using short strings. check-in: 99eba10b76 user: base@atomicules.co.uk tags: origin/master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to exposurses.c.

1
2
3
4
5

6
7
8
9
10
11
12
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417





/* This file based on menu_scroll.c from:
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html */
#include <curses.h>
#include <menu.h>
#include <math.h>


#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

char *iso_array[] = {
	"50",
	"100",
	"200",
................................................................................
						/* Test finding nearest matching value in array? */
						char aperture_sel_[4] = "";
						strncpy(aperture_sel_, aperture_sel+2, 3);
						/* There is probably a nicer way to format the below */
						set_menu_pattern(
							shutter_menu,
							shutter_array[nearest_match(
								shutter(aperture_sel_, exposure(iso_sel)),
								2
							)]
						);
						set_top_row(shutter_menu, 3);
						menu_driver(shutter_menu, REQ_DOWN_ITEM);
						menu_driver(shutter_menu, REQ_UP_ITEM);
						wrefresh(shutter_win);
					}
					if (strcmp("", aperture_sel) == 0) {
						/* Tests setting to row number */
						set_top_row(aperture_menu, 3);
................................................................................
			array_value_db = fraction_to_double(shutter_array[0]);
			break;
		case 3:
			strncpy(array_value_str, aperture_array[0]+2, 3);
			array_value_db = strtod(array_value_str, NULL);
			break;
	}
	diff = abs(array_value_db - x);
	/* lots of repetition here but pointers to arrays seem to be a bad thing */
	switch(menu) {
		case 1:
			for ( n = 1; iso_array[n] != NULL; ++n ) {
				array_value_db = strtod(iso_array[n], NULL);
				if (abs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = abs(array_value_db - x);
				}
			}
			break;
		case 2:
			for ( n = 1; iso_array[n] != NULL; ++n ) {
				array_value_db = fraction_to_double(shutter_array[n]);
				if (abs(array_value_db - x) < diff) {
					diff_idx = n;
					diff = abs(array_value_db - x);
				}
			}
			break;
		case 3:
			for ( n = 1; iso_array[n] != NULL; ++n ) {
				strncpy(array_value_str, aperture_array[0]+2, 3);
				array_value_db = strtod(array_value_str, NULL);
				if (abs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = abs(array_value_db - x);
				}
			}
			break;
	}
	return diff_idx;
}

double fraction_to_double(char *fraction) {
	double fraction_as_db;
	char denominator[9];
	char *ptr = strchr(fraction, "/");

	if (ptr) {
		/*then split*/
		strncpy(denominator, fraction+2, 5);
		fraction_as_db = 1/strtod(denominator, NULL);
	}
	else {
		fraction_as_db = strtod(fraction, NULL);
	}
return fraction_as_db;
}










>







 







|



<







 







|





|

|




|

|

|




|


|

|










|




|






>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
...
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
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
/* This file based on menu_scroll.c from:
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html */
#include <curses.h>
#include <menu.h>
#include <math.h>
#include <stdlib.h>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

char *iso_array[] = {
	"50",
	"100",
	"200",
................................................................................
						/* Test finding nearest matching value in array? */
						char aperture_sel_[4] = "";
						strncpy(aperture_sel_, aperture_sel+2, 3);
						/* There is probably a nicer way to format the below */
						set_menu_pattern(
							shutter_menu,
							shutter_array[nearest_match(
								shutter(strtod(aperture_sel_, NULL), exposure(atoi(iso_sel))),
								2
							)]
						);

						menu_driver(shutter_menu, REQ_DOWN_ITEM);
						menu_driver(shutter_menu, REQ_UP_ITEM);
						wrefresh(shutter_win);
					}
					if (strcmp("", aperture_sel) == 0) {
						/* Tests setting to row number */
						set_top_row(aperture_menu, 3);
................................................................................
			array_value_db = fraction_to_double(shutter_array[0]);
			break;
		case 3:
			strncpy(array_value_str, aperture_array[0]+2, 3);
			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 */
	switch(menu) {
		case 1:
			for ( n = 1; iso_array[n] != NULL; ++n ) {
				array_value_db = strtod(iso_array[n], NULL);
				if (fabs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;
		case 2:
			for ( n = 1; shutter_array[n] != NULL; ++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);
				}
			}
			break;
		case 3:
			for ( n = 1; aperture_array[n] != NULL; ++n ) {
				strncpy(array_value_str, aperture_array[0]+2, 3);
				array_value_db = strtod(array_value_str, NULL);
				if (fabs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;
	}
	return diff_idx;
}

double fraction_to_double(char *fraction) {
	double fraction_as_db;
	char denominator[9];
	char *ptr = strstr(fraction, "/");

	if (ptr) {
		/*then split*/
		strncpy(denominator, fraction+2, 5);
		fraction_as_db = 1 / strtod(denominator, NULL);
	}
	else {
		fraction_as_db = strtod(fraction, NULL);
	}
return fraction_as_db;
}

/* Debug lines
 * sprintf(temp, "%f", x);
 * mvprintw(LINES - 4, 0, temp);
 * refresh();*/