[libcamera-devel,05/10] ipa: raspberrypi: Af: Add AfState
diff mbox series

Message ID 20220613142853.98484-6-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • ipa: raspberrypi: Introduce an autofocus algorithm
Related show

Commit Message

Jean-Michel Hautbois June 13, 2022, 2:28 p.m. UTC
Now that controls are introduced, use the AfState to control the
algorithm.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 src/ipa/raspberrypi/controller/af_status.h | 5 +++--
 src/ipa/raspberrypi/controller/iob/af.cpp  | 8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/af_status.h b/src/ipa/raspberrypi/controller/af_status.h
index f8cb1301..3428d032 100644
--- a/src/ipa/raspberrypi/controller/af_status.h
+++ b/src/ipa/raspberrypi/controller/af_status.h
@@ -7,15 +7,16 @@ 
  */
 #pragma once
 
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
 #include <libcamera/geometry.h>
 
 /*
  * The focus algorithm should post the following structure into the image's
  * "af.status" metadata.
  */
-
 struct AfStatus {
 	uint32_t lensPosition;
-	uint32_t state;
+	libcamera::controls::AfStateEnum state;
 	libcamera::Rectangle windows;
 };
diff --git a/src/ipa/raspberrypi/controller/iob/af.cpp b/src/ipa/raspberrypi/controller/iob/af.cpp
index 12d41c81..b03e52c5 100644
--- a/src/ipa/raspberrypi/controller/iob/af.cpp
+++ b/src/ipa/raspberrypi/controller/iob/af.cpp
@@ -78,7 +78,7 @@  void Af::Initialise()
 {
 	status_.lensPosition = 0.0;
 	maxContrast_ = 0.0;
-	status_.state = 1;
+	status_.state = libcamera::controls::AfStateScanning;
 }
 
 void Af::Prepare(Metadata *image_metadata)
@@ -109,7 +109,7 @@  void Af::afFineScan()
 
 	if (afScan(kFineSearchStep)) {
 		LOG(IoBAf, Debug) << "AF found the best focus position !";
-		status_.state = 2;
+		status_.state = libcamera::controls::AfStateFocused;
 		fineCompleted_ = true;
 	}
 }
@@ -162,7 +162,7 @@  void Af::afReset()
 	LOG(IoBAf, Debug) << "Reset AF parameters";
 	status_.lensPosition = 0;
 	focus_ = 0;
-	status_.state = 0;
+	status_.state = libcamera::controls::AfStateIdle;
 	previousContrast_ = 0.0;
 	coarseCompleted_ = false;
 	fineCompleted_ = false;
@@ -195,7 +195,7 @@  void Af::Process(StatisticsPtr &stats, [[maybe_unused]] Metadata *image_metadata
 		currentContrast_ += stats->focus_stats[i].contrast_val[1][1]
 				  / stats->focus_stats[i].contrast_val_num[1][1];
 
-	if (status_.state != 2) {
+	if (status_.state != libcamera::controls::AfStateFocused) {
 		afCoarseScan();
 		afFineScan();
 	} else {