aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2019-12-23 10:20:48 +0100
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2019-12-23 10:20:48 +0100
commitaf25f6071811b499167a0a8e3634fb5e43f6c1cc (patch)
treee8d9769c483278611d974cc639a8823f83a9d03f
parent9c6f6a1c6b2207411ff9ae1278dfddf271e525b3 (diff)
parent841117da51e8beac2e2048b75b6c30368941ffa3 (diff)
Merge branch 'matheusmoreira-oneshot'
* matheusmoreira-oneshot: zbarcam: remove LF from raw one shot mode output zbarimg: remove LF from raw one shot mode output zbarcam: add one shot scanning mode zbarimg: add one shot scanning mode
-rw-r--r--zbarcam/zbarcam.c74
-rw-r--r--zbarimg/zbarimg.c14
2 files changed, 58 insertions, 30 deletions
diff --git a/zbarcam/zbarcam.c b/zbarcam/zbarcam.c
index 3dfa812..3e8b669 100644
--- a/zbarcam/zbarcam.c
+++ b/zbarcam/zbarcam.c
@@ -49,6 +49,7 @@ static const char *note_usage =
" --verbose=N set specific debug output level\n"
" --xml use XML output format\n"
" --raw output decoded symbol data without symbology prefix\n"
+ " -1, --oneshot exit after scanning one QR code\n"
#ifdef HAVE_DBUS
" --nodbus disable dbus message\n"
#endif
@@ -67,7 +68,7 @@ static const char *xml_foot =
"</source></barcodes>\n";
static zbar_processor_t *proc;
-static int quiet = 0;
+static int quiet = 0, oneshot = 0;
static enum {
DEFAULT, RAW, XML
} format = DEFAULT;
@@ -88,7 +89,7 @@ static inline int parse_config (const char *cfgstr, int i, int n, char *arg)
fprintf(stderr, "ERROR: need argument for option: %s\n", arg);
return(1);
}
-
+
if(zbar_processor_parse_config(proc, cfgstr)) {
fprintf(stderr, "ERROR: invalid configuration setting: %s\n", cfgstr);
return(1);
@@ -129,8 +130,14 @@ static void data_handler (zbar_image_t *img, const void *userdata)
if(fwrite(xml_buf, xml_len, 1, stdout) != 1)
continue;
}
- printf("\n");
n++;
+
+ if(oneshot) {
+ if (format != RAW)
+ printf("\n");
+ break;
+ } else
+ printf("\n");
}
if(format == XML && n)
@@ -187,6 +194,7 @@ int main (int argc, const char *argv[])
case 'h': return(usage(0));
case 'v': zbar_increase_verbosity(); break;
case 'q': quiet = 1; break;
+ case '1': oneshot = 1; break;
default:
fprintf(stderr, "ERROR: unknown bundled config: -%c\n\n",
argv[i][j]);
@@ -214,6 +222,8 @@ int main (int argc, const char *argv[])
}
else if(!strcmp(argv[i], "--quiet"))
quiet = 1;
+ else if(!strcmp(argv[i], "--oneshot"))
+ oneshot = 1;
else if(!strcmp(argv[i], "--xml"))
format = XML;
else if(!strcmp(argv[i], "--raw"))
@@ -292,34 +302,40 @@ int main (int argc, const char *argv[])
if(zbar_processor_set_active(proc, active))
return(zbar_processor_error_spew(proc, 0));
- /* let the callback handle data */
- int rc;
- while((rc = zbar_processor_user_wait(proc, -1)) >= 0) {
- if(rc == 'q' || rc == 'Q')
- break;
- // HACK: controls are known on V4L2 by ID, not by name. This is also
- // not compatible with other platforms
- if(rc == 'b' || rc == 'B') {
- int value;
- zbar_processor_get_control(proc, "Brightness", &value);
- zbar_processor_set_control(proc, "Brightness", ++value);
- }
- if(rc == 'n' || rc == 'N') {
- int value;
- zbar_processor_get_control(proc, "Brightness", &value);
- zbar_processor_set_control(proc, "Brightness", --value);
- }
- if(rc == ' ') {
- active = !active;
- if(zbar_processor_set_active(proc, active))
- return(zbar_processor_error_spew(proc, 0));
+ if (oneshot) {
+ if (zbar_process_one(proc, -1) < 0)
+ if (zbar_processor_get_error_code(proc) != ZBAR_ERR_CLOSED)
+ return zbar_processor_error_spew(proc, 0);
+ } else {
+ /* let the callback handle data */
+ int rc;
+ while((rc = zbar_processor_user_wait(proc, -1)) >= 0) {
+ if(rc == 'q' || rc == 'Q')
+ break;
+ // HACK: controls are known on V4L2 by ID, not by name. This is also
+ // not compatible with other platforms
+ if(rc == 'b' || rc == 'B') {
+ int value;
+ zbar_processor_get_control(proc, "Brightness", &value);
+ zbar_processor_set_control(proc, "Brightness", ++value);
+ }
+ if(rc == 'n' || rc == 'N') {
+ int value;
+ zbar_processor_get_control(proc, "Brightness", &value);
+ zbar_processor_set_control(proc, "Brightness", --value);
+ }
+ if(rc == ' ') {
+ active = !active;
+ if(zbar_processor_set_active(proc, active))
+ return(zbar_processor_error_spew(proc, 0));
+ }
}
- }
- /* report any errors that aren't "window closed" */
- if(rc && rc != 'q' && rc != 'Q' &&
- zbar_processor_get_error_code(proc) != ZBAR_ERR_CLOSED)
- return(zbar_processor_error_spew(proc, 0));
+ /* report any errors that aren't "window closed" */
+ if(rc && rc != 'q' && rc != 'Q' &&
+ zbar_processor_get_error_code(proc) != ZBAR_ERR_CLOSED)
+ return(zbar_processor_error_spew(proc, 0));
+ }
/* free resources (leak check) */
zbar_processor_destroy(proc);
diff --git a/zbarimg/zbarimg.c b/zbarimg/zbarimg.c
index a4732f1..c22374d 100644
--- a/zbarimg/zbarimg.c
+++ b/zbarimg/zbarimg.c
@@ -85,6 +85,7 @@ static const char *note_usage =
" -D, --nodisplay disable display of following images (default)\n"
" --xml, --noxml enable/disable XML output format\n"
" --raw output decoded symbol data without symbology prefix\n"
+ " -1, --oneshot exit after scanning one QR code\n"
" -S<CONFIG>[=<VALUE>], --set <CONFIG>[=<VALUE>]\n"
" set decoder/scanner <CONFIG> to <VALUE> (or 1)\n"
// FIXME overlay level
@@ -147,6 +148,7 @@ static const char *xml_foot =
static int notfound = 0, exit_code = 0;
static int num_images = 0, num_symbols = 0;
static int xmllvl = 0;
+static int oneshot = 0;
char *xmlbuf = NULL;
unsigned xmlbuflen = 0;
@@ -244,9 +246,16 @@ static int scan_image (const char *filename)
return(-1);
}
}
- printf("\n");
found++;
num_symbols++;
+
+ if(oneshot) {
+ if(xmllvl >= 0)
+ printf("\n");
+ break;
+ }
+ else
+ printf("\n");
}
if(xmllvl > 2) {
xmllvl--;
@@ -327,6 +336,7 @@ int main (int argc, const char *argv[])
switch(arg[j]) {
case 'h': return(usage(0, NULL, NULL));
case 'q': quiet = 1; break;
+ case '1': oneshot = 1; break;
case 'v': zbar_increase_verbosity(); break;
case 'd': display = 1; break;
case 'D': break;
@@ -345,6 +355,8 @@ int main (int argc, const char *argv[])
quiet = 1;
argv[i] = NULL;
}
+ else if(!strcmp(arg, "--oneshot"))
+ oneshot = 1;
else if(!strcmp(arg, "--verbose"))
zbar_increase_verbosity();
else if(!strncmp(arg, "--verbose=", 10))

Privacy Policy