Add camera options
This commit is contained in:
parent
02c10df53f
commit
31a1f91e72
@ -15,6 +15,8 @@ typedef struct camera_options_s {
|
||||
bool allow_dma;
|
||||
float high_res_factor;
|
||||
float low_res_factor;
|
||||
|
||||
char options[4096];
|
||||
} camera_options_t;
|
||||
|
||||
typedef struct camera_s {
|
||||
|
@ -65,11 +65,15 @@ option_t all_options[] = {
|
||||
DEFINE_OPTION_DEFAULT(camera, allow_dma, bool, "1"),
|
||||
DEFINE_OPTION(camera, high_res_factor, float),
|
||||
DEFINE_OPTION(camera, low_res_factor, float),
|
||||
DEFINE_OPTION_PTR(camera, options, list),
|
||||
|
||||
DEFINE_OPTION(http, port, uint),
|
||||
DEFINE_OPTION(http, maxcons, uint),
|
||||
|
||||
DEFINE_OPTION_DEFAULT(log, debug, bool, "1"),
|
||||
DEFINE_OPTION_DEFAULT(log, verbose, bool, "1"),
|
||||
DEFINE_OPTION_PTR(log, filter, string),
|
||||
DEFINE_OPTION_PTR(log, filter, list),
|
||||
|
||||
{}
|
||||
};
|
||||
|
||||
|
32
opts/opts.c
32
opts/opts.c
@ -5,13 +5,32 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
static int option_handler_print(option_t *option, char *data);
|
||||
static int option_handler_set(option_t *option, char *data);
|
||||
|
||||
#define OPTION_VALUE_LIST_SEP ","
|
||||
|
||||
static void print_help(option_t *options)
|
||||
{
|
||||
for (int i = 0; options[i].name; i++) {
|
||||
option_t *option = &options[i];
|
||||
|
||||
printf("%40s\t", option->name);
|
||||
|
||||
if (option->value_string) {
|
||||
if (option->value_list) {
|
||||
char *string = option->value_list;
|
||||
char *token;
|
||||
int tokens = 0;
|
||||
|
||||
while (token = strsep(&string, OPTION_VALUE_LIST_SEP)) {
|
||||
if (tokens++ > 0)
|
||||
printf("\n%40s\t", "");
|
||||
printf("%s", token);
|
||||
}
|
||||
|
||||
if (!tokens)
|
||||
printf("(none)");
|
||||
} else if (option->value_string) {
|
||||
printf(option->format, option->value_string);
|
||||
} else {
|
||||
if (option->value_mapping) {
|
||||
@ -60,7 +79,16 @@ static int parse_opt(option_t *options, const char *key)
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
if (option->value_string) {
|
||||
if (option->value_list) {
|
||||
char *ptr = option->value_list;
|
||||
|
||||
if (*ptr) {
|
||||
strcat(ptr, OPTION_VALUE_LIST_SEP);
|
||||
ptr += strlen(ptr);
|
||||
}
|
||||
|
||||
ret = sscanf(value, option->format, ptr);
|
||||
} else if (option->value_string) {
|
||||
ret = sscanf(value, option->format, option->value_string);
|
||||
} else if (option->value_mapping) {
|
||||
for (int j = 0; option->value_mapping[j].name; j++) {
|
||||
|
@ -10,6 +10,7 @@ typedef struct option_value_s {
|
||||
typedef struct options_s {
|
||||
const char *name;
|
||||
char *value_string;
|
||||
char *value_list;
|
||||
union {
|
||||
unsigned *value;
|
||||
unsigned *value_uint;
|
||||
@ -35,6 +36,7 @@ typedef struct options_s {
|
||||
#define OPTION_FORMAT_bool "%d"
|
||||
#define OPTION_FORMAT_float "%f"
|
||||
#define OPTION_FORMAT_string "%s"
|
||||
#define OPTION_FORMAT_list "%s"
|
||||
|
||||
#define DEFINE_OPTION(_section, _name, _type) \
|
||||
{ \
|
||||
|
Loading…
x
Reference in New Issue
Block a user