3 #include "test_AutoExpose.h"
8 static void _AssertCall(uint16_t num,
char const * name)
12 GString *message = g_string_new(NULL);
13 g_string_append_printf(message,
"`%s` is not call %d", name, num);
15 TEST_ASSERT_TRUE_MESSAGE(
16 AssertCall(mock, num, name),
20 g_string_free(message,
true);
24 void AutoExpose_turns_led1_red_to_indicate_starting(
void)
32 void AutoExpose_sets_min_peak_at_target_minus_tolerance(
void)
42 void AutoExpose_clamps_min_peak_at_max_dark_if_target_minus_tolerance_is_GREATER_THAN_target(
void)
49 TEST_ASSERT_GREATER_THAN_UINT16(1,2);
54 TEST_ASSERT_EQUAL_UINT16(
max_dark, min_peak);
56 void AutoExpose_clamps_min_peak_at_max_dark_if_target_minus_tolerance_is_LESS_THAN_max_dark(
void)
63 TEST_ASSERT_LESS_THAN_UINT16(2,1);
68 TEST_ASSERT_EQUAL_UINT16(
max_dark, min_peak);
70 void AutoExpose_sets_max_peak_at_target_plus_tolerance(
void)
80 void AutoExpose_clamps_max_peak_at_65535_counts_if_target_plus_tolerance_is_LESS_THAN_target(
void)
85 TEST_ASSERT_LESS_THAN_UINT16(2,1);
86 TEST_ASSERT_LESS_THAN_UINT16(
93 TEST_ASSERT_EQUAL_UINT16(UINT16_MAX, max_peak);
95 void AutoExpose_loops_until_done(
void)
99 void AutoExpose_exposes_the_pixels(
void)
105 _AssertCall(1,
"LisExpose");
108 _AssertCall(1,
"S13131Expose");
111 void AutoExpose_reads_pixel_counts_into_global_frame_buffer(
void)
117 _AssertCall(2,
"LisReadout");
120 _AssertCall(2,
"S13131Readout");
124 void AutoExpose_finds_frame_peak_in_range_start_pixel_to_stop_pixel(
void)
131 frame[byte_index] = 0;
134 uint16_t
const pixnum = 100;
135 uint16_t byte_index = (pixnum-1)*2;
136 frame[byte_index++] = 0xAB;
137 frame[byte_index] = 0xCD;
140 TEST_ASSERT_LESS_THAN_UINT16(2,1);
142 TEST_ASSERT_GREATER_THAN_UINT16(1,2);
143 TEST_ASSERT_GREATER_THAN_UINT16(pixnum,
stop_pixel);
147 TEST_ASSERT_EQUAL_UINT16(0xABCD, peak);
149 void AutoExpose_is_done_if_peak_less_than_max_dark_AND_exposure_at_max(
void)
159 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
164 frame[byte_index] = 0;
167 uint16_t
const pixnum = 100;
168 uint16_t byte_index = (pixnum-1)*2;
169 frame[byte_index++] = 0x11;
170 frame[byte_index] = 0x93;
184 uint8_t iterations = NumberOfActualCalls(mock)/2;
186 TEST_ASSERT_EQUAL_UINT8(1, iterations);
188 void AutoExpose_scales_exposure_by_10_if_peak_less_than_max_dark(
void)
195 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
200 frame[byte_index] = 0;
203 uint16_t
const pixnum = 100;
204 uint16_t byte_index = (pixnum-1)*2;
205 frame[byte_index++] = 0x11;
206 frame[byte_index] = 0x93;
216 uint16_t initial_exposure = 50;
225 uint8_t iterations = NumberOfActualCalls(mock)/2;
227 TEST_ASSERT_EQUAL_UINT8(1, iterations);
231 void AutoExpose_clamps_exposure_at_max_exposure_if_10_x_exposure_is_GREATER_THAN_max_exposure(
void)
238 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
243 frame[byte_index] = 0;
246 uint16_t
const pixnum = 100;
247 uint16_t byte_index = (pixnum-1)*2;
248 frame[byte_index++] = 0x11;
249 frame[byte_index] = 0x93;
259 uint16_t initial_exposure = 10000;
268 uint8_t iterations = NumberOfActualCalls(mock)/2;
270 TEST_ASSERT_EQUAL_UINT8(1, iterations);
274 void AutoExpose_scales_exposure_by_half_if_peak_ABOVE_max_peak(
void)
280 uint16_t peak = 0xC222;
281 TEST_ASSERT_GREATER_THAN_UINT16(1,2);
282 TEST_ASSERT_GREATER_THAN_UINT16(max_peak,peak);
289 frame[byte_index] = 0;
292 uint16_t
const pixnum = 100;
293 uint16_t byte_index = (pixnum-1)*2;
294 frame[byte_index++] = 0xC2;
295 frame[byte_index] = 0x22;
305 uint16_t initial_exposure = 500;
314 uint8_t iterations = NumberOfActualCalls(mock)/2;
316 TEST_ASSERT_EQUAL_UINT8(1, iterations);
322 void AutoExpose_clamps_exposure_at_min_exposure_if_half_exposure_is_LESS_THAN_min_exposure(
void)
328 uint16_t peak = 0xC222;
329 TEST_ASSERT_GREATER_THAN_UINT16(1,2);
330 TEST_ASSERT_GREATER_THAN_UINT16(max_peak,peak);
337 frame[byte_index] = 0;
340 uint16_t
const pixnum = 100;
341 uint16_t byte_index = (pixnum-1)*2;
342 frame[byte_index++] = 0xC2;
343 frame[byte_index] = 0x22;
361 uint8_t iterations = NumberOfActualCalls(mock)/2;
363 TEST_ASSERT_EQUAL_UINT8(1, iterations);
367 void AutoExpose_is_done_if_peak_BELOW_min_peak_and_exposure_at_max_exposure(
void)
376 uint16_t peak = 0xA886;
377 TEST_ASSERT_LESS_THAN_UINT16(2,1);
378 TEST_ASSERT_LESS_THAN_UINT16(min_peak,peak);
382 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
387 frame[byte_index] = 0;
390 uint16_t
const pixnum = 100;
391 uint16_t byte_index = (pixnum-1)*2;
392 frame[byte_index++] = 0xA8;
393 frame[byte_index] = 0x86;
407 uint8_t iterations = NumberOfActualCalls(mock)/2;
409 TEST_ASSERT_EQUAL_UINT8(1, iterations);
411 void AutoExpose_scales_exposure_by_target_div_peak_if_peak_BELOW_min_peak_and_exposure_not_at_max(
void)
417 uint16_t peak = 0xA886;
418 TEST_ASSERT_LESS_THAN_UINT16(2,1);
419 TEST_ASSERT_LESS_THAN_UINT16(min_peak,peak);
423 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
428 frame[byte_index] = 0;
431 uint16_t
const pixnum = 100;
432 uint16_t byte_index = (pixnum-1)*2;
433 frame[byte_index++] = 0xA8;
434 frame[byte_index] = 0x86;
444 uint16_t initial_exposure = 50;
453 uint8_t iterations = NumberOfActualCalls(mock)/2;
455 TEST_ASSERT_EQUAL_UINT8(1, iterations);
468 void AutoExpose_clamps_exposure_at_max_exposure_if_gain_is_GREATER_THAN_max_exposure(
void)
475 TEST_ASSERT_EQUAL_UINT16(
max_dark,4500);
486 frame[byte_index] = 0;
489 uint16_t
const pixnum = 100;
490 uint16_t byte_index = (pixnum-1)*2;
491 frame[byte_index++] = 0x11;
492 frame[byte_index] = 0x94;
503 uint16_t initial_exposure = 6354;
512 uint8_t iterations = NumberOfActualCalls(mock)/2;
514 TEST_ASSERT_EQUAL_UINT8(1, iterations);
519 void AutoExpose_is_done_if_peak_is_in_the_target_range(
void)
530 uint16_t peak = 0xB554;
531 TEST_ASSERT_EQUAL_UINT16(
target, peak);
537 frame[byte_index] = 0;
540 uint16_t
const pixnum = 100;
541 uint16_t byte_index = (pixnum-1)*2;
542 frame[byte_index++] = 0xB5;
543 frame[byte_index] = 0x54;
549 uint16_t initial_exposure = 50;
556 uint8_t iterations = NumberOfActualCalls(mock)/2;
558 TEST_ASSERT_EQUAL_UINT8(1, iterations);
560 void AutoExpose_turns_led1_green_to_indicate_it_hit_the_target_range(
void)
564 void AutoExpose_gives_up_if_it_iterates_for_max_tries(
void)
579 uint16_t peak = 0xA886;
580 TEST_ASSERT_EQUAL_UINT16(min_peak-1, peak);
586 frame[byte_index] = 0;
589 uint16_t
const pixnum = 100;
590 uint16_t byte_index = (pixnum-1)*2;
591 frame[byte_index++] = 0xA8;
592 frame[byte_index] = 0x86;
619 uint8_t iterations = NumberOfActualCalls(mock)/2;
620 TEST_ASSERT_EQUAL_UINT8(
max_tries, iterations);
uint16_t max_exposure
max_exposure is 1.31 seconds (65535 20µs-cycles) This is the 16-bit limit, UINT16_MAX,...
uint16_t start_pixel
AutoExpose() ignores pixels below start_pixel.
uint8_t max_tries
maximum number of tries before AutoExpose() gives up
uint16_t stop_pixel
AutoExpose() ignores pixels above stop_pixel.
uint16_t target_tolerance
target ± target_tolerance is the target peak counts range for AutoExpose().
uint16_t max_dark
max_dark is a conservative estimate on the largest dark offset
uint16_t target
target peak counts for AutoExpose().
uint16_t min_exposure
min_exposure is 100 microseconds (five 20µs-cycles) This is a safe lower limit to avoid dead frames.
uint16_t exposure_ticks
LIS-770i exposure time.
#define MAX_NUM_PIXELS
LIS-770i maximum number of pixels.
uint8_t frame[]
One frame of pixel data is, at most, 1568 bytes.
uint16_t GetPeak(uint16_t const, uint16_t const)
uint16_t AutoExpose(void)