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

Example of setting a control whose type is pyrav4l2.controls.MenuItem #7

Open
matanox opened this issue Feb 11, 2024 · 2 comments
Open

Comments

@matanox
Copy link
Contributor

matanox commented Feb 11, 2024

Would it be very tedios to exemplify setting a control's value when the type of the control within pyrav4l2 is a pyrav4l2 MenuItem and not a plain python type?

E.g. this way is obviously wrong:

from pyrav4l2 import Device, MenuItem

dev = Device("/dev/video0")
if dev.is_video_capture_capable:

    for c in dev.controls:
        cv = dev.get_control_value(c)
        if isinstance(cv, MenuItem):
            print(f'{c.name} is {cv.name} (a MenuItem)')
            if c.name == 'LED1 Mode':
                dev.set_control_value(c, MenuItem(cv.ctrl_id, cv.index, 'On'))
            if c.name == 'LED1 Frequency':
                dev.set_control_value(c, MenuItem(cv.ctrl_id, cv.index, '10 Hz'))
        else:
            print(f'{c.name} is {cv}')
@tgorochowik
Copy link
Member

Hi,

MenuItem is used for possible settings of Menu, so I'm assuming dev.controls contains a Menu object. This object contans .items which use the MenuItem class.

Please see this interactive example for reference:

Python 3.11.5 (main, Sep  2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyrav4l2 import Device
>>> dev = Device("/dev/video0")
>>> for i, c in enumerate(dev.controls):
...     print(i, c.name, c)
... 
0 User Controls <pyrav4l2.controls.Control object at 0x7f089c5ecbd0>
1 Brightness <pyrav4l2.controls.Control object at 0x7f089c8b9a10>
2 Contrast <pyrav4l2.controls.Control object at 0x7f089c5ed290>
3 Saturation <pyrav4l2.controls.Control object at 0x7f089c5ed310>
4 Hue <pyrav4l2.controls.Control object at 0x7f089c5ed390>
5 White Balance, Automatic <pyrav4l2.controls.Control object at 0x7f089c5ed450>
6 Gamma <pyrav4l2.controls.Control object at 0x7f089c5ed490>
7 Power Line Frequency <pyrav4l2.controls.Menu object at 0x7f089c5ed710>
(...)
>>> m = dev.controls[7]
>>> for i, mi in enumerate(m.items):
...     print(i, mi.name)
... 
0 Disabled
1 50 Hz
2 60 Hz
3 Auto
>>> dev.get_control_value(m).name
'Disabled'
>>> dev.set_control_value(m, m.items[2])
>>> dev.get_control_value(m).name
'60 Hz'

I hope this helps! If in doubt, you can take a look at https://github.com/antmicro/pyvidctrl - this util utilizes pyrav4l2 quite extensively so should cover all possibilities

@matanox
Copy link
Contributor Author

matanox commented Feb 13, 2024

Thanks a lot! I'll check how I missed that reading the code ...

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

2 participants