void config_set_defaults(void) { CameraParameter *param; Config *cfg; char *home_dir; boolean valid; /* Camera parameter table and pikrellcam config table have initial value pointers | to static storage. Replace these pointers to an allocated copy of the | initial value so that when later config changes are made the changes | can be dup_string() replaced into the pointers. */ for (param = &camera_parameters[0]; param < &camera_parameters[CAMERA_PARAMETERS_SIZE]; ++param) param->arg = strdup(param->arg); for (cfg = &config[0]; cfg < &config[CONFIG_SIZE]; ++cfg) { cfg->arg = strdup(cfg->arg); valid = (*cfg->config_func)(cfg->arg, &cfg->result); if (!valid) printf("config_set_default%s: %s %s\n", valid ? "" : " FAIL", cfg->option, cfg->arg); } pikrellcam.version = strdup(PIKRELLCAM_VERSION); pikrellcam.timelapse_format = strdup("tl_$n_$N.jpg"); pikrellcam.preview_filename = strdup(""); gethostname(pikrellcam.hostname, HOST_NAME_MAX); /* If pikrellcam started by rc.local or web page, need to get correct | home directory. Makefile does a setuid/setgid on executable. */ home_dir = getpwuid(geteuid())->pw_dir; asprintf(&pikrellcam.config_dir, "%s/%s", home_dir, PIKRELLCAM_CONFIG_DIR); if (make_directory(pikrellcam.config_dir)) { asprintf(&pikrellcam.config_file, "%s/%s", pikrellcam.config_dir, PIKRELLCAM_CONFIG); asprintf(&pikrellcam.motion_regions_config_file, "%s/%s", pikrellcam.config_dir, PIKRELLCAM_MOTION_REGIONS_CONFIG); asprintf(&pikrellcam.at_commands_config_file, "%s/%s", pikrellcam.config_dir, PIKRELLCAM_AT_COMMANDS_CONFIG); asprintf(&pikrellcam.timelapse_status_file, "%s/%s", pikrellcam.config_dir, PIKRELLCAM_TIMELAPSE_STATUS); } /* Make sure some motion regions exist. These will be replaced if there | is a motion regions config file */ motion_command("add_region 0.042 0.159 0.224 0.756"); motion_command("add_region 0.266 0.159 0.233 0.756"); motion_command("add_region 0.500 0.150 0.233 0.750"); motion_command("add_region 0.734 0.156 0.224 0.753"); motion_frame.show_regions = FALSE; }
void command_process(char *command_line) { VideoCircularBuffer *vcb = &video_circular_buffer; Command *cmd; char command[64], args[128], buf[32], *path; int i, n; if (!command_line || *command_line == '\0') return; n = sscanf(command_line, "%63s %[^\n]", command, args); if (n < 1 || command[0] == '#') return; for (cmd = NULL, i = 0; i < COMMAND_SIZE; cmd = NULL, ++i) { cmd = &commands[i]; if (!strcmp(command, cmd->name)) { if (cmd->n_args != n - 1) { log_printf("Wrong number of args for command: %s\n", command); return; } break; } } if (!cmd) { if ( !config_set_option(command, args, FALSE) && !mmalcam_config_parameter_set(command, args, TRUE) ) log_printf("Bad command: [%s] [%s]\n", command, args); return; } if (cmd->code != display_cmd) log_printf("command_process: %s\n", command_line); if (cmd->code < display_cmd && !display_is_default()) { display_set_default(); return; } switch (cmd->code) { case record: pthread_mutex_lock(&vcb->mutex); if (config_boolean_value(args) == TRUE) { if (vcb->pause) vcb->pause = FALSE; else { if (vcb->state == VCB_STATE_MOTION_RECORD) video_record_stop(vcb); video_record_start(vcb, VCB_STATE_MANUAL_RECORD_START); } } else video_record_stop(vcb); pthread_mutex_unlock(&vcb->mutex); break; case record_pause: /* Can pause manual record only. Because of event_gap/capture | times, I'm not even sure what it would mean to pause a | motion record. */ pthread_mutex_lock(&vcb->mutex); if (vcb->state == VCB_STATE_MANUAL_RECORD) vcb->pause = vcb->pause ? FALSE : TRUE; else vcb->pause = FALSE; pthread_mutex_unlock(&vcb->mutex); break; case still: snprintf(buf, sizeof(buf), "%d", pikrellcam.still_sequence); path = media_pathname(pikrellcam.still_dir, pikrellcam.still_filename, 'N', buf, '\0', NULL); pikrellcam.still_sequence += 1; still_capture(path); free(path); break; case tl_start: if ((n = atoi(args)) < 1) n = 0; time_lapse.activated = TRUE; time_lapse.on_hold = FALSE; if (!time_lapse.event && n > 0) { time_lapse.sequence = 0; ++time_lapse.series; time_lapse.event = event_add("timelapse", pikrellcam.t_now, n, timelapse_capture, NULL); } else if (n > 0) /* Change the period */ { time_lapse.event->time += (n - time_lapse.period); time_lapse.event->period = n; } if (n > 0) time_lapse.period = n; /* n == 0 just sets on_hold FALSE */ config_timelapse_save_status(); break; case tl_hold: config_set_boolean(&time_lapse.on_hold, args); config_timelapse_save_status(); break; case tl_end: if (time_lapse.activated) { event_remove(time_lapse.event); time_lapse.event = NULL; time_lapse.activated = FALSE; time_lapse.on_hold = FALSE; config_timelapse_save_status(); exec_no_wait(pikrellcam.on_timelapse_end_cmd, NULL); } break; case tl_inform_convert: if (!strcmp(args, "done")) { event_remove(time_lapse.inform_event); dup_string(&time_lapse.convert_name, ""); time_lapse.convert_size = 0; } else { dup_string(&time_lapse.convert_name, args); time_lapse.inform_event = event_add("tl_inform_convert", pikrellcam.t_now, 5, timelapse_inform_convert, NULL); } break; case tl_show_status: config_set_boolean(&time_lapse.show_status, args); break; case display_cmd: display_command(args); break; case motion_cmd: motion_command(args); break; case motion_enable: n = motion_frame.motion_enable; config_set_boolean(&motion_frame.motion_enable, args); if (n && !motion_frame.motion_enable) { pthread_mutex_lock(&vcb->mutex); if (vcb->state == VCB_STATE_MOTION_RECORD) video_record_stop(vcb); pthread_mutex_unlock(&vcb->mutex); } break; case save_config: config_save(pikrellcam.config_file); break; case quit: config_timelapse_save_status(); if (pikrellcam.config_modified) config_save(pikrellcam.config_file); display_quit(); exit(0); break; default: log_printf("command in table with no action!\n"); break; } }