Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions camera-hal3-sample/src/CameraHAL3Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,35 @@ void configUpdateMeta(android::CameraMetadata* meta, int cmd)
unsigned char awb = 1;
(*meta).update(ANDROID_CONTROL_AWB_MODE, &awb, 1);
}
case CONFIG_AUTO_FOCUS: {
unsigned char af = ANDROID_CONTROL_AF_MODE_AUTO;
(*meta).update(ANDROID_CONTROL_AF_MODE, &af, 1);
}
break;
default:
break;
}
}


void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value)
{
switch (cmd) {
case CONFIG_FIXED_FOCUS: {
unsigned char af = ANDROID_CONTROL_AF_MODE_OFF;
unsigned char af_trigger = ANDROID_CONTROL_AF_TRIGGER_CANCEL;
float focus_distance = value;

(*meta).update(ANDROID_CONTROL_AF_MODE, &af, 1);
(*meta).update(ANDROID_CONTROL_AF_TRIGGER, &af_trigger, 1);
(*meta).update(ANDROID_LENS_FOCUS_DISTANCE, &focus_distance, 1);
}
break;
default:
break;
}
}

void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value1, float value2, float value3)
{
android::sp<android::VendorTagDescriptor> vendorTags = android::VendorTagDescriptor::getGlobalVendorTagDescriptor();
Expand Down
3 changes: 3 additions & 0 deletions camera-hal3-sample/src/CameraHAL3Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define CONFIG_WHITE_BALANCE_COLOR_TEMP 6
#define CONFIG_WHITE_BALANCE_GAIN 7
#define CONFIG_SNAPSHOT_ROTATION 8
#define CONFIG_AUTO_FOCUS 9
#define CONFIG_FIXED_FOCUS 10


typedef struct _StreamInfo {
Expand All @@ -36,6 +38,7 @@ struct CamxHAL3Config {

void configUpdateMeta(android::CameraMetadata* meta, int cmd);
void configUpdateMeta(android::CameraMetadata* meta, int cmd, int value);
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value);
void configUpdateMeta(android::CameraMetadata* meta, int cmd, float value1, float value2, float value3);


Expand Down
36 changes: 36 additions & 0 deletions camera-hal3-sample/src/CameraHAL3Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ static void setAntibanding();
static void setColorCorrection();
static void setWhiteBalance();
static void setSnapshotRotation();
static void setFocus();
static int getlineToInt(std::string prompt);
static float getlineToFloat(std::string prompt);

Expand Down Expand Up @@ -296,6 +297,8 @@ int main(int argc, char *argv[])
setWhiteBalance();
} else if (command == "r") {
setSnapshotRotation();
} else if (command == "f") {
setFocus();
} else {
if (command != "h" && !command.empty()) {
printf("Unknown command \'%s\'.\n", command.c_str());
Expand All @@ -307,6 +310,7 @@ int main(int argc, char *argv[])
printf("Press w: set white balance.\n");
printf("Press a: set antibanding.\n");
printf("Press c: set color correction.\n");
printf("Press f: set focus.\n");
printf("Press q: quit.\n");
}
}
Expand Down Expand Up @@ -494,6 +498,38 @@ static void setSnapshotRotation()
}
}

static void setFocus()
{
std::string command;

while(true) {
printf("Press 1: auto focus, 2: fixed focus, q: quit\n");
printf(">> ");

std::getline(std::cin, command);

if (command == "1") {
android::CameraMetadata *meta = ::getCurrentMeta();

configUpdateMeta(meta, CONFIG_AUTO_FOCUS);
::updateMetaData(meta);
break;
} else if (command == "2") {
float focus_distance;
focus_distance = getlineToFloat("focus distance (e.g 0 - far, 1500 - near): ");
android::CameraMetadata *meta = ::getCurrentMeta();

configUpdateMeta(meta, CONFIG_FIXED_FOCUS, focus_distance);
::updateMetaData(meta);
break;
} else if (command == "q") {
break;
} else {
printf("Wrong input.\n");
}
}
}


static int getlineToInt(std::string prompt)
{
Expand Down