Merge branch 'feature/autoexposure-wait'
This commit is contained in:
commit
1e0daa39cc
|
@ -1 +1 @@
|
||||||
497
|
499
|
||||||
|
|
|
@ -154,6 +154,7 @@ uint8_t LineBuffer[CAMERA_IMAGE_WIDTH + 40];
|
||||||
int LineCount = 0;
|
int LineCount = 0;
|
||||||
static int FrameCount = 0;
|
static int FrameCount = 0;
|
||||||
volatile int Camera_Captured = 0;
|
volatile int Camera_Captured = 0;
|
||||||
|
unsigned int BlackPixels = 0;
|
||||||
|
|
||||||
static uint8_t ReadRegister(uint8_t reg)
|
static uint8_t ReadRegister(uint8_t reg)
|
||||||
{
|
{
|
||||||
|
@ -310,7 +311,9 @@ void TIM1_CC_IRQHandler(void)
|
||||||
CurrentLine = 0;
|
CurrentLine = 0;
|
||||||
FrameCount++;
|
FrameCount++;
|
||||||
|
|
||||||
if(FrameCount == 5)
|
// Check if the last frame's exposure is reasonable
|
||||||
|
if(BlackPixels >= (unsigned)(CAMERA_PIXELS * CAMERA_EXPOSURE_LOW)
|
||||||
|
&& BlackPixels <= (unsigned)(CAMERA_PIXELS * CAMERA_EXPOSURE_HIGH))
|
||||||
{
|
{
|
||||||
Camera_Captured = 1;
|
Camera_Captured = 1;
|
||||||
// Disable everything
|
// Disable everything
|
||||||
|
@ -318,6 +321,9 @@ void TIM1_CC_IRQHandler(void)
|
||||||
TIM1->CR1 = 0;
|
TIM1->CR1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset black pixel counter
|
||||||
|
BlackPixels = 0;
|
||||||
|
|
||||||
// Dummy read
|
// Dummy read
|
||||||
TIM1->CCR2;
|
TIM1->CCR2;
|
||||||
TIM1->SR &= ~TIM_SR_CC2IF;
|
TIM1->SR &= ~TIM_SR_CC2IF;
|
||||||
|
@ -371,6 +377,7 @@ void TIM3_IRQHandler(void)
|
||||||
error = pixel;
|
error = pixel;
|
||||||
ImageBuffer[(line * CAMERA_IMAGE_WIDTH + i) / 8] |=
|
ImageBuffer[(line * CAMERA_IMAGE_WIDTH + i) / 8] |=
|
||||||
0x80 >> (i % 8);
|
0x80 >> (i % 8);
|
||||||
|
BlackPixels++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,12 @@
|
||||||
|
|
||||||
#define CAMERA_IMAGE_WIDTH 160
|
#define CAMERA_IMAGE_WIDTH 160
|
||||||
#define CAMERA_IMAGE_HEIGHT 144
|
#define CAMERA_IMAGE_HEIGHT 144
|
||||||
|
#define CAMERA_PIXELS (CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT)
|
||||||
|
|
||||||
|
// Maximum and minimum share of black pixels for an image to be accepted
|
||||||
|
#define CAMERA_EXPOSURE_LIMIT 0.4
|
||||||
|
#define CAMERA_EXPOSURE_LOW (0.5 - CAMERA_EXPOSURE_LIMIT)
|
||||||
|
#define CAMERA_EXPOSURE_HIGH (0.5 + CAMERA_EXPOSURE_LIMIT)
|
||||||
|
|
||||||
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
||||||
// dithering.
|
// dithering.
|
||||||
|
|
Loading…
Reference in a new issue