Skip to content

Commit d7be864

Browse files
author
Anes Hadziahmetagic
committed
added focus distance configuration
Signed-off-by: Anes Hadziahmetagic <[email protected]>
1 parent 54aadc8 commit d7be864

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

camera-hal3-sample/src/CameraHAL3Config.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ void configUpdateMeta(android::CameraMetadata* meta, int cmd)
8080
}
8181

8282

83+
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value)
84+
{
85+
switch (cmd) {
86+
case CONFIG_FIXED_FOCUS: {
87+
unsigned char af = ANDROID_CONTROL_AF_MODE_OFF;
88+
unsigned char af_trigger = ANDROID_CONTROL_AF_TRIGGER_CANCEL;
89+
float focus_distance = (float)value;
90+
91+
(*meta).update(ANDROID_CONTROL_AF_MODE, &af, 1);
92+
(*meta).update(ANDROID_CONTROL_AF_TRIGGER, &af_trigger, 1);
93+
(*meta).update(ANDROID_LENS_FOCUS_DISTANCE, &focus_distance, 1);
94+
}
95+
break;
96+
default:
97+
break;
98+
}
99+
}
100+
83101
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value1, float value2, float value3)
84102
{
85103
android::sp<android::VendorTagDescriptor> vendorTags = android::VendorTagDescriptor::getGlobalVendorTagDescriptor();

camera-hal3-sample/src/CameraHAL3Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define CONFIG_WHITE_BALANCE_COLOR_TEMP 6
1919
#define CONFIG_WHITE_BALANCE_GAIN 7
2020
#define CONFIG_SNAPSHOT_ROTATION 8
21+
#define CONFIG_FIXED_FOCUS 9
2122

2223

2324
typedef struct _StreamInfo {
@@ -36,6 +37,7 @@ struct CamxHAL3Config {
3637

3738
void configUpdateMeta(android::CameraMetadata* meta, int cmd);
3839
void configUpdateMeta(android::CameraMetadata* meta, int cmd, int value);
40+
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value);
3941
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value1, float value2, float value3);
4042

4143

camera-hal3-sample/src/CameraHAL3Main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static void setAntibanding();
221221
static void setColorCorrection();
222222
static void setWhiteBalance();
223223
static void setSnapshotRotation();
224+
static void setLensFocusDistance();
224225
static int getlineToInt(std::string prompt);
225226
static float getlineToFloat(std::string prompt);
226227

@@ -296,6 +297,8 @@ int main(int argc, char *argv[])
296297
setWhiteBalance();
297298
} else if (command == "r") {
298299
setSnapshotRotation();
300+
} else if (command == "f") {
301+
setLensFocusDistance();
299302
} else {
300303
if (command != "h" && !command.empty()) {
301304
printf("Unknown command \'%s\'.\n", command.c_str());
@@ -307,6 +310,7 @@ int main(int argc, char *argv[])
307310
printf("Press w: set white balance.\n");
308311
printf("Press a: set antibanding.\n");
309312
printf("Press c: set color correction.\n");
313+
printf("Press f: set focus distance.\n");
310314
printf("Press q: quit.\n");
311315
}
312316
}
@@ -494,6 +498,15 @@ static void setSnapshotRotation()
494498
}
495499
}
496500

501+
static void setLensFocusDistance() {
502+
float focus_distance;
503+
focus_distance = getlineToFloat("focus distance (e.g 0 - far, 1500 - near): ");
504+
android::CameraMetadata *meta = ::getCurrentMeta();
505+
506+
configUpdateMeta(meta, CONFIG_FIXED_FOCUS, focus_distance);
507+
::updateMetaData(meta);
508+
}
509+
497510

498511
static int getlineToInt(std::string prompt)
499512
{

0 commit comments

Comments
 (0)