Use dtb auto detection for config file

This commit is contained in:
Martijn Braam 2020-09-18 17:07:23 +02:00
parent 26fab100bb
commit 59dc47f72c
5 changed files with 72 additions and 12 deletions

View File

@ -0,0 +1,18 @@
[device]
csi=sun6i-csi
[rear]
driver=ov5640
width=2592
height=1944
rate=15
fmt=BGGR8
rotate=270
[front]
driver=gc2145
width=800
height=600
rate=30
fmt=BGGR8
rotate=90

View File

@ -0,0 +1,18 @@
[device]
csi=sun6i-csi
[rear]
driver=ov5640
width=2592
height=1944
rate=15
fmt=BGGR8
rotate=270
[front]
driver=gc2145
width=800
height=600
rate=30
fmt=BGGR8
rotate=90

41
main.c
View File

@ -843,13 +843,44 @@ on_camera_switch_clicked(GtkWidget *widget, gpointer user_data)
start_capturing(video_fd);
}
int
find_config(char *conffile)
{
char buf[512];
FILE *fp;
if(access("/proc/device-tree/compatible", F_OK) != -1) {
fp = fopen("/proc/device-tree/compatible", "r");
fgets(buf, 512, fp);
fclose(fp);
sprintf(conffile, "/usr/share/megapixels/config/%s.ini", buf);
if(access(conffile, F_OK) != -1) {
printf("Found config file at %s\n", conffile);
return 0;
}
sprintf(conffile, "config/%s.ini", buf);
if(access(conffile, F_OK) != -1) {
printf("Found config file at %s\n", conffile);
return 0;
}
printf("%s not found\n", conffile);
} else {
printf("Could not read device name from device tree\n");
}
conffile = "/etc/megapixels.ini";
if(access(conffile, F_OK) != -1) {
printf("Found config file at %s\n", conffile);
return 0;
}
return -1;
}
int
main(int argc, char *argv[])
{
if (argc != 2) {
g_printerr("Usage: camera configfile\n");
return 1;
}
char conffile[512];
find_config(conffile);
gtk_init(&argc, &argv);
g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", TRUE, NULL);
@ -886,7 +917,7 @@ main(int argc, char *argv[])
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
int result = ini_parse(argv[1], config_ini_handler, NULL);
int result = ini_parse(conffile, config_ini_handler, NULL);
if (result == -1) {
g_printerr("Config file not found\n");
return 1;

View File

@ -1,7 +0,0 @@
[device]
rear=/dev/video0
[preview]
width=640
height=480
fmt=YUYV