Skip to content

Commit f042f06

Browse files
author
Anes Hadziahmetagic
committed
added focus configuration
introduced focus configuration menu with: 1 - autofocus setting 2 - manual focus setting with focus distance configuration Signed-off-by: Anes Hadziahmetagic <[email protected]>
1 parent 54aadc8 commit f042f06

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

camera-hal3-sample/src/CameraHAL3Config.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,35 @@ void configUpdateMeta(android::CameraMetadata* meta, int cmd)
7373
unsigned char awb = 1;
7474
(*meta).update(ANDROID_CONTROL_AWB_MODE, &awb, 1);
7575
}
76+
case CONFIG_AUTO_FOCUS: {
77+
unsigned char af = ANDROID_CONTROL_AF_MODE_AUTO;
78+
(*meta).update(ANDROID_CONTROL_AF_MODE, &af, 1);
79+
}
7680
break;
7781
default:
7882
break;
7983
}
8084
}
8185

8286

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

camera-hal3-sample/src/CameraHAL3Config.h

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

2224

2325
typedef struct _StreamInfo {
@@ -36,6 +38,7 @@ struct CamxHAL3Config {
3638

3739
void configUpdateMeta(android::CameraMetadata* meta, int cmd);
3840
void configUpdateMeta(android::CameraMetadata* meta, int cmd, int value);
41+
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value);
3942
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value1, float value2, float value3);
4043

4144

camera-hal3-sample/src/CameraHAL3Main.cpp

Lines changed: 36 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 setFocus();
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+
setFocus();
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.\n");
310314
printf("Press q: quit.\n");
311315
}
312316
}
@@ -494,6 +498,38 @@ static void setSnapshotRotation()
494498
}
495499
}
496500

501+
static void setFocus()
502+
{
503+
std::string command;
504+
505+
while(true) {
506+
printf("Press 1: auto focus, 2: fixed focus, q: quit\n");
507+
printf(">> ");
508+
509+
std::getline(std::cin, command);
510+
511+
if (command == "1") {
512+
android::CameraMetadata *meta = ::getCurrentMeta();
513+
514+
configUpdateMeta(meta, CONFIG_AUTO_FOCUS);
515+
::updateMetaData(meta);
516+
break;
517+
} else if (command == "2") {
518+
float focus_distance;
519+
focus_distance = getlineToFloat("focus distance (e.g 0 - far, 1500 - near): ");
520+
android::CameraMetadata *meta = ::getCurrentMeta();
521+
522+
configUpdateMeta(meta, CONFIG_FIXED_FOCUS, focus_distance);
523+
::updateMetaData(meta);
524+
break;
525+
} else if (command == "q") {
526+
break;
527+
} else {
528+
printf("Wrong input.\n");
529+
}
530+
}
531+
}
532+
497533

498534
static int getlineToInt(std::string prompt)
499535
{

0 commit comments

Comments
 (0)