forked from dicarlo236/cube-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam_config.cpp
76 lines (60 loc) · 1.77 KB
/
webcam_config.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "webcam_config.h"
int camera = -1;
const char cmd_prefix[] = "v4l2-ctl -d /dev/video";
const char ctrl_prefix[] = " --set-ctrl=";
const char fps_prefix[] = " -p ";
void parse_line(char* line, int first_camera)
{
char* pch = strtok(line," ");
// don't do anything for a comment (starts with /)
if(pch[0] == '/' || strlen(pch) < 3)
return;
//set camera to modify
if(!strcmp("CAMERA",pch))
{
pch = strtok(NULL," ");
// camera 0,1, or invalid
if(pch[0] == '0') camera = first_camera;
else if(pch[0] == '1') camera = first_camera + 1;
else printf("Invalid camera number %s\n",pch);
printf("Now modifying camera %d\n",camera);
return;
}
// if camera was never set or somehow became invalid
if(camera < 0)
{
printf("[Webcam Config] Error! Configuration file does not specify camera.\n");
return;
}
//set fps command
if(!strcmp("FPS",pch))
{
pch = strtok(NULL," ");
char command[500];
//fps has a different prefix, -p
sprintf(command,"%s%d%s%s\n",cmd_prefix,camera,fps_prefix,pch);
//execute command
system(command);
return;
}
//otherwise its a command,value pair
//get value
char* value = strtok(NULL," ");
char command[500];
sprintf(command,"%s%d%s%s=%s\n",cmd_prefix,camera,ctrl_prefix,pch,value);
printf("RUNNING COMMAND: %s",command);
system(command);
}
// load configuration file
void load_config_file(int first_camera)
{
FILE* file = fopen("../webcam.cfg","r");
char line[500];
// parse lines
while(fgets(line,sizeof(line),file))
parse_line(line,first_camera);
fclose(file);
}