It worked, sorry for the delay.

stable_yavg interval is changed to smaller one.
the fix about how long should be the exposure field(the one you gave me
yesterday) is included
the function is commented - I hope it would be useful.

Regards
Stefan Krastanov

2009/3/8 Brian Johnson <[email protected]>

>
> Try
> # git format-patch -s HEAD^
>
>
> On Sun, Mar 8, 2009 at 10:49 AM, Stefan Krastanov
> <[email protected]> wrote:
> > the comment are reversed, sorry
> >
> > 2009/3/8 Stefan Krastanov <[email protected]>
> >>
> >> The step is calculated as follows:
> >>
> >> if(dev->camera.old_step ^ dev->camera.older_step)
> >>           dev->camera.exposure_step/=2; //the steps are in the same
> >> direction - step must be bigger
> >> else
> >>           dev->camera.exposure_step+=2; //oscilating - divide the step
> by
> >> 2
> >>
> >> With my cam I have stable picture in under one second. (about 1-2
> seconds
> >> if I'm in full darkness, but well - in that case it does not mater as
> the
> >> picture is just dark;)
> >>
> >> exposure_step is unsigned in case one stays in the dark long enough for
> an
> >> overflow.
> >>
> >> and about the git commit - that's what I have got after running the
> >> commands - there is no patch on the disk - I'm sorry for asking stupid
> >> questions but what should I do.
> >>
> >> # git commit -a -m "new software AE function to address problems with
> >> exposure oscillations on mt9v011"
> >> Created commit 552ed00: new software AE function to address problems
> with
> >> exposure oscillations on mt9v011
> >>  3 files changed, 40 insertions(+), 79 deletions(-)
> >> # git format-patch -s
> >> no output on the console
> >>
> >>
> >> 2009/3/8 Vasily Khoruzhick <[email protected]>
> >>>
> >>> On Sunday 08 March 2009 14:38:51 Stefan Krastanov wrote:
> >>> > I will be very happy to give you the sorce if you
> >>> > think it's usefull, but I don't know how "patch" works. What should I
> >>> > do.
> >>>
> >>> Try:
> >>> git commit -a -m "You comment about commit"
> >>> git format-patch -s
> >>>
> >>> And then send patch to the list
> >>
> >
> >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
Lets make microdia webcams plug'n play, (currently plug'n pray)
To post to this group, send email to [email protected]
Visit us online https://groups.google.com/group/microdia
-~----------~----~----~----~------~----~------~--~---

From 7bedc815523b15b0fa35e4729234d1aaca5d354e Mon Sep 17 00:00:00 2001
From: Stefan Krastanov <[email protected]>
Date: Sun, 8 Mar 2009 16:10:23 +0100
Subject: [PATCH] new software AE function to address problems with exposure oscillations on mt9v011


Signed-off-by: Stefan Krastanov <[email protected]>
---
 micron.c      |   14 +++----
 sn9c20x-dev.c |  102 ++++++++++++++++++---------------------------------------
 sn9c20x.h     |    3 +-
 3 files changed, 40 insertions(+), 79 deletions(-)

diff --git a/micron.c b/micron.c
index f924c6f..9e3e479 100644
--- a/micron.c
+++ b/micron.c
@@ -557,11 +557,10 @@ int mt9v112_probe(struct usb_sn9c20x *dev)
 int mt9v011_set_exposure(struct usb_sn9c20x *dev)
 {
 	int ret = 0;
-	__u8 buf[2];
+	__u16 exp;
 
-	buf[0] = (dev->vsettings.exposure >> 4);
-	buf[1] = 0;
-	ret |= sn9c20x_write_i2c_data(dev, 2, 0x09, buf);
+	exp = (dev->vsettings.exposure << 4);
+	ret |= sn9c20x_write_i2c_data16(dev, 1, 0x09, &exp);
 	/* Maybe we have to disable AE/AWB/flicker avoidence (currently not
 	 * used) for MT9V111 sensor, because IFP controls this register if
 	 * one of them is enabled. */
@@ -571,7 +570,7 @@ int mt9v011_set_exposure(struct usb_sn9c20x *dev)
 int mt9v111_set_exposure(struct usb_sn9c20x *dev)
 {
 	int ret = 0;
-	__u8 buf[2];
+	__u16 exp;
 
 
 	ret = mt9v111_select_address_space(dev, MT9V111_ADDRESSSPACE_SENSOR);
@@ -579,9 +578,8 @@ int mt9v111_set_exposure(struct usb_sn9c20x *dev)
 	if (ret < 0)
 		return -11;	/* -EAGAIN */
 
-	buf[0] = (dev->vsettings.exposure >> 4);
-	buf[1] = 0;
-	ret |= sn9c20x_write_i2c_data(dev, 2, 0x09, buf);
+	exp = (dev->vsettings.exposure << 4);
+	ret |= sn9c20x_write_i2c_data16(dev, 1, 0x09, &exp);
 	/* Maybe we have to disable AE/AWB/flicker avoidence (currently not
 	 * used) for MT9V111 sensor, because IFP controls this register if
 	 * one of them is enabled. */
diff --git a/sn9c20x-dev.c b/sn9c20x-dev.c
index 96964df..771390b 100644
--- a/sn9c20x-dev.c
+++ b/sn9c20x-dev.c
@@ -112,11 +112,11 @@ int sn9c20x_initialize_sensor(struct usb_sn9c20x *dev)
 	int ret = 0;
 	int i;
 
-	dev->camera.min_yavg = 60;
-	dev->camera.max_yavg = 150;
-	dev->camera.min_stable_yavg = 70;
-	dev->camera.max_stable_yavg = 140;
-	dev->camera.old_yavg = -1;
+	dev->camera.min_yavg = 80;
+	dev->camera.max_yavg = 130;
+	dev->camera.old_step = 0;
+	dev->camera.older_step = 0;
+	dev->camera.exposure_step = 16;
 
 	/* Probe sensor first if sensor set to probe*/
 	if (dev->camera.sensor == PROBE_SENSOR) {
@@ -292,14 +292,12 @@ int dev_sn9c20x_button_detection(struct usb_sn9c20x *dev)
  *
  * @returns 0 or negative error value
  *
- * @author Vasily Khoruzhick
+ * @author Stefan Krastanov
  */
 int dev_sn9c20x_perform_soft_ae(struct usb_sn9c20x *dev)
 {
-	int yavg;
-	int koef = 100, new_exp, i;
+	int yavg, new_exp;
 	yavg = -1;
-	i = 10;
 
 	if (!dev->camera.set_exposure)
 		return -1;
@@ -311,79 +309,43 @@ int dev_sn9c20x_perform_soft_ae(struct usb_sn9c20x *dev)
 		return -1;
 	}
 
-	/* Image is too dark */
-	if (yavg < dev->camera.min_yavg) {
-		/* yavg can't be 0 - in that way new_exp == infinity */
-		if (yavg == 0)
-			yavg = 1;
-		if (dev->camera.old_yavg != -1) {
-			/* Previous correction was made to make image darker,
-			 * but we made it too dark. Calculating our error
-			 * and taking it into account.
-			 * Usually error is 0.7 - 2, so we multiply it by 100
-			 */
-			if (dev->camera.old_yavg > dev->camera.max_yavg)
-				koef = 100 * dev->camera.
-					min_stable_yavg / yavg;
-			else
-				koef = 100;
-		}
-
-		/* Calculating new exposure value. We assuming that
-		 * exposure linearly depends on YAVG, but we taking
-		 * our calculated error into account */
-		new_exp = (dev->camera.min_stable_yavg
-			* dev->vsettings.exposure * 100) / (yavg * koef);
-
-		/* Exposure can't be more than 0xff or less than 0x1 */
+	/* image too dark */
+	if(yavg < dev->camera.min_yavg){
+		//change exposure just a bit
+		new_exp=dev->vsettings.exposure+dev->camera.exposure_step;
 		if (new_exp > 0xff)
 			new_exp = 0xff;
 		if (new_exp < 0x1)
 			new_exp = 1;
-
-		dev->camera.old_yavg = yavg;
-
-		/* Applying new exposure */
+		//set it
 		dev->vsettings.exposure = new_exp;
 		dev->camera.set_exposure(dev);
-	}
+		//note the direction of the change
+		dev->camera.older_step=dev->camera.old_step;
+		dev->camera.old_step=1;//it's going up
 
-	/* Image is too bright */
-	else if (yavg > dev->camera.max_yavg) {
-			/* yavg can't be 0 - in that way new_exp == infinity */
-		if (yavg == 0)
-			yavg = 1;
-		if (dev->camera.old_yavg != -1) {
-
-			/* Previous correction was made to make image brighter,
-			 * but we made it too bright. Calculating our error
-			 * and taking it into account.
-			 * Usually error is 0.7 - 2, so we multiply it by 100
-			 */
-			if (dev->camera.old_yavg < dev->camera.min_yavg)
-				koef = 100 * yavg / dev->camera.
-					max_stable_yavg;
-			else
-				koef = 100;
-		}
-
-		/* Calculating new exposure value. We assuming that
-		 * exposure linearly depends on YAVG, but we taking
-		 * our calculated error into account */
-		new_exp = (koef * dev->camera.max_stable_yavg
-			* dev->vsettings.exposure) / (yavg * 100);
-
-		/* Exposure can't be more than 0xff or less than 0x1 */
+		/*check if it's oscillating and take smaller step if it is*/
+		if(dev->camera.old_step ^ dev->camera.older_step) dev->camera.exposure_step/=2; //oscilating - divide the step by 2
+		else dev->camera.exposure_step+=2; //the steps are in the same direction - step must be bigger
+	}
+	/*image too light*/
+	if(yavg > dev->camera.max_yavg){
+		//change exposure just a bit
+		new_exp=dev->vsettings.exposure-dev->camera.exposure_step;
 		if (new_exp > 0xff)
 			new_exp = 0xff;
 		if (new_exp < 0x1)
 			new_exp = 1;
-
-		dev->camera.old_yavg = yavg;
-
-		/* Applying new exposure */
+		//set it
 		dev->vsettings.exposure = new_exp;
-		dev->camera.set_exposure(dev);
+		dev->camera.set_exposure(dev);	
+		//note the direction of the change
+		dev->camera.older_step=dev->camera.old_step;
+		dev->camera.old_step=0;//it's going down
+
+		/*check if it's oscillating and take smaller step if it is*/
+		if(dev->camera.old_step ^ dev->camera.older_step) dev->camera.exposure_step/=2; //oscilating - divide the step by 2
+		else dev->camera.exposure_step+=2; //the steps are in the same direction - step must be bigger
 	}
 
 	return 0;
diff --git a/sn9c20x.h b/sn9c20x.h
index 27bab4a..630e507 100644
--- a/sn9c20x.h
+++ b/sn9c20x.h
@@ -306,7 +306,8 @@ struct sn9c20x_camera {
 	__u8 i2c_flags;
 	__u8 address;
 
-	int min_yavg, max_yavg, min_stable_yavg, max_stable_yavg, old_yavg;
+	int min_yavg, max_yavg, old_step, older_step;
+	unsigned int exposure_step;
 
 	atomic_t yavg;
 
-- 
1.5.6.3

Reply via email to