|
@@ -177,7 +177,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)
|
|
|
+load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name, int lint)
|
|
|
{
|
|
|
const char *sensor_driver, *bridge_driver;
|
|
|
config_setting_t *root = config_lookup(cfg, name);
|
|
@@ -196,11 +196,14 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name)
|
|
|
camera->media_fd = 0;
|
|
|
camera->video_fd = 0;
|
|
|
|
|
|
- int res = find_media_node(camera, bridge_driver, sensor_driver);
|
|
|
- if (res < 0) {
|
|
|
- log_debug(" Could not find media node with this sensor\n");
|
|
|
- free(camera);
|
|
|
- return -1;
|
|
|
+ // Don't access hardware in linting mode
|
|
|
+ if (lint == 0) {
|
|
|
+ int res = find_media_node(camera, bridge_driver, sensor_driver);
|
|
|
+ if (res < 0) {
|
|
|
+ log_debug(" Could not find media node with this sensor\n");
|
|
|
+ free(camera);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
camera->name = strdup(name);
|
|
@@ -216,6 +219,11 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name)
|
|
|
config_setting_t *modes = config_setting_lookup(root, "Modes");
|
|
|
config_setting_t *mode;
|
|
|
|
|
|
+ if (modes == NULL) {
|
|
|
+ log_error("Sensor '%s' does not define any modes\n", camera->name);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
int num_modes = config_setting_length(modes);
|
|
|
camera->modes = malloc(num_modes * sizeof(libmegapixels_mode *));
|
|
|
camera->num_modes = num_modes;
|
|
@@ -381,11 +389,22 @@ load_camera(libmegapixels_devconfig *config, config_t *cfg, const char *name)
|
|
|
n++;
|
|
|
}
|
|
|
|
|
|
+ if (n == 0) {
|
|
|
+ log_debug("No modes defined for sensor '%s'\n", camera->name);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int
|
|
|
libmegapixels_load_file(libmegapixels_devconfig *config, const char *file)
|
|
|
+{
|
|
|
+ return libmegapixels_load_file_lint(config, file, 0);
|
|
|
+}
|
|
|
+
|
|
|
+int
|
|
|
+libmegapixels_load_file_lint(libmegapixels_devconfig *config, const char *file, int linting)
|
|
|
{
|
|
|
if (config->loaded_config) {
|
|
|
log_error("Config already loaded\n");
|
|
@@ -403,9 +422,13 @@ libmegapixels_load_file(libmegapixels_devconfig *config, const char *file)
|
|
|
|
|
|
config_init(&cfg);
|
|
|
if (!config_read_file(&cfg, file)) {
|
|
|
- fprintf(stderr, "Could not read %s\n", file);
|
|
|
- fprintf(stderr, "%s:%d - %s\n",
|
|
|
- config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
|
|
+ if (config_error_type(&cfg) == CONFIG_ERR_FILE_IO) {
|
|
|
+ fprintf(stderr, "Could not read %s: %s\n", file, config_error_text(&cfg));
|
|
|
+ } else {
|
|
|
+ fprintf(stderr, "Could not read %s:\n", file);
|
|
|
+ fprintf(stderr, "\t%s:%d - %s\n",
|
|
|
+ config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
|
|
+ }
|
|
|
config_destroy(&cfg);
|
|
|
return 0;
|
|
|
}
|
|
@@ -413,11 +436,11 @@ libmegapixels_load_file(libmegapixels_devconfig *config, const char *file)
|
|
|
int version = 0;
|
|
|
if (config_lookup_int(&cfg, "Version", &version)) {
|
|
|
if (version != 1) {
|
|
|
- fprintf(stderr, "Invalid version %d\n", version);
|
|
|
+ fprintf(stderr, "Could not load '%s': Invalid version %d\n", file, version);
|
|
|
return 0;
|
|
|
}
|
|
|
} else {
|
|
|
- fprintf(stderr, "Missing version\n");
|
|
|
+ fprintf(stderr, "Could not load '%s': Missing version\n", file);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -446,7 +469,7 @@ libmegapixels_load_file(libmegapixels_devconfig *config, const char *file)
|
|
|
if (strcmp(member->name, "Model") == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- load_camera(config, &cfg, member->name);
|
|
|
+ load_camera(config, &cfg, member->name, linting);
|
|
|
}
|
|
|
|
|
|
return 1;
|