seems to work

main^2
Steffen 2 months ago
parent d9ca54b676
commit 906428b4e0

@ -44,6 +44,8 @@ Configuration::Configuration() {
web_height = -1;
web_width = -1;
web_imagerefresh = 250;
filter_ratio = 0.5;
};
Configuration::~Configuration() {
@ -276,3 +278,38 @@ void Configuration::Help() {
printf (" ./miniwebcam -sslkey ./ssl-key.pem -sslcert ./ssl-cert.pem -websize 800x600\n");
}
void Configuration::SetValue(std::string name, std::string value) {
if (name.compare("filter_ratio") == 0) {
filter_ratio = atof(value.c_str());
debug ("Filter Ration set to : %g", filter_ratio);
}
};
std::string Configuration::GetValues() {
JSONParse jp;
JSONElement je;
je.Clear();
jp.Clear();
JSONParse jpe;
//
jpe.Clear();
jpe.AddObject("name", "filter_ratio");
jpe.AddObject("value", filter_ratio);
jpe.AddObject("desc", "Ratio between new to old image (1.0 = new image)");
je.SetAddArray("variables", jpe.ToString());
//
jp.AddObject(je);
return jp.ToString();
};

@ -47,12 +47,17 @@ public:
std::string vdev_dumpfile;
std::string vdev_dumppath;
float filter_ratio;
Configuration();
~Configuration();
int LoadArgs(int argc, char **argv);
int LoadFile(std::string fn);
void SetValue(std::string name, std::string value);
std::string GetValues();
int GetInitFlags() { return initflags; };
std::string GetFilename() { return filename; };

@ -73,7 +73,7 @@ static void *thread_video(void *ignored_argument) {
}
Lock();
inputimage.CopyTo(&currentimage, config.web_width, config.web_height);
if (inputfloatfilter.AddScaledImage(&inputfloat, 0.6, 0.4) == 0)
if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0)
inputfloat.CopyTo(&inputfloatfilter);
inputfloatfilter.CopyTo(&currentimagefloat);
UnLock();

@ -277,7 +277,7 @@ int VideoFrameFloat::CopyTo(VideoFrameFloat *dest) {
};
int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) {
int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float ratio) {
float *sptr, *dptr;
int x, y;
@ -285,7 +285,7 @@ int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) {
for (dptr = memf, sptr = vf->GetPixBuf(), y = 0; y < height; y++)
for (x = 0; x < width*3; x++) {
*dptr = f1 * (*dptr) + f2 * (*sptr);
*dptr = (1.0-ratio) * (*dptr) + ratio * (*sptr);
dptr++;
sptr++;
}

@ -49,7 +49,7 @@ class VideoFrameFloat {
int CopyTo(VideoFrame *dest);
int CopyTo(VideoFrameFloat *dest);
int AddScaledImage(VideoFrameFloat *vf, float f1, float f2);
int AddScaledImage(VideoFrameFloat *vf, float ratio);
};

@ -10,6 +10,9 @@ extern VideoDevice *vdev;
std::string API_Get_Ctrls();
std::string API_Set_Ctrl(std::string request);
std::string API_Get_Values();
std::string API_Set_Value(std::string request);
// InMemoryFile GenerateJpgFile(VideoFrame *vf);
InMemoryTar assets;
@ -44,9 +47,20 @@ int WebCamServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerClien
if (webclient->SendResponseData(requestbuffer, API_Get_Ctrls(), "") != 1) return 0;
}
else if (request.find("/set/ctrl") != std::string::npos) {
debug ("set controls");
debug ("set control");
if (webclient->SendResponseData(requestbuffer, API_Set_Ctrl(request), "") != 1) return 0;
}
else if (request.compare("/get/variables") == 0) {
debug ("get values");
if (webclient->SendResponseData(requestbuffer, API_Get_Values(), "") != 1) return 0;
}
else if (request.find("/set/var") != std::string::npos) {
debug ("set value");
if (webclient->SendResponseData(requestbuffer, API_Set_Value(request), "") != 1) return 0;
}
else if (isfile("www"+request)) {
if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0;
}
@ -102,14 +116,57 @@ std::string API_Set_Ctrl(std::string request) {
while ((t = strchr (t, '/'))) {
i++;
t++;
if (i == 3) id = atol (t);
if (i == 4) value = atoi (t);
printf ("%d %s\n", i, t);
if (i == 3) {
char *v = strchr (t, '=');
id = atol (t);
if (v == NULL) break;
value = atoi(++v);
debug ("id:%d value:%d", id, value);
vdev->SetDevCtrl(id, value);
break;
}
if (i > 4) break;
}
vdev->SetDevCtrl(id, value);
JSONParse jp;
jp.Clear();
return jp.ToString();
}
std::string API_Get_Values() {
return config.GetValues();
}
std::string API_Set_Value(std::string request) {
std::string name;
std::string value;
char *t = (char*) request.c_str();
int i = 0;
while ((t = strchr (t, '/'))) {
i++;
t++;
printf ("%d %s\n", i, t);
if (i == 3) {
char *v = strchr (t, '=');
if (v == NULL) break;
name = ((std::string) t).substr(0, (v-t));
value = (++v);
debug ("name:%s value:%s", name.c_str(), value.c_str());
config.SetValue(name, value);
break;
}
if (i > 4) break;
}
JSONParse jp;
jp.Clear();
return jp.ToString();
}

@ -2,3 +2,14 @@ body {
background-color: #444;
color: #BBB;
}
table, th, td {
border: thin solid;
border-collapse: collapse;
}
.float {
float: left;
padding: 10px;
border: thin solid;
}

@ -19,7 +19,14 @@
<br>
<table id="controls"></table>
<div class="float">
<h2>Controls</h2><hr>
<table id="controls"></table>
</div>
<div class="float">
<h2>Infos</h2><hr>
<table id="variables"></table>
</div>
<br>
@ -32,6 +39,7 @@
<script>
let ctrls;
let variables;
function reloadImage() {
const img1 = document.getElementById('webcamimage');
@ -59,7 +67,34 @@ function refreshCtrls() {
ctrls.ctrls.forEach(function (elm, idx) {
t += "<tr><td>"+elm.name+"</td><td>"+elm.min+"</td>"+
"<td>"+elm.max+"</td><td>" +
"<input class=\"ctrlvalue\" dataid=\""+elm.id+"\" value=\""+elm.value+"\"></td></tr>";
"<input class=\"ctrlvalue\" dataid=\""+elm.id+"\" value=\""+elm.value+"\" size=\"6\"></td></tr>";
});
t += "</tbody>";
table.innerHTML = t;
},
error: function(error) {
debug.innerHTML = "ERROR";
}
});
}
function refreshVariables() {
let debug = document.getElementById("debug");
$.ajax({
type: "POST",
url: 'get/variables',
data: "",
success: function(response)
{
let jsonData = {};
variables = JSON.parse(response);
let table = document.getElementById("variables");
let t = "<tbody>";
variables.variables.forEach(function (elm, idx) {
t += "<tr><td>"+elm.name+"</td><td><input class=\"variablevalue\" dataid=\""+elm.name+"\" value=\""+elm.value+"\" size=\"6\"></td></tr>";
});
t += "</tbody>";
table.innerHTML = t;
@ -70,12 +105,33 @@ function refreshCtrls() {
});
}
function setCtrl(id, value) {
let debug = document.getElementById("debug");
$.ajax({
type: "POST",
url: 'set/ctrl/'+id+"/"+value,
url: 'set/ctrl/'+id+"="+value,
data: "",
success: function(response)
{
refreshCtrls();
},
error: function(error) {
debug.innerHTML = "ERROR";
}
});
}
function setVariable(id, value) {
let debug = document.getElementById("debug");
$.ajax({
type: "POST",
url: 'set/var/'+id+"="+value,
data: "",
success: function(response)
{
@ -87,8 +143,10 @@ function setCtrl(id, value) {
});
}
setInterval(reloadImage, 500);
refreshCtrls();
refreshVariables();
$(document).on('keypress', '.ctrlvalue', function(e) {
if (e.key === 'Enter' || e.keyCode === 13) {
@ -102,6 +160,18 @@ $(document).on('keypress', '.ctrlvalue', function(e) {
}
});
$(document).on('keypress', '.variablevalue', function(e) {
if (e.key === 'Enter' || e.keyCode === 13) {
// Hier deine Funktion einfügen
let id = this.getAttribute('dataid');
let value = this.value;
setVariable(id, value);
// Verhindert das Standard-Verhalten (z. B. Formular absenden)
e.preventDefault();
}
});
</script>
</html>
Loading…
Cancel
Save