You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
5.8 KiB
223 lines
5.8 KiB
|
|
#include "configuration.h"
|
|
#include "video.h"
|
|
#include "gui.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string>
|
|
|
|
// extern VideoDev *videodev;
|
|
extern GtkBuilder *_builder_; // work around for threads
|
|
|
|
|
|
Configuration::Configuration() {
|
|
debugpath = NULL;
|
|
readdumppath = NULL;
|
|
};
|
|
|
|
|
|
Configuration::~Configuration() {
|
|
};
|
|
|
|
|
|
std::string Configuration::GetDefaultFileName() {
|
|
std::string fn = "";
|
|
char *hd = getenv ((char*)"HOME");
|
|
|
|
if (hd != NULL) {
|
|
fn = hd;
|
|
fn = fn + "/" + CONFIGURATION_DEFAULTFILE;
|
|
}
|
|
|
|
return fn;
|
|
};
|
|
|
|
|
|
void Configuration::SaveDefault() {
|
|
std::string fn = GetDefaultFileName();
|
|
if (fn.length() < 1) {
|
|
printf ("%s:%d %s could not read HOME environment variable\n", __FILE__, __LINE__, __FUNCTION__);
|
|
return;
|
|
}
|
|
SaveConfig (fn);
|
|
};
|
|
|
|
|
|
void Configuration::LoadDefault() {
|
|
std::string fn = GetDefaultFileName();
|
|
if (fn.length() < 1) {
|
|
printf ("%s:%d %s could not read HOME environment variable\n", __FILE__, __LINE__, __FUNCTION__);
|
|
return;
|
|
}
|
|
LoadConfig (fn);
|
|
};
|
|
|
|
|
|
/*
|
|
* collect all the settings, and push them into the JSONparse object
|
|
* save the json string.
|
|
*/
|
|
void Configuration::SaveConfig(std::string filename) {
|
|
JSONParse jp;
|
|
string vstr;
|
|
int i;
|
|
GtkWidget *cb;
|
|
GtkWidget *cbe;
|
|
|
|
//
|
|
// Add resolution, format and video device to config json element
|
|
cb = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videores"));
|
|
cbe = gtk_bin_get_child(GTK_BIN(cb));
|
|
jp.AddObject("video_resolution", (string) gtk_entry_get_text(GTK_ENTRY(cbe)));
|
|
cb = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videofmt"));
|
|
cbe = gtk_bin_get_child(GTK_BIN(cb));
|
|
jp.AddObject("video_format", (string) gtk_entry_get_text(GTK_ENTRY(cbe)));
|
|
cb = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videodev"));
|
|
cbe = gtk_bin_get_child(GTK_BIN(cb));
|
|
jp.AddObject("device", (string) gtk_entry_get_text(GTK_ENTRY(cbe)));
|
|
|
|
|
|
//
|
|
// histogram settings and debayer mode
|
|
jp.AddObject("histogram_log", histogram_log);
|
|
jp.AddObject("debayer_mode", debayer_mode);
|
|
|
|
|
|
//
|
|
// save button config
|
|
for (i = 0; i < BTN_PRESET_MAX; i++) {
|
|
JSONElement je;
|
|
je.type = JSON_T_ARRAY;
|
|
je.name = "presetbtn"+ std::to_string(i);
|
|
list<VideoDevCtrl>::iterator vciter;
|
|
JSONParse jpbtn;
|
|
jpbtn.Clear();
|
|
|
|
// convert VideoDevCtrl to JSON
|
|
for (vciter = presetbtn[i].begin(); vciter != presetbtn[i].end(); vciter++) {
|
|
jpbtn.Clear();
|
|
jpbtn.AddObject("name", vciter->name);
|
|
jpbtn.AddObject("id", (signed int) vciter->id);
|
|
jpbtn.AddObject("max", vciter->max);
|
|
jpbtn.AddObject("min", vciter->min);
|
|
jpbtn.AddObject("value", vciter->value);
|
|
|
|
if (je.value.length()>0) je.value += "," + jpbtn.ToString();
|
|
else je.value = jpbtn.ToString();
|
|
}
|
|
jp.AddObject(je);
|
|
}
|
|
|
|
//
|
|
// save config
|
|
if (jp.SaveToFile(filename)) {
|
|
printf ("%s:%d %s could not save to file [%s] Error: %s\n", __FILE__, __LINE__, __FUNCTION__,
|
|
filename.c_str(), strerror(errno));
|
|
}
|
|
};
|
|
|
|
|
|
void Configuration::LoadConfig(std::string filename) {
|
|
JSONParse jp;
|
|
string vstr;
|
|
int i;
|
|
JSONElement je;
|
|
|
|
if (jp.LoadFromFile(filename)) {
|
|
printf ("%s:%d %s could not load from file [%s] Error: %s\n", __FILE__, __LINE__, __FUNCTION__,
|
|
filename.c_str(), strerror(errno));
|
|
}
|
|
else {
|
|
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
//
|
|
// set resolution and video stream mode
|
|
//
|
|
if (jp.GetValue("video_resolution", &vstr)) {
|
|
GtkWidget *cbox = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videores"));
|
|
GtkWidget *cbdevice = gtk_bin_get_child(GTK_BIN(cbox));
|
|
gtk_entry_set_text(GTK_ENTRY(cbdevice), vstr.c_str());
|
|
}
|
|
if (jp.GetValue("video_format", &vstr)) {
|
|
GtkWidget *cbox = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videofmt"));
|
|
GtkWidget *cbdevice = gtk_bin_get_child(GTK_BIN(cbox));
|
|
gtk_entry_set_text(GTK_ENTRY(cbdevice), vstr.c_str());
|
|
}
|
|
|
|
jp.GetValueInt("histogram_log", &i);
|
|
SetHistogramLog(i);
|
|
|
|
jp.GetValueInt("debayer_mode", &i);
|
|
SetDebayerMode(i);
|
|
|
|
//
|
|
// start streaming if a device was selected.
|
|
//
|
|
if (jp.GetValue("device", &vstr)) {
|
|
GtkWidget *cbox = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "cb-videodev"));
|
|
GtkWidget *cbdevice = gtk_bin_get_child(GTK_BIN(cbox));
|
|
gtk_entry_set_text(GTK_ENTRY(cbdevice), vstr.c_str());
|
|
}
|
|
|
|
//
|
|
// load the button config
|
|
//
|
|
for (i = 0; i < BTN_PRESET_MAX; i++) {
|
|
VideoDevCtrl ctrl;
|
|
JSONParse jpbtn, jpctrl;
|
|
list<JSONElement> je;
|
|
list<JSONElement>::iterator iter;
|
|
int ctrli;
|
|
int64_t id;
|
|
|
|
//
|
|
// load all controls from JSONParse object
|
|
presetbtn[i].clear();
|
|
ctrli = 0;
|
|
while (jp.GetObjectIdx("presetbtn"+ std::to_string(i), ctrli, &jpctrl)) {
|
|
jpctrl.GetValue("name", &ctrl.name);
|
|
jpctrl.GetValueInt64("id", &id);
|
|
ctrl.id = id;
|
|
jpctrl.GetValueInt("min", &ctrl.min);
|
|
jpctrl.GetValueInt("max", &ctrl.max);
|
|
jpctrl.GetValueInt("value", &ctrl.value);
|
|
presetbtn[i].push_back(ctrl);
|
|
ctrli++;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/*
|
|
* presetbtn[btn]
|
|
*/
|
|
void Configuration::SetPresetButton (int btn, list<VideoDevCtrl> *parameters) {
|
|
if (btn < 0 || btn >= BTN_PRESET_MAX) return;
|
|
presetbtn[btn] = *parameters;
|
|
};
|
|
|
|
|
|
list<VideoDevCtrl> Configuration::GetPresetButton (int btn) {
|
|
list<VideoDevCtrl> emptylist;
|
|
if (btn >= 0 && btn < BTN_PRESET_MAX) return presetbtn[btn];
|
|
return emptylist;
|
|
};
|
|
|
|
|
|
void Configuration::SetHistogramLog(int trueorfalse) {
|
|
GtkWidget *cfg_logh = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "menu-settings-loghistogram"));
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(cfg_logh), (trueorfalse == 1));
|
|
histogram_log = trueorfalse;
|
|
};
|
|
|
|
|
|
|
|
void Configuration::SetDebayerMode(int trueorfalse) {
|
|
GtkWidget *cfg_debayer = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "menu-settings-bilinearrgb"));
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(cfg_debayer), (trueorfalse == 1));
|
|
debayer_mode = trueorfalse;
|
|
};
|
|
|
|
|