瀏覽代碼

Load the flash settings from the config file

Martijn Braam 6 月之前
父節點
當前提交
ee42577519
共有 3 個文件被更改,包括 89 次插入3 次删除
  1. 11 2
      include/libmegapixels.h
  2. 61 1
      src/parse.c
  3. 17 0
      util/findconfig.c

+ 11 - 2
include/libmegapixels.h

@@ -24,8 +24,12 @@ libmegapixels_find_config_verbose(char *configfile, int print);
 #define LIBMEGAPIXELS_CFA_GRBG 3
 #define LIBMEGAPIXELS_CFA_RGGB 4
 
-#define LIBMEGAPIXELS_XFER_RAW 0;
-#define LIBMEGAPIXELS_XFER_SRGB 8;
+#define LIBMEGAPIXELS_XFER_RAW 0
+#define LIBMEGAPIXELS_XFER_SRGB 8
+
+#define LIBMEGAPIXELS_FLASH_SCREEN 0
+#define LIBMEGAPIXELS_FLASH_V4L 1
+#define LIBMEGAPIXELS_FLASH_LED 2
 
 struct _lmp_cmd {
 		int type;
@@ -82,9 +86,14 @@ struct _lmp_camera {
 		char *media_path;
 		char *sensor_path;
 		char *video_path;
+		char *flash_path;
+		char *lens_path;
+		int flash_type;
 		int media_fd;
 		int sensor_fd;
 		int video_fd;
+		int flash_fd;
+		int lens_fd;
 
 		int num_modes;
 		libmegapixels_mode **modes;

+ 61 - 1
src/parse.c

@@ -115,6 +115,49 @@ find_media_node(libmegapixels_camera *camera, const char *media_name, const char
 				}
 			}
 
+			// Find the flash
+			for (int i = 0; i < topology.num_entities; i++) {
+				if (entities[i].function == MEDIA_ENT_F_FLASH) {
+					for (int j = 0; j < topology.num_links; j++) {
+						if (links[j].sink_id != entities[i].id) {
+							continue;
+						}
+						for (int k = 0; k < topology.num_interfaces; k++) {
+							if (interfaces[k].id != links[j].source_id) {
+								continue;
+							}
+
+							camera->flash_path = find_path_for_devnode(interfaces[k].devnode);
+							camera->flash_type = LIBMEGAPIXELS_FLASH_V4L;
+							break;
+						}
+					}
+					break;
+				}
+			}
+
+
+			// Find the lens actuator
+			for (int i = 0; i < topology.num_entities; i++) {
+				if (entities[i].function == MEDIA_ENT_F_LENS) {
+					for (int j = 0; j < topology.num_links; j++) {
+						if (links[j].sink_id != entities[i].id) {
+							continue;
+						}
+						for (int k = 0; k < topology.num_interfaces; k++) {
+							if (interfaces[k].id != links[j].source_id) {
+								continue;
+							}
+
+							camera->lens_path = find_path_for_devnode(interfaces[k].devnode);
+							break;
+						}
+					}
+					break;
+				}
+			}
+
+
 			// Find the bridge
 			for (int i = 0; i < topology.num_entities; i++) {
 				if (entities[i].function == MEDIA_ENT_F_IO_V4L) {
@@ -179,7 +222,7 @@ find_media_node(libmegapixels_camera *camera, const char *media_name, const char
 int
 load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name, int lint)
 {
-	const char *sensor_driver, *bridge_driver;
+	const char *sensor_driver, *bridge_driver, *flashpath;
 	config_setting_t *root = config_lookup(cfg, name);
 	log_debug("Loading camera '%s'\n", name);
 	if (!config_setting_lookup_string(root, "SensorDriver", &sensor_driver)) {
@@ -195,6 +238,11 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name, in
 	camera->sensor_fd = 0;
 	camera->media_fd = 0;
 	camera->video_fd = 0;
+	camera->flash_fd = 0;
+	camera->lens_fd = 0;
+	camera->flash_path = NULL;
+	camera->lens_path = NULL;
+	camera->flash_type = LIBMEGAPIXELS_FLASH_SCREEN;
 
 	// Don't access hardware in linting mode
 	if (lint == 0) {
@@ -216,6 +264,18 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name, in
 	camera->index = config->count;
 	config->cameras[config->count++] = camera;
 
+	if (config_setting_lookup_string(root, "FlashPath", &flashpath)) {
+		camera->flash_path = strdup(flashpath);
+		camera->flash_type = LIBMEGAPIXELS_FLASH_LED;
+	}
+	int flashDisplay = 0;
+	if (config_setting_lookup_bool(root, "FlashDisplay", &flashDisplay)) {
+		if (flashDisplay) {
+			camera->flash_path = NULL;
+			camera->flash_type = LIBMEGAPIXELS_FLASH_SCREEN;
+		}
+	}
+
 	config_setting_t *modes = config_setting_lookup(root, "Modes");
 	config_setting_t *mode;
 

+ 17 - 0
util/findconfig.c

@@ -65,6 +65,23 @@ main(int argc, char *argv[])
 			printf("Sensor: %s (%s)\n", config->cameras[i]->sensor_name, config->cameras[i]->sensor_path);
 		}
 		printf("Video : %s\n", config->cameras[i]->video_path);
+		if (config->cameras[i]->flash_type == LIBMEGAPIXELS_FLASH_SCREEN) {
+			printf("Flash : screen\n");
+		} else {
+			if (config->cameras[i]->flash_path) {
+				switch (config->cameras[i]->flash_type) {
+					case LIBMEGAPIXELS_FLASH_LED:
+						printf("Flash : LED (%s)\n", config->cameras[i]->flash_path);
+						break;
+					case LIBMEGAPIXELS_FLASH_V4L:
+						printf("Flash : V4L flash entity (%s)\n", config->cameras[i]->flash_path);
+						break;
+				}
+			}
+		}
+		if (config->cameras[i]->lens_path) {
+			printf("Focus : %s\n", config->cameras[i]->lens_path);
+		}
 		printf("Modes : ");
 		for (int j = 0; j < config->cameras[i]->num_modes; j++) {
 			if (j > 0) {