exposurses

Check-in [6513b427e7]
Login

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

Overview
Comment:Implement functionality to calc req'd and then sel nearest match in menu

So far only implemented on Shutter menu, i.e. have to select ISO and
Aperture, it will then use the equations to calculate the exact required
shutter speed, but then select the nearest value in the menu.

In order to do that added these two functions:

- nearest_match
- fraction_to_double

The latter needed, because need to convert "1/1000", etc into float. For
Aperture menu items can just strip off the "f/".

Seems to work for Sunny 16.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 6513b427e7cb2d6191054029b8a73724a11be100601d6317c34b2a9d480a3ce3
User & Date: base@atomicules.co.uk 2013-08-29 23:24:17
Context
2013-08-31
07:47
Remove extraneous line that came from menu_scroll.c check-in: ed161d4179 user: base@atomicules.co.uk tags: origin/master, trunk
2013-08-29
23:24
Implement functionality to calc req'd and then sel nearest match in menu

So far only implemented on Shutter menu, i.e. have to select ISO and
Aperture, it will then use the equations to calculate the exact required
shutter speed, but then select the nearest value in the menu.

In order to do that added these two functions:

- nearest_match
- fraction_to_double

The latter needed, because need to convert "1/1000", etc into float. For
Aperture menu items can just strip off the "f/".

Seems to work for Sunny 16. check-in: 6513b427e7 user: base@atomicules.co.uk tags: origin/master, trunk

2013-08-27
12:00
Fix order of arguements in exposure functions check-in: c663824d67 user: base@atomicules.co.uk tags: origin/master, trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to exposurses.c.

10
11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26
27
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
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
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







-
+
+













-
+
+










-
+
+


















+
+







char *iso_array[] = {
	"50",
	"100",
	"200",
	"400",
	"800",
	"1600",
	"3200"
	"3200",
	NULL
};

char *shutter_array[] = {
	"1/1000",
	"1/500",
	"1/250",
	"1/125",
	"1/60",
	"1/30",
	"1/15",
	"1/8",
	"1/4",
	"1/2",
	"1"
	"1",
	NULL
};

char *aperture_array[] = {
	"f/1.4",
	"f/2",
	"f/2.8",
	"f/4",
	"f/5.6",
	"f/8",
	"f/11",
	"f/16"
	"f/16",
	NULL
};

ITEM **iso_items;
ITEM **shutter_items;
ITEM **aperture_items;
MENU *iso_menu;
MENU *shutter_menu;
MENU *aperture_menu;
WINDOW *iso_win;
WINDOW *shutter_win;
WINDOW *aperture_win;

void selection(char *name);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
int exposure(int iso);
int selection_counter;
double shutter(int exposure, double aperture);
double aperture(int exposure, int shutter);
int nearest_match(double x, int menu);
double fraction_to_double(char *fraction);

char iso_sel[5] = "";
char shutter_sel[7] = "";
char aperture_sel[6] = "";
int menu_counter = 1;

int main() {
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
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







+

-
-
-
-
-
+





+
+
+
+
+
+
+
+
+
+
+






+







				}
				if (menu_counter != menu_sel_last)
					 selection_counter += 1;
				if (selection_counter == 2) { 
					/* calculate the other menu */
					/* how to get missing menu? */
					if (strcmp("", iso_sel) == 0) {
						/* Test searching for item in menu */
						set_menu_pattern(iso_menu, "200");

						/* Test setting item in menu
							set_top_row(iso_menu, 3);
						/* This works, but plain refreshing doesn't work properly */
						/* But cheating and using menu_driver to go up/down does */
						/* Using menu_driver to go up/down to force refresh */
						menu_driver(iso_menu, REQ_DOWN_ITEM);
						menu_driver(iso_menu, REQ_UP_ITEM);
						wrefresh(iso_win);
					}
					if (strcmp("", shutter_sel) == 0) {
						/* 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);
						menu_driver(aperture_menu, REQ_DOWN_ITEM);
						menu_driver(aperture_menu, REQ_UP_ITEM);
						wrefresh(aperture_win);
					}
					/* clear the selections for next time */
					selection_counter = 0;
326
327
328
329
330
331
332








































































340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
	return pow(aperture, 2) / pow(2, exposure);
}

double aperture (int exposure, int shutter) {
	/* EV = log2 (N^2/t) */
	return sqrt(pow(2, exposure) * shutter);
}

int nearest_match (double x, int menu) {
	/* Need to search array for closest match */
	int n;
	int diff_idx = 0;
	char array_value_str[7];
	double array_value_db;
	double diff;

	/* Need a starting value for difference */
	switch(menu) {
		case 1:
			array_value_db = strtod(iso_array[0], NULL);
			break;
		case 2:
			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[5];
	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;
}