Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use q to quit in oneshot mode #265

Open
ghost opened this issue Sep 9, 2023 · 1 comment
Open

Can't use q to quit in oneshot mode #265

ghost opened this issue Sep 9, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 9, 2023

If you launch zbarcam with -1 or --oneshot, , q to quit no longer works.

@matheusmoreira
Copy link
Contributor

That's true. Here's the code I wrote that handles one shot mode:

zbar/zbarcam/zbarcam.c

Lines 327 to 365 in 150df8e

/* start video */
active = 1;
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));
}

In order to support camera controls, that if (oneshot) statement must be moved into the while loop somehow. I couldn't figure out a way to do it back then. I simply used the zbar_process_one interface:

zbar/include/zbar.h

Lines 955 to 967 in 150df8e

/** process from the video stream until a result is available,
* or the timeout (in milliseconds) expires.
* specify a timeout of -1 to scan indefinitely
* (zbar_processor_set_active() may still be used to abort the scan
* from another thread).
* if the library window is visible, video display will be enabled.
* @note that multiple results may still be returned (despite the
* name).
* @returns >0 if symbols were successfully decoded,
* 0 if no symbols were found (ie, the timeout expired)
* or -1 if an error occurs
*/
extern int zbar_process_one(zbar_processor_t *processor, int timeout);

... Which ironically does not return exactly one result, it turns out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant