firmware  v0.1.2
Chromation Spectrometer Dev-Kit
AutoExpose.h
Go to the documentation of this file.
1 
44 #ifndef _AUTOEXPOSE_H
45 #define _AUTOEXPOSE_H
46 
47 #include <stdint.h>
48 #include <stdbool.h>
49 
51 extern uint8_t max_tries;
52 
54 extern uint16_t start_pixel;
55 
57 extern uint16_t stop_pixel;
58 
60 extern uint16_t target;
61 
63 extern uint16_t target_tolerance;
64 
66 extern uint16_t max_dark;
67 
71 extern uint16_t min_exposure;
72 
84 extern uint16_t max_exposure;
85 
86 inline uint16_t _MinPeak(uint16_t target, uint16_t target_tolerance)
87 {
88  uint16_t min_peak = target-target_tolerance;
89 
90  /* ------------------------------ */
91  /* | clamp min_peak at max_dark | */
92  /* ------------------------------ */
93 
94  // guard against arithmetic wrap around where target - tol > target
95  if ( min_peak > target) min_peak = max_dark;
96  // guard against large tolerance where target - tol < max_dark
97  else if ( min_peak < max_dark) min_peak = max_dark;
98  return min_peak;
99 }
100 
101 // ---------------------------------------------------------
102 // | stdint.h |
103 // | defines UINT16_MAX as 65535 |
104 // | (both /usr/include/stdint.h and avr/include/stdint.h) |
105 // ---------------------------------------------------------
106 
107 inline uint16_t _MaxPeak(uint16_t target, uint16_t target_tolerance)
108 {
109  uint16_t max_peak = target + target_tolerance;
110 
111  /* --------------------------- */
112  /* | clamp max_peak at 65535 | */
113  /* --------------------------- */
114  // guard against arithmetic wrap around where target + tol < target
115  if ( max_peak < target) max_peak = UINT16_MAX;
116  return max_peak;
117 }
118 
119 #endif // _AUTOEXPOSE_H
uint16_t max_exposure
max_exposure is 1.31 seconds (65535 20µs-cycles) This is the 16-bit limit, UINT16_MAX,...
Definition: AutoExpose.c:12
uint16_t start_pixel
AutoExpose() ignores pixels below start_pixel.
Definition: AutoExpose.c:6
uint8_t max_tries
maximum number of tries before AutoExpose() gives up
Definition: AutoExpose.c:5
uint16_t stop_pixel
AutoExpose() ignores pixels above stop_pixel.
Definition: AutoExpose.c:7
uint16_t target_tolerance
target ± target_tolerance is the target peak counts range for AutoExpose().
Definition: AutoExpose.c:9
uint16_t max_dark
max_dark is a conservative estimate on the largest dark offset
Definition: AutoExpose.c:10
uint16_t target
target peak counts for AutoExpose().
Definition: AutoExpose.c:8
uint16_t min_exposure
min_exposure is 100 microseconds (five 20µs-cycles) This is a safe lower limit to avoid dead frames.
Definition: AutoExpose.c:11