new web interface, but still could not figure out how to speed up the image conversion

main
Steffen Pohle 3 weeks ago
parent da165782b1
commit eeac4f134b

@ -294,7 +294,7 @@ void Configuration::SetValue(std::string name, std::string value) {
filter_ratio = atof(value.c_str()); filter_ratio = atof(value.c_str());
debug ("Filter Ration set to : %g", filter_ratio); debug ("Filter Ration set to : %g", filter_ratio);
} }
if (name.compare("auto_birghtness") == 0) { if (name.compare("auto_brightness") == 0) {
auto_brightness = atol(value.c_str()); auto_brightness = atol(value.c_str());
debug ("Auto Brightness set to : %ld", auto_brightness); debug ("Auto Brightness set to : %ld", auto_brightness);
} }
@ -341,4 +341,3 @@ std::string Configuration::GetValues() {
jp.AddObject(je); jp.AddObject(je);
return jp.ToString(); return jp.ToString();
}; };

@ -132,8 +132,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig
destf->SetSize(srcw, srch); destf->SetSize(srcw, srch);
ptrdstf = destf->GetPixBuf(); ptrdstf = destf->GetPixBuf();
} }
switch (pixelformat) { switch (pixelformat) {
case (V4L2_PIX_FMT_RGB32): case (V4L2_PIX_FMT_RGB32):
for (ys = 0, yd = 0; ys < (signed int)srch; ys++) { for (ys = 0, yd = 0; ys < (signed int)srch; ys++) {

@ -47,13 +47,13 @@ static void *thread_webserver(void *ignored_argument) {
static void *thread_video(void *ignored_argument) { static void *thread_video(void *ignored_argument) {
int cycle = 0; timeval tv_fps;
timeval tv1; time_t time_fps, time_refreshctls;
time_t time1;
time1 = time(NULL); time_fps = time(NULL);
time_refreshctls = time(NULL);
gettimeofday(&tv1, NULL); gettimeofday(&tv_fps, NULL);
if (config.vdev_dumpfile.length() > 0) { if (config.vdev_dumpfile.length() > 0) {
vdev = new VideoDevice_Dump(); vdev = new VideoDevice_Dump();
@ -82,9 +82,12 @@ static void *thread_video(void *ignored_argument) {
vdev->Stop(); vdev->Stop();
vdev->Start(); vdev->Start();
} }
if ((cycle++ % 10) == 0) vdev->RefreshCtrls(); if (time(NULL) - time_refreshctls > 10) {
if (time(NULL) - time1 > 5) { vdev->RefreshCtrls();
time1 = time(NULL); time_refreshctls = time(NULL);
}
if (time(NULL) - time_fps > 5) {
time_fps = time(NULL);
debug ("FPS: %f", framespersecond); debug ("FPS: %f", framespersecond);
} }
Lock(); Lock();
@ -93,8 +96,8 @@ static void *thread_video(void *ignored_argument) {
inputfloat.CopyTo(&inputfloatfilter); inputfloat.CopyTo(&inputfloatfilter);
inputfloatfilter.CopyTo(&currentimagefloat); inputfloatfilter.CopyTo(&currentimagefloat);
UnLock(); UnLock();
if (framespersecond == -1) framespersecond = 1.0/(timedeiff_ms(&tv1)/1000.0); if (framespersecond == -1) framespersecond = 1.0/(timedeiff_ms(&tv_fps)/1000.0);
else framespersecond = (framespersecond * 59.0 + 1.0/(timedeiff_ms(&tv1)/1000.0)) / 60.0; else framespersecond = (framespersecond * 59.0 + 1.0/(timedeiff_ms(&tv_fps)/1000.0)) / 60.0;
} }
thread_video_exit: thread_video_exit:
@ -159,6 +162,9 @@ int main(int argc, char **argv) {
usleep (1000); usleep (1000);
} }
pthread_join(thr_webserver, NULL);
pthread_join(thr_video, NULL);
return 0; return 0;
}; };

@ -435,9 +435,7 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP; buf.memory = V4L2_MEMORY_MMAP;
Lock();
ret = xioctl(fd, VIDIOC_DQBUF, &buf); ret = xioctl(fd, VIDIOC_DQBUF, &buf);
UnLock();
if (ret == -1) { if (ret == -1) {
switch (errno) { switch (errno) {
case EAGAIN: case EAGAIN:
@ -457,9 +455,7 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat
Convert(&cdata, destframe, destfloat, inbuffer[buf.index].data, buf.bytesused, Convert(&cdata, destframe, destfloat, inbuffer[buf.index].data, buf.bytesused,
fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height); fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height);
} }
Lock();
ret = xioctl(fd, VIDIOC_QBUF, &buf); ret = xioctl(fd, VIDIOC_QBUF, &buf);
UnLock();
if (ret == -1) { if (ret == -1) {
debug ("error on VIDIOC_QBUF %s", strerror(errno)); debug ("error on VIDIOC_QBUF %s", strerror(errno));
@ -542,6 +538,26 @@ int VideoDevice_V4L2::GetDevCtrl(unsigned int id, int *value) {
}; };
void VideoDevice_V4L2::RefreshCtrls() {
std::list<VideoDevCtrl>::iterator i;
struct v4l2_queryctrl queryctrl;
int ret;
for (i = vidctrls.begin(); i != vidctrls.end(); i++) {
CLEAR(queryctrl);
queryctrl.id = i->id;
Lock();
ret = xioctl(cfd != -1 ? cfd : fd, VIDIOC_QUERYCTRL, &queryctrl);
UnLock();
if (ret == 0) {
i->min = queryctrl.minimum;
i->max = queryctrl.maximum;
}
GetDevCtrl(i->id, &i->value);
}
};
void VideoDevice_V4L2::PrintCaps(uint32_t caps) { void VideoDevice_V4L2::PrintCaps(uint32_t caps) {
printf ("%s:%d %s Caps: %x\n", __FILE__, __LINE__, __FUNCTION__, caps); printf ("%s:%d %s Caps: %x\n", __FILE__, __LINE__, __FUNCTION__, caps);
@ -572,4 +588,3 @@ void VideoDevice_V4L2::PrintFmt(struct v4l2_format *f) {
printf (" fmt.pix.bytesperline : %d\n", f->fmt.pix.bytesperline); printf (" fmt.pix.bytesperline : %d\n", f->fmt.pix.bytesperline);
printf (" fmt.pix.sizeimage : %d\n", f->fmt.pix.sizeimage); printf (" fmt.pix.sizeimage : %d\n", f->fmt.pix.sizeimage);
}; };

@ -33,6 +33,7 @@ class VideoDevice_V4L2 : public VideoDevice {
int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat); int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat);
int SetDevCtrl(unsigned int id, int value); int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value); int GetDevCtrl(unsigned int id, int *value);
void RefreshCtrls();
void PrintCaps(uint32_t caps); void PrintCaps(uint32_t caps);
void PrintFmt(struct v4l2_format *f); void PrintFmt(struct v4l2_format *f);

@ -33,7 +33,7 @@ void VideoFrame::FreeFrame() {
void VideoFrame::AllocateFrame() { void VideoFrame::AllocateFrame() {
int memnewsize = width * height * 3; int memnewsize = width * height * 3;
if (memnewsize < mem_allocated) return; if (memnewsize <= mem_allocated) return;
else if (memnewsize == 0) FreeFrame(); else if (memnewsize == 0) FreeFrame();
mem = (unsigned char *) realloc (mem, memnewsize); mem = (unsigned char *) realloc (mem, memnewsize);
@ -48,6 +48,7 @@ void VideoFrame::AllocateFrame() {
int VideoFrame::SetSize(int w, int h) { int VideoFrame::SetSize(int w, int h) {
if (w < 0 && h < 0) return 0; if (w < 0 && h < 0) return 0;
if (w == width && h == height) return 1;
width = w; width = w;
height = h; height = h;
@ -188,7 +189,7 @@ void VideoFrameFloat::FreeFrame() {
void VideoFrameFloat::AllocateFrame() { void VideoFrameFloat::AllocateFrame() {
int memnewsize = width * height * 3 * sizeof(float); int memnewsize = width * height * 3 * sizeof(float);
if (memnewsize < memf_allocated) return; if (memnewsize <= memf_allocated) return;
else if (memnewsize == 0) { else if (memnewsize == 0) {
FreeFrame(); FreeFrame();
return; return;
@ -231,6 +232,7 @@ int VideoFrameFloat::TestScreen(int w, int h) {
int VideoFrameFloat::SetSize(int w, int h) { int VideoFrameFloat::SetSize(int w, int h) {
if (w < 0 || h < 0) return 0; if (w < 0 || h < 0) return 0;
if (width == w && height == h) return 1;
width = w; width = w;
height = h; height = h;

@ -1,20 +1,632 @@
:root {
color-scheme: dark;
--page: #101820;
--surface: #17232d;
--surface-raised: #1d2b37;
--border: #2a3a47;
--text: #edf4f7;
--muted: #91a2ae;
--accent: #55d6be;
--accent-dark: #143b39;
--danger: #ff817c;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
body { body {
background-color: #444; min-width: 320px;
color: #BBB; min-height: 100vh;
margin: 0;
background:
radial-gradient(ellipse at 50% -20%, rgba(47, 105, 114, 0.2), transparent 55%),
var(--page);
color: var(--text);
}
button,
input {
font: inherit;
}
.app-shell {
width: min(1440px, 100%);
margin: 0 auto;
padding: 0 36px;
}
.topbar {
min-height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid rgba(145, 162, 174, 0.15);
}
.brand {
display: inline-flex;
align-items: center;
gap: 12px;
color: var(--text);
text-decoration: none;
}
.brand-mark {
width: 40px;
height: 40px;
display: grid;
place-items: center;
border: 1px solid rgba(85, 214, 190, 0.32);
border-radius: 12px;
background: var(--accent-dark);
color: var(--accent);
}
.brand-mark svg {
width: 23px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.7;
}
.brand strong,
.brand small {
display: block;
}
.brand strong {
font-size: 15px;
letter-spacing: 0.01em;
}
.brand small {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.connection-status,
.section-title {
display: inline-flex;
align-items: center;
gap: 9px;
}
.connection-status {
color: #b6c5cc;
font-size: 12px;
}
.status-dot,
.live-indicator {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px rgba(85, 214, 190, 0.55);
}
.connection-status.offline .status-dot {
background: var(--danger);
box-shadow: 0 0 12px rgba(255, 129, 124, 0.4);
}
main {
padding-top: 42px;
}
.page-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 26px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
h1 {
margin-bottom: 8px;
font-size: clamp(26px, 3vw, 36px);
font-weight: 650;
letter-spacing: -0.035em;
}
.subtitle {
margin-bottom: 0;
color: var(--muted);
font-size: 14px;
}
.toggle-card {
position: relative;
display: flex;
align-items: center;
gap: 18px;
min-width: 238px;
padding: 13px 15px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(23, 35, 45, 0.8);
cursor: pointer;
}
.toggle-copy {
flex: 1;
}
.toggle-copy strong,
.toggle-copy small {
display: block;
}
.toggle-copy strong {
font-size: 12px;
font-weight: 650;
}
.toggle-copy small {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.toggle-card input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.toggle-track {
position: relative;
width: 36px;
height: 21px;
flex: 0 0 auto;
border-radius: 20px;
background: #384852;
transition: background 160ms ease;
}
.toggle-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 15px;
height: 15px;
border-radius: 50%;
background: white;
content: "";
transition: transform 160ms ease;
}
.toggle-card input:checked + .toggle-track {
background: #258f7c;
}
.toggle-card input:checked + .toggle-track::after {
transform: translateX(15px);
}
.toggle-card input:focus-visible + .toggle-track {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.preview-card,
.panel {
overflow: hidden;
border: 1px solid var(--border);
border-radius: 15px;
background: rgba(23, 35, 45, 0.92);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14);
}
.section-bar,
.preview-footer {
display: flex;
align-items: center;
justify-content: space-between;
}
.section-bar {
min-height: 54px;
padding: 0 18px;
}
.section-title {
gap: 10px;
}
.section-title h2,
.panel-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 650;
}
.preview-label {
padding: 5px 9px;
border: 1px solid var(--border);
border-radius: 20px;
color: #b6c5cc;
font-size: 10px;
}
.preview-stage {
position: relative;
display: grid;
min-height: 240px;
aspect-ratio: 16 / 8.5;
max-height: 68vh;
place-items: center;
overflow: hidden;
background:
linear-gradient(135deg, rgba(42, 58, 71, 0.35), transparent 50%),
#0a1117;
}
.preview-stage img {
display: block;
width: 100%;
height: 100%;
object-fit: contain;
}
.preview-error {
position: absolute;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(16, 24, 32, 0.88);
color: var(--muted);
font-size: 12px;
} }
.noborder { .preview-footer {
border: none; min-height: 42px;
padding: 0 18px;
border-top: 1px solid rgba(145, 162, 174, 0.12);
color: var(--muted);
font-size: 10px;
} }
.withborder { .content-grid {
border: thin solid; display: grid;
border-collapse: collapse; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.85fr);
align-items: start;
gap: 18px;
margin-top: 20px;
} }
.float { .panel {
float: left; padding: 20px;
padding: 10px;
border: thin solid;
} }
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 17px;
}
.panel-heading .eyebrow {
margin-bottom: 6px;
}
.panel-heading h2 {
font-size: 17px;
letter-spacing: -0.02em;
}
.count-badge {
padding: 5px 9px;
border: 1px solid var(--border);
border-radius: 20px;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.search-box {
display: flex;
align-items: center;
gap: 9px;
height: 38px;
margin-bottom: 14px;
padding: 0 11px;
border: 1px solid var(--border);
border-radius: 8px;
background: #121d26;
color: var(--muted);
}
.search-box:focus-within {
border-color: rgba(85, 214, 190, 0.65);
}
.search-box svg {
width: 16px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-width: 1.8;
}
.search-box input {
width: 100%;
border: 0;
outline: 0;
background: transparent;
color: var(--text);
font-size: 12px;
}
.search-box input::placeholder {
color: #748591;
}
.control-list,
.settings-list {
display: grid;
gap: 9px;
}
.control-card,
.setting-row {
min-width: 0;
padding: 13px;
border: 1px solid rgba(145, 162, 174, 0.14);
border-radius: 10px;
background: rgba(29, 43, 55, 0.58);
}
.control-card {
display: grid;
grid-template-columns: minmax(100px, 1fr) minmax(80px, 1.5fr) 78px auto;
align-items: center;
gap: 12px;
}
.control-header {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 4px 8px;
min-width: 0;
}
.control-header h3,
.setting-details h3 {
overflow-wrap: anywhere;
margin: 0;
font-size: 12px;
font-weight: 600;
text-transform: capitalize;
}
.range-label {
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.control-input-row {
display: grid;
grid-column: 2 / -1;
grid-template-columns: minmax(0, 1fr) 78px auto;
align-items: center;
gap: 8px;
}
.control-slider {
width: 100%;
height: 4px;
accent-color: var(--accent);
cursor: pointer;
}
.control-slider:disabled {
cursor: not-allowed;
opacity: 0.4;
}
.control-value,
.variable-value {
width: 100%;
min-width: 0;
height: 32px;
padding: 0 8px;
border: 1px solid var(--border);
border-radius: 6px;
outline: 0;
background: #111b23;
color: var(--text);
font-size: 12px;
}
.control-value:focus,
.variable-value:focus {
border-color: var(--accent);
}
.button {
border: 1px solid rgba(85, 214, 190, 0.32);
border-radius: 6px;
background: var(--accent-dark);
color: #90f0dc;
cursor: pointer;
font-weight: 650;
transition: background 140ms ease, border-color 140ms ease;
}
.button:hover {
border-color: var(--accent);
background: #1b514b;
}
.button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.button-small {
min-height: 32px;
padding: 0 10px;
font-size: 10px;
}
.setting-row {
display: grid;
gap: 12px;
}
.setting-details p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.setting-editor {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 8px;
}
.panel-hint {
margin: 13px 1px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.empty-state {
padding: 18px 12px;
border: 1px dashed rgba(145, 162, 174, 0.25);
border-radius: 9px;
color: var(--muted);
font-size: 11px;
text-align: center;
}
.notice {
margin-top: 18px;
padding: 12px 14px;
border: 1px solid rgba(255, 129, 124, 0.35);
border-radius: 9px;
background: rgba(83, 37, 39, 0.28);
color: #ffaaa5;
font-size: 12px;
}
.footer {
display: flex;
justify-content: space-between;
padding: 24px 2px 28px;
color: #748591;
font-size: 10px;
}
[hidden] {
display: none !important;
}
@media (max-width: 850px) {
.app-shell {
padding: 0 22px;
}
.content-grid {
grid-template-columns: minmax(0, 1fr);
}
.preview-stage {
aspect-ratio: 16 / 10;
}
}
@media (max-width: 560px) {
.app-shell {
padding: 0 14px;
}
.topbar {
min-height: 68px;
}
main {
padding-top: 28px;
}
.page-heading {
align-items: stretch;
flex-direction: column;
gap: 17px;
}
.toggle-card {
min-width: 0;
width: 100%;
}
.preview-stage {
min-height: 190px;
aspect-ratio: 4 / 3;
}
.section-bar,
.preview-footer {
padding-right: 12px;
padding-left: 12px;
}
.panel {
padding: 15px;
}
.control-card {
grid-template-columns: minmax(0, 0.9fr) minmax(35px, 1fr) 62px auto;
gap: 6px;
padding: 9px;
}
.control-input-row {
display: contents;
}
.control-slider {
grid-column: 2;
}
.control-value {
grid-column: 3;
}
.control-card .button {
grid-column: 4;
}
.footer {
padding-bottom: 20px;
}
}

@ -1,192 +1,397 @@
<html> <!doctype html>
<html lang="en">
<head> <head>
<title>MiniWebCam</title> <meta charset="utf-8">
<script src="jquery-3.1.0.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#101820">
<link rel="stylesheet" href="default.css"> <link rel="stylesheet" href="default.css">
<title>MiniWebCam</title>
</head> </head>
<body> <body>
<div class="app-shell">
<table class="noborder"><tr><td> <header class="topbar">
<label>Filter Processing<input id="floatimage" type="checkbox"></label> <a class="brand" href="/" aria-label="MiniWebCam home">
</td><td> <span class="brand-mark" aria-hidden="true">
<label>Auto Brightness<input id="autobright" type="search" list="autobrightlist"><datalist id="autobrightlist"></datalist></label> <svg viewBox="0 0 24 24"><path d="M4 7.5h3l1.5-2h7l1.5 2h3A1.5 1.5 0 0 1 21.5 9v9a1.5 1.5 0 0 1-1.5 1.5H4A1.5 1.5 0 0 1 2.5 18V9A1.5 1.5 0 0 1 4 7.5Z"/><circle cx="12" cy="13" r="4"/></svg>
</td></tr> </span>
</table> <span>
<br> <strong>MiniWebCam</strong>
<small>Camera dashboard</small>
<div class="webcamimage"> </span>
<img id="webcamimage" src="snapshot.jpg"></img> </a>
</div> <div class="connection-status" id="connection-status" role="status">
<span class="status-dot" aria-hidden="true"></span>
<br> <span id="status-text">Connecting…</span>
</div>
<div class="float"> </header>
<h2>Controls</h2><hr>
<table id="controls" class="withborder"></table> <main>
</div> <section class="page-heading">
<div class="float"> <div>
<h2>Infos</h2><hr> <p class="eyebrow">LIVE MONITOR</p>
<table id="variables" class="withborder"></table> <h1>Camera overview</h1>
</div> <p class="subtitle">Live video and device controls in one place.</p>
</div>
<br> <label class="toggle-card" for="floatimage">
<span class="toggle-copy">
<div id="debug"> <strong>Filter processing</strong>
</div> <small>Show the processed image</small>
</span>
</body> <input id="floatimage" type="checkbox" role="switch">
<span class="toggle-track" aria-hidden="true"></span>
<script> </label>
</section>
let ctrls;
let variables; <section class="preview-card" aria-label="Live camera preview">
<div class="section-bar">
function reloadImage() { <div class="section-title">
const img1 = document.getElementById('webcamimage'); <span class="live-indicator" aria-hidden="true"></span>
const filterimage1 = document.getElementById('floatimage'); <h2>Live preview</h2>
let src1 = "snapshot.jpg"; </div>
if (filterimage1.checked) src1 = "snapshot-float.jpg"; <span class="preview-label" id="preview-label">Standard image</span>
src1 = src1 + '?' + new Date().getTime(); </div>
img1.src = src1; <div class="preview-stage">
} <img id="webcamimage" src="snapshot.jpg" alt="Live webcam preview">
<div class="preview-error" id="preview-error" hidden>Waiting for camera image…</div>
function refreshCtrls() { </div>
let debug = document.getElementById("debug"); <div class="preview-footer">
let datalist = document.getElementById("autobrightlist"); <span>Image updates automatically</span>
datalist.innerHTML = ""; <span id="last-updated">Waiting for first frame</span>
$.ajax({ </div>
type: "POST", </section>
url: 'get/ctrls',
data: "", <div class="content-grid">
success: function(response) <section class="panel controls-panel">
{ <div class="panel-heading">
let jsonData = {}; <div>
<p class="eyebrow">DEVICE</p>
ctrls = JSON.parse(response); <h2>Camera controls</h2>
let table = document.getElementById("controls"); </div>
let t = "<thead class=\"withborder\"><tr class=\"withborder\"><th class=\"withborder\">Name</th><th class=\"withborder\">Min</th><th class=\"withborder\">Max</th><th class=\"withborder\">Value</th></thead><tbody>"; <span class="count-badge" id="control-count">0 controls</span>
ctrls.ctrls.forEach(function (elm, idx) { </div>
t += "<tr class=\"withborder\"><td class=\"withborder\">"+elm.name+"</td><td class=\"withborder\">"+elm.min+"</td>"+ <label class="search-box" for="control-search">
"<td class=\"withborder\">"+elm.max+"</td><td class=\"withborder\">" + <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.8" cy="10.8" r="6.8"/><path d="m16 16 5 5"/></svg>
"<input class=\"ctrlvalue\" dataid=\""+elm.id+"\" value=\""+elm.value+"\" size=\"6\" inputmode=\"search\"></td></tr>"; <input id="control-search" type="search" placeholder="Find a control…" autocomplete="off">
datalist.innerHTML += "<option value=\""+elm.id + " " + elm.name+"\">"; </label>
<div class="control-list" id="controls">
<div class="empty-state">Loading camera controls…</div>
</div>
<p class="panel-hint">Adjust a slider or enter a value, then select Apply. Press Enter to apply from the value field.</p>
</section>
<section class="panel settings-panel">
<div class="panel-heading">
<div>
<p class="eyebrow">PROCESSING</p>
<h2>Image settings</h2>
</div>
</div>
<div class="settings-list" id="variables">
<div class="empty-state">Loading image settings…</div>
</div>
<p class="panel-hint">Changes take effect immediately. Press Enter or select Apply to save.</p>
</section>
</div>
<div class="notice" id="notice" role="alert" hidden></div>
</main>
<footer class="footer">
<span>MiniWebCam</span>
<span>Local camera dashboard</span>
</footer>
</div>
<script>
const image = document.getElementById("webcamimage");
const controlsElement = document.getElementById("controls");
const variablesElement = document.getElementById("variables");
const notice = document.getElementById("notice");
const statusText = document.getElementById("status-text");
const connectionStatus = document.getElementById("connection-status");
let controls = [];
let filterEnabled = false;
let refreshCount = 0;
function post(url) {
return fetch(url, { method: "POST" }).then(function(response) {
if (!response.ok) throw new Error("Request failed: " + response.status);
return response.text();
}); });
t += "</tbody>"; }
table.innerHTML = t;
}, function setStatus(connected, message) {
error: function(error) { connectionStatus.classList.toggle("offline", !connected);
debug.innerHTML = "ERROR"; statusText.textContent = message;
} }
});
} function showError(message) {
notice.textContent = message;
notice.hidden = false;
function refreshVariables() { }
let debug = document.getElementById("debug");
function clearError() {
$.ajax({ notice.hidden = true;
type: "POST", notice.textContent = "";
url: 'get/variables', }
data: "",
success: function(response) function reloadImage() {
{ const imageName = filterEnabled ? "snapshot-float.jpg" : "snapshot.jpg";
let jsonData = {}; image.src = imageName + "?" + Date.now();
document.getElementById("preview-label").textContent =
variables = JSON.parse(response); filterEnabled ? "Processed image" : "Standard image";
let table = document.getElementById("variables"); }
let t = "<thead><tr class=\"withborder\"><th class=\"withborder\">Name</th><th class=\"withborder\">Value</th><th class=\"withborder\">Description</th></thead><tbody>";
variables.variables.forEach(function (elm, idx) { image.addEventListener("load", function() {
t += "<tr class=\"withborder\"><td class=\"withborder\">"+elm.name+"</td>"+ document.getElementById("preview-error").hidden = true;
"<td class=\"withborder\"><input class=\"variablevalue\" dataid=\""+elm.name+"\" value=\""+elm.value+"\" size=\"6\" inputmode=\"search\"></td>"+ document.getElementById("last-updated").textContent =
"<td class=\"withborder\">"+elm.desc+"</td></tr>"; "Updated " + new Date().toLocaleTimeString();
});
image.addEventListener("error", function() {
document.getElementById("preview-error").hidden = false;
});
document.getElementById("floatimage").addEventListener("change", function() {
filterEnabled = this.checked;
reloadImage();
});
function makeControlCard(control) {
const card = document.createElement("article");
card.className = "control-card";
card.dataset.name = String(control.name).toLocaleLowerCase();
const header = document.createElement("div");
header.className = "control-header";
const name = document.createElement("h3");
name.textContent = control.name;
const range = document.createElement("span");
range.className = "range-label";
range.textContent = control.min + " – " + control.max;
header.append(name, range);
const inputRow = document.createElement("div");
inputRow.className = "control-input-row";
const slider = document.createElement("input");
slider.className = "control-slider";
slider.type = "range";
slider.min = control.min;
slider.max = control.max;
slider.value = control.value;
slider.dataset.id = control.id;
slider.setAttribute("aria-label", control.name + " slider");
slider.disabled = Number(control.max) <= Number(control.min);
const value = document.createElement("input");
value.className = "control-value";
value.type = "number";
value.inputMode = "numeric";
value.min = control.min;
value.max = control.max;
value.value = control.value;
value.dataset.id = control.id;
value.setAttribute("aria-label", control.name + " value");
let submitTimeout;
slider.addEventListener("input", function() {
value.value = slider.value;
window.clearTimeout(submitTimeout);
submitTimeout = window.setTimeout(function() {
submitControl(value);
}, 300);
});
slider.addEventListener("change", function() {
window.clearTimeout(submitTimeout);
submitControl(value);
}); });
t += "</tbody>";
table.innerHTML = t;
},
error: function(error) {
debug.innerHTML = "ERROR";
}
});
}
function setCtrl(id, value) {
let debug = document.getElementById("debug");
$.ajax({
type: "POST",
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)
{
refreshCtrls();
},
error: function(error) {
debug.innerHTML = "ERROR";
}
});
}
let cyclecnt = 0;
function refresh() {
reloadImage();
if (((cyclecnt++) % 25) == 0) {
refreshCtrls();
refreshVariables();
}
}
setInterval(refresh, 500);
refreshCtrls();
refreshVariables();
$(document).on('keypress', '.ctrlvalue', function(e) {
if (e.key === 'Enter' || e.keyCode === 13) {
// Hier deine Funktion einfügen
let id = this.getAttribute('dataid');
let value = this.value;
setCtrl(id, value);
// Verhindert das Standard-Verhalten (z. B. Formular absenden)
e.preventDefault();
}
});
$(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) const apply = document.createElement("button");
e.preventDefault(); apply.className = "button button-small";
} apply.type = "button";
}); apply.dataset.action = "apply-control";
apply.textContent = "Apply";
apply.addEventListener("click", function() {
submitControl(value);
});
inputRow.append(slider, value, apply);
card.append(header, inputRow);
return card;
}
function refreshCtrls() {
return post("get/ctrls")
.then(function(response) {
const data = JSON.parse(response);
controls = data.ctrls || [];
const activeId = document.activeElement &&
(document.activeElement.classList.contains("control-value") ||
document.activeElement.classList.contains("control-slider"))
? document.activeElement.dataset.id
: null;
if (activeId === null) {
controlsElement.replaceChildren();
if (controls.length === 0) {
const empty = document.createElement("div");
empty.className = "empty-state";
empty.textContent = "No camera controls are available.";
controlsElement.appendChild(empty);
} else {
controls.forEach(function(control) {
controlsElement.appendChild(makeControlCard(control));
});
}
} else {
controls.forEach(function(control) {
const input = controlsElement.querySelector(
'.control-value[data-id="' + CSS.escape(String(control.id)) + '"]'
);
if (input) {
input.min = control.min;
input.max = control.max;
}
const card = input && input.closest(".control-card");
if (card) {
const slider = card.querySelector(".control-slider");
const isActive = input === document.activeElement ||
slider === document.activeElement;
if (!isActive) {
input.value = control.value;
slider.value = control.value;
}
slider.min = control.min;
slider.max = control.max;
slider.dataset.id = control.id;
slider.disabled = Number(control.max) <= Number(control.min);
card.querySelector(".range-label").textContent =
control.min + " – " + control.max;
}
});
}
document.getElementById("control-count").textContent =
controls.length + (controls.length === 1 ? " control" : " controls");
setStatus(true, "Camera connected");
clearError();
filterControls();
}, function() {
setStatus(false, "Connection issue");
showError("Could not load camera controls. The camera service may be unavailable.");
});
}
function refreshVariables() {
return post("get/variables")
.then(function(response) {
const data = JSON.parse(response);
const variables = data.variables || [];
const activeName = document.activeElement &&
document.activeElement.classList.contains("variable-value")
? document.activeElement.dataset.name
: null;
if (activeName !== null) return;
variablesElement.replaceChildren();
if (variables.length === 0) {
const empty = document.createElement("div");
empty.className = "empty-state";
empty.textContent = "No image settings are available.";
variablesElement.appendChild(empty);
return;
}
variables.forEach(function(variable) {
const row = document.createElement("article");
row.className = "setting-row";
const details = document.createElement("div");
details.className = "setting-details";
const name = document.createElement("h3");
name.textContent = variable.name.replaceAll("_", " ");
const description = document.createElement("p");
description.textContent = variable.desc;
details.append(name, description);
const editor = document.createElement("div");
editor.className = "setting-editor";
const input = document.createElement("input");
input.className = "variable-value";
input.type = "number";
input.step = "any";
input.value = variable.value;
input.dataset.name = variable.name;
input.setAttribute("aria-label", variable.name + " value");
const apply = document.createElement("button");
apply.className = "button button-small";
apply.type = "button";
apply.textContent = "Apply";
apply.addEventListener("click", function() {
submitVariable(input);
});
editor.append(input, apply);
row.append(details, editor);
variablesElement.appendChild(row);
});
}, function() {
showError("Could not load image settings.");
});
}
function submitControl(input) {
if (!input.value.trim()) {
input.focus();
return;
}
post("set/ctrl/" + encodeURIComponent(input.dataset.id) + "=" +
encodeURIComponent(input.value)).then(function() {
clearError();
refreshCtrls();
}, function() {
showError("Could not apply the camera control.");
});
}
function submitVariable(input) {
if (!input.value.trim()) {
input.focus();
return;
}
post("set/var/" + encodeURIComponent(input.dataset.name) + "=" +
encodeURIComponent(input.value)).then(function() {
clearError();
refreshVariables();
}, function() {
showError("Could not apply the image setting.");
});
}
</script> function filterControls() {
const query = document.getElementById("control-search").value
.trim().toLocaleLowerCase();
controlsElement.querySelectorAll(".control-card").forEach(function(card) {
card.hidden = !card.dataset.name.includes(query);
});
}
document.getElementById("control-search").addEventListener("input", filterControls);
document.addEventListener("keydown", function(event) {
if (event.key !== "Enter") return;
if (event.target.classList.contains("control-value")) {
submitControl(event.target);
} else if (event.target.classList.contains("variable-value")) {
submitVariable(event.target);
}
});
function refresh() {
reloadImage();
if (refreshCount++ % 25 === 0) {
refreshCtrls();
refreshVariables();
}
}
refreshCtrls();
refreshVariables();
window.setInterval(refresh, 500);
</script>
</body>
</html> </html>
Loading…
Cancel
Save