[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\nindent_style = tab\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.{json,md}]\nindent_size = 2\nindent_style = space\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".gitattributes",
    "content": "* text=auto eol=lf\n"
  },
  {
    "path": ".gitignore",
    "content": "dist/\nnode_modules/\n.uvccrc\n.uvccrc.json\n"
  },
  {
    "path": ".prettierignore",
    "content": "dist/\nexamples/**/*.json\n"
  },
  {
    "path": ".xo-config.cjs",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nmodule.exports = {\n\textends: [\n\t\t\"eslint-config-joelpurra/typescript\",\n\t],\n};\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# [`uvcc`](https://joelpurra.com/projects/uvcc/) changelog\n\nSee [full list of commits](https://github.com/joelpurra/uvcc/commits) for details.\n\n## v7.0.0\n\n- 8779b90 Target Node.js v16, v18, v19, v20\n  - Drop v14 (about two months early), drop v17 (about eight months late), add v19 (about four months late), add v20 (about two months early).\n- 61d8071 Add example output from Elgato Facecam ([4057:0120](./examples/elgato-facecam/4057-120/)) (#28 by @m0ose)\n\n## v6.0.0\n\n- 3a79c54 Add example output from Logitech C922 Pro Stream Webcam ([1133:2140](./examples/logitech-c922/1133-2140/))\n- 9342420 Add example output from Microsoft LifeCam Studio Model 1425 ([1118:2065](./examples/microsoft-1425/1118-2065/)) (#17 by @holbrookdev)\n- aebbe71 Update example output from Logitech C920 ([1133:2093](./examples/logitech-c920/1133-2093/))\n- 235fe37 Take vendor/product ids into account for examples\n  - Relates to [#21](https://github.com/joelpurra/uvcc/issues/21), where the differences between hardware variations within the same camera \"marketing name\" are discussed.\n- 999c7d5 Upgrade forked uvc-control v2\n  - [Targets `node-usb` ^v2.4.1](https://github.com/node-usb/node-usb/releases/tag/v2.4.1) via [the forked `node-uvc-control` v2](https://github.com/joelpurra/node-uvc-control/commits/v2) at [`267b0db`](https://github.com/joelpurra/node-uvc-control/commit/267b0dbe77636e15e69cfb8f3de310641fac72b5).\n  - Still uses the legacy USB device interface.\n- e5e9748 Target Node.js v14, v16, v17, v18\n  - These are the available [current/active/maintenance releases](https://github.com/nodejs/Release) as of 2022-05-12.\n  - Fixes [#25](https://github.com/joelpurra/uvcc/issues/25).\n\n## v5.0.2\n\n- 7cc2775 Upgrade [forked uvc-control v2](https://github.com/joelpurra/node-uvc-control)\n  - [Pins `node-usb` to v1.9.2](https://github.com/node-usb/node-usb/releases/tag/v1.9.2) via [the forked `node-uvc-control` v2](https://github.com/joelpurra/node-uvc-control/commit/v2).\n  - Includes an [upstream fix in `node-usb`](https://github.com/node-usb/node-usb/pull/460) for the `uvcc` program exit delay.\n  - Should fix [#20](https://github.com/joelpurra/uvcc/issues/20) and [#22](https://github.com/joelpurra/uvcc/issues/22).\n\n## v5.0.1\n\n- 3c171b1 Upgrade package-lock.json\n  - Includes [pinning `node-usb` to v1.8.0](https://github.com/node-usb/node-usb/releases/tag/v1.8.0) via [the forked `node-uvc-control` v2](https://github.com/joelpurra/node-uvc-control/commit/d87e551f95d281e6a32f6ad4b379bc7e81ff6273).\n    - Should fix [#19 package errors after node/npm upgrade](https://github.com/joelpurra/uvcc/issues/19).\n\n## v5.0.0\n\n- a2bab40 Target Node.js v12, v14, v16, v17\n  - Fixes [#18](https://github.com/joelpurra/uvcc/issues/18).\n- ebea941 Upgrade package-lock.json\n  - Includes an upgrade to [`node-usb` v1.8.0](https://github.com/node-usb/node-usb/releases/tag/v1.8.0) via [the forked `node-uvc-control` v2](https://github.com/joelpurra/node-uvc-control/commit/42d1c526719f064a5bd4edfeab457a81687f69aa), which breaks [#16](https://github.com/joelpurra/uvcc/issues/16) (delay at program exit) again.\n  - The alternative is that `uvcc` doesn't work at all on the [current Node.js v17](https://github.com/nodejs/Release).\n  - See also [node-usb/node-usb#418](https://github.com/node-usb/node-usb/issues/418).\n- Other dependencies also upgraded.\n\n## v4.0.1\n\n- ccf5e05 Fix `--version` flag\n\n## v4.0.0\n\n- 77757f0 Switch to ESM\n  - Modernizes code to use [Node.js ECMAScript modules](https://nodejs.org/api/esm.html).\n  - Targets [current stable Node.js versions](https://github.com/nodejs/Release) (basically v12, v14, v16) which have ESM support.\n\n## v3.0.1\n\n- 08eb9fe Run npm update\n  - Includes fix in [joelpurra/node-uvc-control@8c5f5f4](https://github.com/joelpurra/node-uvc-control/commit/8c5f5f41389bb6a8b4b243115ab92892d633cb55) for [#16](https://github.com/joelpurra/uvcc/issues/16), pin `node-usb` to v1.6.5 due to long delay due when using v1.7.0.\n- b0ad267 Add npm run debug\n\n## v3.0.0\n\n- e8d7dec Target node.js v12+\n- efde45e Update example output from Logitech C920\n- bed8ac3 Upgrade forked uvc-control v2\n  - Swallows errors when discovering/listing USB/UVC devices.\n    - Avoids some problems with `LIBUSB_ERROR_IO` when using `uvcc devices`. The issue seems to be dependent on the internal (software) state (perhaps the traversal order) of USB drivers/devices (and perhaps on _which_ other USB devices are used) connected to the system. Using `sudo` does not prevent `LIBUSB_ERROR_IO`.\n    - The change means that `uvcc devices` can be used without `sudo` (by swallowing `LIBUSB_ERROR_ACCESS` thrown when opening some USB devices) even when the user has insufficient privileges, although inaccessible UVC devices will not be listed.\n- e5d9f49 Warn for camera mismatch\n  - Fixes part of [#10](https://github.com/joelpurra/uvcc/issues/10) by warning for unexpected camera results.\n- 526b9f4 Upgrade forked uvc-control v2\n  - Fixes part of [#10](https://github.com/joelpurra/uvcc/issues/10) by allowing filtering by only product id, or only by device address.\n- 7a9dd89 Add some styling to command help\n- 4691cbf Update usage examples\n  - Fixes [#14](https://github.com/joelpurra/uvcc/issues/14) by improving examples.\n\n## v2.0.4\n\n- 9f3073e Upgrade forked uvc-control v2\n  - Fixes [#8](https://github.com/joelpurra/uvcc/issues/8), setting `absolute_focus`.\n\n## v2.0.3\n\n- d34da77 Upgrade forked uvc-control v2\n  - Fixes [#6](https://github.com/joelpurra/uvcc/issues/6), setting `absolute_exposure_time`.\n\n## v2.0.2\n\n- 8c24f19 Add compatible cameras and help wanted notes\n\n## v2.0.1\n\n- ff28515 Fix broken anchor tag in README.md\n\n## v2.0.0\n\n### ⚠ Breaking changes\n\n- Camera controls changed name in the upstream `uvc-control` v2, so old exports won't import without edits.\n  - Most changes are from camel-case `someCameraControl` to snake-case `some_camera_control`, for example `autoExposureMode` to `auto_exposure_mode`.\n  - Other controls changed name a bit more, such as `autoWhiteBalance` to `auto_white_balance_temperature`.\n  - See `uvcc controls` for your camera.\n\n### Features\n\n- Uses forked `uvc-control` v2, as breaking bug fixes were not reviewed (not commented, accepted, nor rejected) in time for this release ([uvc-control#64](https://github.com/makenai/node-uvc-control/pull/64)).\n  - If the equivalent changes are made, `uvcc` can go back to using the upstream.\n  - Below feature changes are a mix of changes in `uvc-control` and `uvcc`.\n- Should support additional cameras and camera controls by `uvc-control` dynamically mapping camera controls.\n  - Both `uvc-control` and `uvcc` were developed testing (only?) against Logitech C920 cameras.\n  - Several users tested previews/manual patches using other cameras ([#4](https://github.com/joelpurra/uvcc/issues/4)).\n  - Further changes have only been confirmed using Logitech C920.\n- If a UVC camera is available, it will be autodetected by `uvc-control` using `node-usb`.\n  - Most users will not need to run `uvcc devices` to find and configure their camera.\n  - Uses the \"first\" camera, which may depend on the system, drivers, and in which port the cameras are plugged in.\n  - If necessary, the vendor/product can still be configured as before.\n- If multiple cameras with the same vendor/product are available, it is possible to distinguish between them using `--address`.\n  - Can also be configured using environment variables or configuration files.\n  - See output from `uvcc devices`.\n- Should work on Linux, by changing how `uvc-control` targets the USB device ([uvc-control#58](https://github.com/makenai/node-uvc-control/issues/58)).\n  - Might need to use `sudo uvcc devices` to access and filter the full list of USB devices.\n  - Might need to set up userspace `/dev` (`udev`) rules or equivalent to further get/set camera control values.\n\n### Other changes\n\n- d6b4700 Add example output from Logitech C920\n- 80848a6 Make device address configurable\n- 97a34d0 Make vendor/product ids optional\n- 7b334fa Fix devices command\n- b6c191f Target uvc-control v2\n\n## v1.0.2\n\n- 51e824c Add `find-up`\n\n## v1.0.1\n\n- a4eb66f Use file-relative path to file in the `uvc-control` package\n\n## v1.0.0\n\n- 047980e Initial public release\n- Thanks you [Pawel Szymczykowski](http://twitter.com/makenai) for [uvc-control](https://github.com/makenai/node-uvc-control) for node.js. Without his code I would never have gotten close to automating — or perhaps even being _able_ to — changing camera controls on macOS.\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "DEVELOP.md",
    "content": "# [`uvcc`](https://joelpurra.com/projects/uvcc/) development\n\nGet the source code from the [`uvcc` repository](https://github.com/joelpurra/uvcc).\n\nFollow [git-flow](https://danielkummer.github.io/git-flow-cheatsheet/) and use [git-flow-avh](https://github.com/petervanderdoes/gitflow-avh).\n\n```shell\n# Make sure git-flow is initialized.\ngit flow init -d\n\n# Fetch dependencies.\nnpm install\n\n# Get a fresh local build.\nnpm run --silent rebuild\n\n# Make sure tests pass.\nnpm run --silent test\n\n# Try some commands on your local build.\nnode ./dist/index.js\n\nnode ./dist/index.js controls\n\nnode ./dist/index.js ranges\n\nnode ./dist/index.js export\n\nnode ./dist/index.js get absolute_zoom\n\nnode ./dist/index.js set absolute_zoom 120\n\n# Start debugging.\n# Use the Node.js inspector built-in to Chromium-based browsers.\nnpm run --silent debug:run:break\n\n# Use -- to separate the npm command from uvcc arguments.\nnpm run --silent debug:run:break -- export\n```\n\n## Todo\n\n- Check [open issues and pull requests](https://github.com/joelpurra/uvcc/issues?q=is%3Aopen) and see what can be done.\n- Add tests.\n- Add output examples from additional camera models.\n  - Perhaps create and record a demo video/gif for that model.\n- Add workarounds for cameras with known issues.\n  - Some cameras are known to have issues in other implementations.\n  - Avoid camera- or system-specific workarounds, try to be generic in their detection and prevention.\n  - See [Linux UVC device drivers](https://www.ideasonboard.org/uvc/)'s supported devices list for examples.\n- Compare UVC controls/values with the output from [`v4l2-ctl`](https://www.mankier.com/1/v4l2-ctl).\n  - `v4l2-ctl --list-devices`\n  - `v4l2-ctl --list-ctrls`\n  - See for example the article [Manual USB camera settings in Linux](http://kurokesu.com/main/2016/01/16/manual-usb-camera-settings-in-linux/).\n\n## See also\n\n- The lower-level UVC Node.js library [uvc-control](https://github.com/makenai/node-uvc-control) used by `uvcc`.\n- The even lower level library [`libusb`](http://libusb.info/) ([Wikipedia](https://en.wikipedia.org/wiki/Libusb)) through the [npm package `usb`](https://www.npmjs.com/package/usb).\n- The [`v4l-utils`](https://linuxtv.org/wiki/index.php/V4l-utils) for [video4linux](https://www.linuxtv.org) ([Wikipedia](https://en.wikipedia.org/wiki/Video4Linux)), which includes [`v4l2-ctl`](https://www.mankier.com/1/v4l2-ctl).\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\">\n  <a href=\"https://files.joelpurra.com/projects/uvcc/demo/2020-09-02/uvcc-demo.2020-09-02.mp4\"><img src=\"https://files.joelpurra.com/projects/uvcc/demo/2020-09-02/uvcc-demo.2020-09-02.gif\" alt=\"uvcc demo video showing rubber ducks and a candle with varying camera settings\" width=\"480\" height=\"270\" border=\"0\" /></a>\n</p>\n<h1 align=\"center\">\n  <a href=\"https://joelpurra.com/projects/uvcc/\">uvcc</a>\n</h1>\n<p align=\"center\">\n  <a href=\"https://en.wikipedia.org/wiki/USB_video_device_class\">USB Video Class</a> (UVC) device configurator\n</p>\n\n## Overview\n\n- Fine-tune camera controls on the fly, such as brightness, contrast, saturation, gain, white balance/color temperature, zoom.\n- Export/import of settings makes it easy to reliably configure one or more cameras for various situations.\n- Command line interface (CLI) with JSON input/output for automation and repeatability.\n\n## Compatible cameras\n\n- [Elgato Facecam](https://www.elgato.com/facecam) ([4057:0120](./examples/elgato-facecam/4057-120/))\n- [Logitech C920 HD Pro Webcam](https://www.logitech.com/en-us/products/webcams/c920s-pro-hd-webcam.html) ([1133:2093](./examples/logitech-c920/1133-2093/))\n- [Logitech C922 Pro Stream Webcam](https://www.logitech.com/en-us/products/webcams/c922-pro-stream-webcam.html) ([1133:2140](./examples/logitech-c922/1133-2140/))\n- [Microsoft LifeCam Studio](https://www.microsoft.com/en-WW/accessories/products/webcams/lifecam-studio) Model 1425 ([1118:1906](./examples/microsoft-1425/1118-1906/), [1118:2065](./examples/microsoft-1425/1118-2065/))\n- Hopefully other [UVC-compatible webcams and digital camcorders](https://en.wikipedia.org/wiki/List_of_USB_video_class_devices).\n\n### Do you have another UVC-compatible camera?\n\n- Add it to the [`./examples/`](./examples/).\n- Is it not working?\n  - [Report an issue.](https://github.com/joelpurra/uvcc/issues?q=is%3Aopen)\n  - [Help fix the source code!](./DEVELOP.md)\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) (`node` and `npm` commands). Published on npm as [`uvcc`](https://www.npmjs.com/package/uvcc).\n\n```shell\nnpm install --global uvcc\n```\n\nOr use [`npx`](https://www.npmjs.com/package/npx) to execute with `npx uvcc`.\n\nOn Linux, you may need to [change device access permissions](./USAGE.md#linux).\n\n## Features\n\n- List available UVC cameras and camera controls.\n- Get/set individual camera controls.\n- Export/import full JSON control snapshots using `stdout`/`stdin`.\n- Per-user/per-directory/custom configuration files to handle multiple cameras.\n\n## Short usage example\n\nFirst start a program which shows a camera preview, such as Photo Booth on macOS or Cheese on Linux.\n\n```shell\n# Display commands and options.\nuvcc --help\n\n# Export current configuration. You can save it to a file, modify, and import later.\nuvcc export\n\n# Turn off automatic white balance to manually set the white balance.\nuvcc set auto_white_balance_temperature 0\n\n# Set the white balance temperature to 2000.\n# NOTE: the white_balance_temperature range for Logitech C920 is 2000-6500.\nuvcc set white_balance_temperature 2000\n\n# Set the contrast to 192.\n# NOTE: the contrast range for Logitech C920 is 0-255, default value 128.\nuvcc set contrast 192\n```\n\n## See also\n\n- Further help and configuration in [USAGE.md](./USAGE.md).\n- The [./examples/](./examples/) directory for some sample output.\n- The [CHANGELOG.md](./CHANGELOG.md), in particular for breaking changes.\n- Read [DEVELOP.md](./DEVELOP.md) to submit a patch or add your camera output to the examples.\n- [USB Video Class](https://en.wikipedia.org/wiki/USB_video_device_class) and [list of USB video class devices](https://en.wikipedia.org/wiki/List_of_USB_video_class_devices) on Wikipedia.\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "USAGE.md",
    "content": "# [`uvcc`](https://joelpurra.com/projects/uvcc/) usage\n\nBy default, the first detected UVC camera will be used. See [configuration](#configuration) to target a specific camera. Note that [many cameras are not UVC-compatible](https://en.wikipedia.org/wiki/List_of_USB_video_class_devices).\n\n```shell\nuvcc --help\n```\n\n```text\nuvcc: USB Video Class (UVC) device configurator for the command line (CLI). Used for webcams, camcorders, etcetera.\n\nCommands:\n  uvcc get <control>                    Get current control value.\n  uvcc set <control> <value1> [value2]  Set control value(s).\n  uvcc range <control>                  Get possible range (min and max) for a control.\n  uvcc ranges                           Get all ranges (min and max).\n  uvcc devices                          List connected UVC devices.\n  uvcc controls                         List all supported controls for the camera.\n  uvcc export                           Output configuration in JSON format, on stdout.\n  uvcc import                           Input configuration in JSON format, from stdin.\n\nDevice selection for multi-camera setups.\n  Numbers in hex (0x000) or decimal (0000) format.\n  --vendor   Camera vendor id (vId).  [number] [default: 0]\n  --product  Camera product id (pId).  [number] [default: 0]\n  --address  Camera device address.  [number] [default: 0]\n\nOptions:\n  --version  Show version number  [boolean]\n  --config   Load command arguments from a JSON file.\n  --verbose  Enable verbose output.  [boolean] [default: false]\n  --help     Show help  [boolean]\n\nExamples:\n\n  Basic usage:\n  uvcc controls                                    Available controls for the camera.\n  uvcc set auto_white_balance_temperature 0        Turn off automatic color correction.\n  uvcc set saturation 64                           Low color saturation (near grayscale).\n  uvcc ranges                                      List possible control ranges.\n  uvcc set absolute_zoom 200                       Zoom in.\n\n  Automate config:\n  - Not all controls can be imported.\n  - Control order matters.\n  uvcc export > my-uvcc-export.json                Save to file.\n  cat my-uvcc-export.json | uvcc import            Load from file.\n\n  Target a specific device:\n  - Only useful for multi-camera setups.\n  - For same-model cameras, also specify address.\n  - Alt. use system USB settings to find devices.\n  uvcc devices                                     List available cameras.\n  sudo uvcc devices                                Avoid LIBUSB_ERROR_ACCESS.\n  uvcc --vendor 0x46d --product 0x82d export\n\nuvcc Copyright © 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it\nunder certain conditions. See GPL-3.0 license for details.\n\nSee also: https://joelpurra.com/projects/uvcc/\n```\n\n## Configuration\n\nThe command line arguments can optionally be provided using environment variables, implicit per-user/per-directory configuration files, or explicitly loaded from JSON files.\n\n### Command line\n\n```shell\n# Find your UVC device, note the vendor id (vId) and product id (pId).\n# The ids can be in hexadecimal (0x000) or decimal (0000) format.\n# Example:\n# - The vendor is Logitech (hexadecimal 0x46d, or decimal 1133).\n# - The product is C920 HD Pro Webcam (hexadecimal 0x82d, or decimal 2093).\n# NOTE: listing USB devices might require root (sudo) on some systems.\nuvcc devices\n\n# Use the vendor id and product id to export current configuration.\n# NOTE: explicitly defining vendor/product is usually not necessary.\nuvcc --vendor 0x46d --product 0x82d export\n```\n\n### Environment variables\n\nSet `UVCC_<argument name>`.\n\n```shell\nUVCC_VERBOSE=true uvcc controls\n```\n\n### Configuration file format\n\nConfiguration files for `uvcc` are in JSON format. If you configure the same camera each time, it is convenient to put `vendor` and `product` in the configuration file.\n\n```json\n{\n  \"vendor\": 1133,\n  \"product\": 2093\n}\n```\n\n### Implicit configuration file\n\nYou can put any command line arguments as properties in a JSON file called either `.uvccrc` or `.uvccrc.json`. The file is loaded from the same directory as `uvcc` is executed in, or the nearest parent directory where it can be found. A convenient location might be your `$HOME` directory.\n\n### Explicit configuration file\n\nInstead of passing command line arguments one by one, an explicit configuration file can be used. Explicitly defining a configuration file will prevent loading of the implicit configuration files.\n\n```shell\nuvcc --config <my-uvcc-config.json>\n```\n\n## Examples\n\nSee additional output examples in [./examples/](./examples/).\n\n### Exported configuration\n\n- Save the exported JSON data to a file as a snapshot of the current camera settings using `uvcc export > my-export.json`.\n- The export format is made to be imported again using `cat my-export.json | uvcc import`.\n- Note that some values are read-only, and are thus not exported.\n- Note that the order of the imported values matters, as for example automatic white balance needs to be turned off before setting a custom white balance.\n\n```shell\nuvcc export\n```\n\n```json\n{\n  \"absolute_pan_tilt\": 0,\n  \"absolute_zoom\": 100,\n  \"auto_exposure_mode\": 8,\n  \"auto_exposure_priority\": 1,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"backlight_compensation\": 0,\n  \"brightness\": 128,\n  \"contrast\": 128,\n  \"gain\": 28,\n  \"power_line_frequency\": 2,\n  \"saturation\": 128,\n  \"sharpness\": 128,\n  \"white_balance_temperature\": 4675\n}\n```\n\n## System-specific details\n\n### Linux\n\nUser access to hardware devices, such as USB cameras, may be restricted by default on Linux. If, for example, `sudo uvcc devices` lists your camera but `uvcc devices` (without `sudo`) does not, then for ease-of-use you may adjust the device access level.\n\nBelow [userspace `/dev`](https://en.wikipedia.org/wiki/Udev) (`udev`) is used to change the access level for a specific device model. Note that relaxing the access level in this way reduces device security.\n\n1. Find your camera model's vendor and product id using, for example, [`lsusb`](https://en.wikipedia.org/wiki/Lspci#lsusb).\n\n   ```shell\n   lsusb\n   ```\n\n   Example output for Logitech (vendor id `046d`) C920 HD Pro Webcam (product id `082d`).\n\n   ```shell\n   Bus 005 Device 013: ID 046d:082d Logitech, Inc. HD Pro Webcam C920\n   ```\n\n1. Create a new `udev` rules file for your UVC camera using your favorite text editor.\n\n   ```shell\n   sudo nano /etc/udev/rules.d/90-uvc-camera.rules\n   ```\n\n1. Add one line for your device by vendor and product id, replacing `046d` and `082d` with the ids for your camera.\n\n   ```text\n   SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"046d\", ATTRS{idProduct}==\"082d\", TAG+=\"uaccess\"\n   ```\n\n   If you have more than one camera model, just add more lines.\n\n1. Reload the device rules files after editing, and apply the changes.\n\n   ```shell\n   sudo udevadm control --reload-rules\n   sudo udevadm trigger --action='change'\n   ```\n\n1. Unplug your camera and plug it back in.\n1. Try `uvcc devices` (without `sudo`) and check if your camera is listed.\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "examples/README.md",
    "content": "# [`uvcc`](https://joelpurra.com/projects/uvcc/) output examples\n\nA small sample of `uvcc` camera control output. See individual subdirectories for specific cameras. Note that [cameras with the same \"marketing name\" may have several USB hardware implementations with different vendor/product ids](https://github.com/joelpurra/uvcc/issues/21), so there may be more than one subdirectory.\n\n## How to add or update the output from your camera\n\n- Open the terminal.\n- Create and/or enter the correct camera product marketing name subdirectory.\n  - The \"marketing name\" is the product name (usually including a short codename) you would see on the box when you buy a camera.\n  - Use [kebab-case](https://en.wikipedia.org/wiki/Kebab_case) naming, with vendor name and product code/name.\n  - Do not use the full \"marketing name\", such as \"Logitech HD Pro Webcam C920\".\n  - Correct examples:\n    - [`logitech-c920`](./logitech-c920/) from `Logitech HD Pro Webcam C920` (`name` in `uvcc devices`).\n    - [`logitech-c922`](./logitech-c922/) from the vendor name and `C922 Pro Stream Webcam` (`name` in `uvcc devices`).\n    - [`microsoft-1425`](./microsoft-1425/) from the vendor name and the model number `1425` found on the label on the camera cable as well as the box the camera was delivered in.\n- Create and/or enter the correct vendor/product id subdirectory.\n  - This is due to [cameras with the same \"marketing name\" having different USB product ids](https://github.com/joelpurra/uvcc/issues/21), and this possibly having different hardware properties.\n  - Use the format `<vendor id>-<product id>` with decimal number formatting, without leading zero padding.\n  - You can find the USB `vendor` and `product` ids in the output of `uvcc devices`.\n  - Correct examples:\n    - [`logitech-c920/1133-2093`](./logitech-c920/1133-2093/)\n    - [`logitech-c922/1133-2140`](./logitech-c920/1133-2140/)\n    - [`microsoft-1425/1118-1906`](./microsoft-1425/1118-1906/)\n    - [`microsoft-1425/1118-2065`](./microsoft-1425/1118-2065/)\n- Reset the camera to default values.\n  - Unplug all cameras.\n  - Reconnect only the camera you want to test.\n  - This done to get \"fresh\" (hopefully default) values for `uvcc export`.\n- Run [`../../update-example.sh`](./update-example.sh)\n- Verify that the `*.json` files were created/updated.\n- Commit your changes and [submit a pull request](https://github.com/joelpurra/uvcc/compare).\n\n## Is it not working?\n\nNot all cameras are [UVC-compatible](https://en.wikipedia.org/wiki/List_of_USB_video_class_devices). If you can confirm that your camera model supports UVC, perhaps `uvcc` needs some fixes to support it.\n\n- [Report the issue](https://github.com/joelpurra/uvcc/issues?q=is%3Aopen) with as much detail as you can.\n- [Fix the source code](../DEVELOP.md) directly, since it is much easier debugging with access to the camera itself.\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "examples/elgato-facecam/4057-120/controls.json",
    "content": "[\n  \"absolute_exposure_time\",\n  \"absolute_zoom\",\n  \"auto_exposure_mode\",\n  \"auto_white_balance_temperature\",\n  \"brightness\",\n  \"contrast\",\n  \"power_line_frequency\",\n  \"saturation\",\n  \"sharpness\",\n  \"white_balance_temperature\"\n]\n"
  },
  {
    "path": "examples/elgato-facecam/4057-120/devices.json",
    "content": "[\n  {\n    \"name\": \"Elgato Facecam\",\n    \"vendor\": 4057,\n    \"product\": 120,\n    \"address\": 5\n  }\n]\n"
  },
  {
    "path": "examples/elgato-facecam/4057-120/export.json",
    "content": "{\n  \"absolute_exposure_time\": 156,\n  \"absolute_zoom\": 1,\n  \"auto_exposure_mode\": 2,\n  \"auto_white_balance_temperature\": 1,\n  \"brightness\": 88,\n  \"contrast\": 4,\n  \"power_line_frequency\": 2,\n  \"saturation\": 37,\n  \"sharpness\": 3,\n  \"white_balance_temperature\": 2800\n}\n"
  },
  {
    "path": "examples/elgato-facecam/4057-120/metadata.json",
    "content": "{\n  \"node\": \"v18.12.1\",\n  \"npm\": \"8.19.2\",\n  \"uname\": \"Linux dooderson-ThinkPad-T490 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\",\n  \"uvcc\": \"v6.0.0\"\n}\n"
  },
  {
    "path": "examples/elgato-facecam/4057-120/ranges.json",
    "content": "{\n  \"absolute_exposure_time\": {\n    \"min\": 1,\n    \"max\": 2500\n  },\n  \"absolute_zoom\": {\n    \"min\": 1,\n    \"max\": 31\n  },\n  \"brightness\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"contrast\": {\n    \"min\": 0,\n    \"max\": 10\n  },\n  \"saturation\": {\n    \"min\": 0,\n    \"max\": 63\n  },\n  \"sharpness\": {\n    \"min\": 0,\n    \"max\": 4\n  },\n  \"white_balance_temperature\": {\n    \"min\": 2800,\n    \"max\": 12500\n  }\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/controls.json",
    "content": "[\n  \"absolute_exposure_time\",\n  \"absolute_focus\",\n  \"absolute_pan_tilt\",\n  \"absolute_zoom\",\n  \"auto_exposure_mode\",\n  \"auto_exposure_priority\",\n  \"auto_focus\",\n  \"auto_white_balance_temperature\",\n  \"backlight_compensation\",\n  \"brightness\",\n  \"contrast\",\n  \"gain\",\n  \"power_line_frequency\",\n  \"saturation\",\n  \"sharpness\",\n  \"white_balance_temperature\"\n]\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/.gitignore",
    "content": "recording/\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/README.md",
    "content": "# [`uvcc`](https://joelpurra.com/projects/uvcc/) demo recording\n\nScripted (repeatable) demo recording showcasing `uvcc` capabilities.\n\n- This is a development tool.\n  - Requires additional software to function.\n  - Does not have usage documentation.\n  - The output is intended for the project `README.md`.\n- Written specifically for Logitech C920.\n  - Uses a mix of imported `*.json` files and direct `uvcc set`.\n  - Not expected to, but might, work with other cameras.\n- Rubber ducks?\n  - The rubber ducks used in the (initial) demo video are used for [rubber duck debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging).\n  - They are also mascots for [joelpurra's stream on Twitch](https://www.twitch.tv/joelpurra).\n\n---\n\n[`uvcc`](https://joelpurra.com/projects/uvcc/) Copyright &copy; 2018, 2019, 2020, 2021, 2022 [Joel Purra](https://joelpurra.com/). Released under [GNU General Public License version 3.0 (GPL-3.0)](https://www.gnu.org/licenses/gpl.html). [Your donations are appreciated!](https://joelpurra.com/donate/)\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/auto.json",
    "content": "{\n  \"absolute_pan_tilt\": [\n    0,\n    0\n  ],\n  \"absolute_zoom\": 100,\n  \"auto_exposure_mode\": 8,\n  \"auto_exposure_priority\": 1,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"brightness\": 128,\n  \"contrast\": 128,\n  \"gain\": 128,\n  \"saturation\": 128,\n  \"sharpness\": 128\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/cold.json",
    "content": "{\n  \"auto_white_balance_temperature\": 0,\n  \"white_balance_temperature\": 2000\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/crazy.json",
    "content": "{\n  \"absolute_zoom\": 500,\n  \"auto_exposure_mode\": 1,\n  \"auto_focus\": 0,\n  \"auto_white_balance_temperature\": 0,\n  \"brightness\": 255,\n  \"contrast\": 0,\n  \"gain\": 255,\n  \"saturation\": 255,\n  \"sharpness\": 255,\n  \"white_balance_temperature\": 2000\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/record-demo.sh",
    "content": "#!/usr/bin/env bash\n\nset -o errexit\nset -o noclobber\nset -o nounset\nset -o pipefail\n\nfunction die() {\n\techo \"FATAL:\" \"$@\" >&2\n\texit 1\n}\n\nfunction changeOverlayTextAsync() {\n\t# NOTE: don't wait for zmqsend, even if it usually is quick.\n\techo \"drawtext reinit 'text=${@}\" | zmqsend &\n}\n\n[[ -x \"$(which node)\" ]] || die 'Could not find ffmpeg executable in $PATH.' 'https://nodejs.org/'\n[[ -x \"$(which ffmpeg)\" ]] || die 'Could not find ffmpeg executable in $PATH.' 'https://ffmpeg.org/'\n[[ -x \"$(which gifski)\" ]] || die 'Could not find gifski executable in $PATH.' 'https://gif.ski/'\n\ndeclare -r SCRIPT_BASE=\"${BASH_SOURCE%/*}\"\ndeclare SCRIPT_BASE_ABSOLUTE\nSCRIPT_BASE_ABSOLUTE=\"$(realpath \"$SCRIPT_BASE\")\"\n\n# NOTE: using the local repository version of uvcc, with any local (even uncommitted) changes.\ndeclare UVCC_INDEX\nUVCC_INDEX=\"$(realpath \"${SCRIPT_BASE_ABSOLUTE}/../../../../dist/index.js\")\"\n\ndeclare -r UVCC=\"node -- ${UVCC_INDEX}\"\n\nmkdir -p './recording/'\n\nset -x\n\n# NOTE: requires\n#  - ffmpeg compiled with --enable-libzmq\n#  - zmqsend from the ffmpeg repository\n# http://www.ffmpeg-archive.org/how-to-build-tools-zmqsend-td4686430.html\n# https://raspberrypi.stackexchange.com/questions/93786/ffmpeg-doesnt-have-tools-zmqsend\ncoproc 'RECORDER' {\n\tffmpeg \\\n\t\t-hide_banner \\\n\t\t-loglevel 'error' \\\n\t\t-f 'v4l2' \\\n\t\t-framerate '24' \\\n\t\t-video_size '1280x720' \\\n\t\t-input_format 'h264' \\\n\t\t-i /dev/video0 \\\n\t\t-ss '2' \\\n\t\t-an \\\n\t\t-sn \\\n\t\t-vf \"\n\t\t\tzmq='',\n\t\t\tscale=sws_flags=spline+accurate_rnd:out_range=tv,\n\t\t\tdrawbox='y=(ih/5):color=black@0.3:width=iw:height=(ih/6):t=fill',\n\t\t\tdrawtext='fontsize=(h/8):fontcolor=black:x=((w-tw)/2):y=(h/5)+(h/36):text=auto.json'\n\t\t\" \\\n\t\t-c:v 'libx264' \\\n\t\t-colorspace 'bt709' \\\n\t\t-color_trc 'bt709' \\\n\t\t-color_primaries 'bt709' \\\n\t\t-color_range 'tv' \\\n\t\t-pix_fmt 'yuv420p' \\\n\t\t-f 'mp4' \\\n\t\t-y \\\n\t\t'./recording/uvcc-demo.mp4'\n\t}\n\n# NOTE: setting -ss '2' to skip the first two seconds of video, to let the camera autoadjust to current lighting conditions.\nsleep 2\n\nchangeOverlayTextAsync 'auto.json'\ncat 'auto.json' | $UVCC import\n\nsleep 5\n\nchangeOverlayTextAsync 'warm.json'\ncat 'warm.json' | $UVCC import\n\nsleep 3\n\nchangeOverlayTextAsync 'cold.json'\ncat 'cold.json' | $UVCC import\n\nsleep 3\n\nchangeOverlayTextAsync 'zoom in, pan/tilt'\n$UVCC set absolute_zoom 500\n\nsleep 1\n\n# TODO: could be smoother by adding more steps.\n$UVCC set absolute_pan_tilt -18000 -18000\n$UVCC set absolute_pan_tilt -36000 -36000\nsleep 0.6\n$UVCC set absolute_pan_tilt -18000 -36000\n$UVCC set absolute_pan_tilt 0 -36000\n$UVCC set absolute_pan_tilt 18000 -36000\n$UVCC set absolute_pan_tilt 36000 -36000\nsleep 0.6\n$UVCC set absolute_pan_tilt 18000 -36000\n$UVCC set absolute_pan_tilt 0 -36000\n\nsleep 1\n\nchangeOverlayTextAsync 'crazy.json'\ncat 'crazy.json' | $UVCC import\n\nsleep 4\n\n# TODO: generate the json for these steps and import, instead of individual step commands.\nchangeOverlayTextAsync 'stepwise color changes'\n$UVCC set brightness 200\n$UVCC set saturation 200\n$UVCC set sharpness 200\n$UVCC set gain 200\n\nsleep 0.5\n\n$UVCC set brightness 150\n$UVCC set saturation 150\n$UVCC set sharpness 150\n$UVCC set gain 150\n\nsleep 0.5\n\n$UVCC set brightness 100\n$UVCC set saturation 100\n$UVCC set sharpness 100\n$UVCC set gain 100\n\nsleep 0.5\n\n$UVCC set brightness 50\n$UVCC set saturation 50\n$UVCC set sharpness 50\n# $UVCC set gain 50\n\nsleep 0.5\n\n# $UVCC set brightness 0\n$UVCC set saturation 0\n$UVCC set sharpness 0\n# $UVCC set gain 0\n\nsleep 2\n\n# NOTE: hardcoded range because dynamically the current absolute_zoom value to get a\n# starting point isn't really reliable, as it depends on camera image output size.\nfor absolute_zoom in {150..100};\ndo\n\t$UVCC set absolute_zoom \"$absolute_zoom\"\ndone\n\n# NOTE: the video is made to loop, so going back to auto.json at the end.\nchangeOverlayTextAsync 'auto.json'\ncat 'auto.json' | $UVCC import\n\nsleep 3\n\n# NOTE: emulate ffmpeg \"q\" (quit) keyboard key press.\necho -n 'q' >& \"${RECORDER[1]}\"\n\n# NOTE: wait for ffmpeg to finish writing the video.\nwait \"${RECORDER_PID}\"\n\n# https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/\n# https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality\n# ffmpeg -hide_banner -loglevel 'error' -i './recording/uvcc-demo.mp4' -filter_complex \"[0:v] fps=4,scale=480:-2:flags=lanczos,split [a][b];[a] palettegen=stats_mode=diff [p];[b][p] paletteuse\" -vsync '0' -loop '0' -y './recording/uvcc-demo.gif'\n\n# https://gif.ski/\nfind ./recording -iname 'demo-*.png' -delete\nffmpeg -hide_banner -loglevel 'error' -i './recording/uvcc-demo.mp4' -vf \"fps='4'\" './recording/demo-%04d.png'\nfind ./recording -iname 'demo-*.png' -print0 | xargs -0 gifski --fps '4' --width '480' --quality '25' --output './recording/uvcc-demo.gif'\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/demo/warm.json",
    "content": "{\n  \"auto_white_balance_temperature\": 0,\n  \"white_balance_temperature\": 6500\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/devices.json",
    "content": "[\n  {\n    \"name\": \"HD Pro Webcam C920\",\n    \"vendor\": 1133,\n    \"product\": 2093,\n    \"address\": 66\n  }\n]\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/export.json",
    "content": "{\n  \"absolute_exposure_time\": 333,\n  \"absolute_focus\": 0,\n  \"absolute_pan_tilt\": [\n    0,\n    0\n  ],\n  \"absolute_zoom\": 100,\n  \"auto_exposure_mode\": 8,\n  \"auto_exposure_priority\": 1,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"backlight_compensation\": 0,\n  \"brightness\": 128,\n  \"contrast\": 128,\n  \"gain\": 97,\n  \"power_line_frequency\": 2,\n  \"saturation\": 128,\n  \"sharpness\": 128,\n  \"white_balance_temperature\": 4852\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/metadata.json",
    "content": "{\n  \"node\": \"v18.1.0\",\n  \"npm\": \"8.8.0\",\n  \"uname\": \"Linux compendious 5.15.0-27-generic #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\",\n  \"uvcc\": \"v6.0.0\"\n}\n"
  },
  {
    "path": "examples/logitech-c920/1133-2093/ranges.json",
    "content": "{\n  \"absolute_exposure_time\": {\n    \"min\": 3,\n    \"max\": 2047\n  },\n  \"absolute_focus\": {\n    \"min\": 0,\n    \"max\": 250\n  },\n  \"absolute_pan_tilt\": {\n    \"min\": [\n      -36000,\n      -36000\n    ],\n    \"max\": [\n      36000,\n      36000\n    ]\n  },\n  \"absolute_zoom\": {\n    \"min\": 100,\n    \"max\": 500\n  },\n  \"backlight_compensation\": {\n    \"min\": 0,\n    \"max\": 1\n  },\n  \"brightness\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"contrast\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"gain\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"saturation\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"sharpness\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"white_balance_temperature\": {\n    \"min\": 2000,\n    \"max\": 6500\n  }\n}\n"
  },
  {
    "path": "examples/logitech-c922/1133-2140/controls.json",
    "content": "[\n  \"absolute_exposure_time\",\n  \"absolute_focus\",\n  \"absolute_pan_tilt\",\n  \"absolute_zoom\",\n  \"auto_exposure_mode\",\n  \"auto_exposure_priority\",\n  \"auto_focus\",\n  \"auto_white_balance_temperature\",\n  \"backlight_compensation\",\n  \"brightness\",\n  \"contrast\",\n  \"gain\",\n  \"power_line_frequency\",\n  \"saturation\",\n  \"sharpness\",\n  \"white_balance_temperature\"\n]\n"
  },
  {
    "path": "examples/logitech-c922/1133-2140/devices.json",
    "content": "[\n  {\n    \"name\": \"C922 Pro Stream Webcam\",\n    \"vendor\": 1133,\n    \"product\": 2140,\n    \"address\": 43\n  }\n]\n"
  },
  {
    "path": "examples/logitech-c922/1133-2140/export.json",
    "content": "{\n  \"absolute_exposure_time\": 250,\n  \"absolute_focus\": 0,\n  \"absolute_pan_tilt\": [\n    0,\n    0\n  ],\n  \"absolute_zoom\": 100,\n  \"auto_exposure_mode\": 8,\n  \"auto_exposure_priority\": 1,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"backlight_compensation\": 0,\n  \"brightness\": 128,\n  \"contrast\": 128,\n  \"gain\": 0,\n  \"power_line_frequency\": 2,\n  \"saturation\": 128,\n  \"sharpness\": 128,\n  \"white_balance_temperature\": 4000\n}\n"
  },
  {
    "path": "examples/logitech-c922/1133-2140/metadata.json",
    "content": "{\n  \"node\": \"v18.1.0\",\n  \"npm\": \"8.8.0\",\n  \"uname\": \"Linux compendious 5.15.0-27-generic #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\",\n  \"uvcc\": \"v6.0.0\"\n}\n"
  },
  {
    "path": "examples/logitech-c922/1133-2140/ranges.json",
    "content": "{\n  \"absolute_exposure_time\": {\n    \"min\": 3,\n    \"max\": 2047\n  },\n  \"absolute_focus\": {\n    \"min\": 0,\n    \"max\": 250\n  },\n  \"absolute_pan_tilt\": {\n    \"min\": [\n      -36000,\n      -36000\n    ],\n    \"max\": [\n      36000,\n      36000\n    ]\n  },\n  \"absolute_zoom\": {\n    \"min\": 100,\n    \"max\": 500\n  },\n  \"backlight_compensation\": {\n    \"min\": 0,\n    \"max\": 1\n  },\n  \"brightness\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"contrast\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"gain\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"saturation\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"sharpness\": {\n    \"min\": 0,\n    \"max\": 255\n  },\n  \"white_balance_temperature\": {\n    \"min\": 2000,\n    \"max\": 6500\n  }\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-1906/controls.json",
    "content": "[\n  \"absolute_exposure_time\",\n  \"absolute_focus\",\n  \"absolute_pan_tilt\",\n  \"absolute_zoom\",\n  \"auto_exposure_mode\",\n  \"auto_focus\",\n  \"auto_white_balance_temperature\",\n  \"backlight_compensation\",\n  \"brightness\",\n  \"contrast\",\n  \"power_line_frequency\",\n  \"saturation\",\n  \"sharpness\",\n  \"white_balance_temperature\"\n]\n"
  },
  {
    "path": "examples/microsoft-1425/1118-1906/devices.json",
    "content": "[\n  {\n    \"name\": \"Microsoft® LifeCam Studio(TM)\",\n    \"vendor\": 1118,\n    \"product\": 1906,\n    \"address\": 28\n  }\n]\n"
  },
  {
    "path": "examples/microsoft-1425/1118-1906/export.json",
    "content": "{\n  \"absolute_exposure_time\": 156,\n  \"absolute_focus\": 0,\n  \"absolute_pan_tilt\": [\n    0,\n    0\n  ],\n  \"absolute_zoom\": 0,\n  \"auto_exposure_mode\": 8,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"backlight_compensation\": 5,\n  \"brightness\": 133,\n  \"contrast\": 5,\n  \"power_line_frequency\": 2,\n  \"saturation\": 103,\n  \"sharpness\": 25,\n  \"white_balance_temperature\": 4500\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-1906/metadata.json",
    "content": "{\n  \"node\": \"v16.6.0\",\n  \"npm\": \"7.20.3\",\n  \"uname\": \"Darwin MacBook-Pro 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64\",\n  \"uvcc\": \"3.0.1\"\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-1906/ranges.json",
    "content": "{\n  \"absolute_exposure_time\": {\n    \"min\": 1,\n    \"max\": 10000\n  },\n  \"absolute_focus\": {\n    \"min\": 0,\n    \"max\": 40\n  },\n  \"absolute_pan_tilt\": {\n    \"min\": [\n      -529200,\n      -432000\n    ],\n    \"max\": [\n      529200,\n      432000\n    ]\n  },\n  \"absolute_zoom\": {\n    \"min\": 0,\n    \"max\": 317\n  },\n  \"backlight_compensation\": {\n    \"min\": 0,\n    \"max\": 10\n  },\n  \"brightness\": {\n    \"min\": 30,\n    \"max\": 255\n  },\n  \"contrast\": {\n    \"min\": 0,\n    \"max\": 10\n  },\n  \"saturation\": {\n    \"min\": 0,\n    \"max\": 200\n  },\n  \"sharpness\": {\n    \"min\": 0,\n    \"max\": 50\n  },\n  \"white_balance_temperature\": {\n    \"min\": 2500,\n    \"max\": 10000\n  }\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-2065/controls.json",
    "content": "[\n  \"absolute_exposure_time\",\n  \"absolute_focus\",\n  \"absolute_pan_tilt\",\n  \"absolute_zoom\",\n  \"auto_exposure_mode\",\n  \"auto_focus\",\n  \"auto_white_balance_temperature\",\n  \"backlight_compensation\",\n  \"brightness\",\n  \"contrast\",\n  \"power_line_frequency\",\n  \"saturation\",\n  \"sharpness\",\n  \"white_balance_temperature\"\n]\n"
  },
  {
    "path": "examples/microsoft-1425/1118-2065/devices.json",
    "content": "[\n  {\n    \"name\": \"Microsoft® LifeCam Studio(TM)\",\n    \"vendor\": 1118,\n    \"product\": 2065,\n    \"address\": 38\n  }\n]\n"
  },
  {
    "path": "examples/microsoft-1425/1118-2065/export.json",
    "content": "{\n  \"absolute_exposure_time\": 156,\n  \"absolute_focus\": 0,\n  \"absolute_pan_tilt\": [\n    0,\n    0\n  ],\n  \"absolute_zoom\": 0,\n  \"auto_exposure_mode\": 8,\n  \"auto_focus\": 1,\n  \"auto_white_balance_temperature\": 1,\n  \"backlight_compensation\": 5,\n  \"brightness\": 133,\n  \"contrast\": 5,\n  \"power_line_frequency\": 2,\n  \"saturation\": 109,\n  \"sharpness\": 25,\n  \"white_balance_temperature\": 6358\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-2065/metadata.json",
    "content": "{\n  \"node\": \"v18.1.0\",\n  \"npm\": \"8.8.0\",\n  \"uname\": \"Linux compendious 5.15.0-27-generic #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\",\n  \"uvcc\": \"v6.0.0\"\n}\n"
  },
  {
    "path": "examples/microsoft-1425/1118-2065/ranges.json",
    "content": "{\n  \"absolute_exposure_time\": {\n    \"min\": 1,\n    \"max\": 10000\n  },\n  \"absolute_focus\": {\n    \"min\": 0,\n    \"max\": 40\n  },\n  \"absolute_pan_tilt\": {\n    \"min\": [\n      -529200,\n      -432000\n    ],\n    \"max\": [\n      529200,\n      432000\n    ]\n  },\n  \"absolute_zoom\": {\n    \"min\": 0,\n    \"max\": 317\n  },\n  \"backlight_compensation\": {\n    \"min\": 0,\n    \"max\": 10\n  },\n  \"brightness\": {\n    \"min\": 30,\n    \"max\": 255\n  },\n  \"contrast\": {\n    \"min\": 0,\n    \"max\": 10\n  },\n  \"saturation\": {\n    \"min\": 0,\n    \"max\": 200\n  },\n  \"sharpness\": {\n    \"min\": 0,\n    \"max\": 50\n  },\n  \"white_balance_temperature\": {\n    \"min\": 2500,\n    \"max\": 10000\n  }\n}\n"
  },
  {
    "path": "examples/update-example.sh",
    "content": "#!/usr/bin/env bash\n\nset -o errexit\nset -o noclobber\nset -o nounset\nset -o pipefail\n\ndeclare -r SCRIPT_BASE=\"${BASH_SOURCE%/*}\"\ndeclare SCRIPT_BASE_ABSOLUTE\nSCRIPT_BASE_ABSOLUTE=\"$(realpath \"$SCRIPT_BASE\")\"\n\ndeclare UVCC_INDEX\nUVCC_INDEX=\"$(realpath \"${SCRIPT_BASE_ABSOLUTE}/../dist/index.js\")\"\n\ndeclare -r UVCC=\"node -- ${UVCC_INDEX}\"\n\nrm -f 'controls.json'\n$UVCC controls > 'controls.json'\n\nrm -f 'devices.json'\n$UVCC devices > 'devices.json'\n\nrm -f 'export.json'\n$UVCC export > 'export.json'\n\nrm -f 'ranges.json'\n$UVCC ranges > 'ranges.json'\n\nrm -f 'metadata.json'\njq \\\n\t--null-input \\\n\t--arg uvcc \"$($UVCC --version)\" \\\n\t--arg node \"$(node --version)\" \\\n\t--arg npm \"$(npm --version)\" \\\n\t--arg uname \"$(uname -a)\" \\\n\t--sort-keys \\\n\t'{\n\t\tuvcc: $uvcc,\n\t\tnode: $node,\n\t\tnpm: $npm,\n\t\tuname: $uname,\n\t}' > 'metadata.json'\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"uvcc\",\n  \"version\": \"7.0.0\",\n  \"description\": \"USB Video Class (UVC) device configurator for the command line (CLI). Used for webcams, camcorders, etcetera.\",\n  \"homepage\": \"https://joelpurra.com/projects/uvcc/\",\n  \"type\": \"module\",\n  \"exports\": \"./dist/index.js\",\n  \"types\": \"./dist/index.d.ts\",\n  \"bin\": {\n    \"uvcc\": \"./dist/index.js\"\n  },\n  \"files\": [\n    \"dist/**/*\"\n  ],\n  \"scripts\": {\n    \"clean\": \"rimraf ./dist/\",\n    \"build\": \"tsc\",\n    \"rebuild\": \"npm run --silent clean && npm run --silent build\",\n    \"build:watch\": \"tsc --watch\",\n    \"debug:run\": \"node --inspect ./dist/index.js\",\n    \"debug:run:break\": \"node --inspect-brk ./dist/index.js\",\n    \"test\": \"npm run --silent lint\",\n    \"lint\": \"npm run --silent lint:xo && npm run --silent lint:prettier && npm run --silent lint:copyright\",\n    \"lint:fix\": \"npm run --silent lint:xo:fix && npm run --silent lint:prettier:fix\",\n    \"lint:copyright\": \"find . -not \\\\( -path './.git/*' -or -path './node_modules/*' -or -path './dist/*' \\\\) -type f \\\\( -iname '*.js' -or -iname '*.ts' \\\\) -print0 | xargs -0 grep -L 'This file is part of uvcc' | sed 's/^/File is missing copyright notice: /'\",\n    \"lint:prettier\": \"prettier --list-different \\\"**/*.json\\\" \\\"**/*.md\\\" || { echo \\\"Prettier needs to format the above files. Try 'npm run --silent lint:fix'.\\\" && exit 1; }\",\n    \"lint:prettier:fix\": \"prettier --write \\\"**/*.json\\\" \\\"**/*.md\\\"\",\n    \"lint:xo\": \"xo\",\n    \"lint:xo:fix\": \"xo --fix\",\n    \"prepublishOnly\": \"git diff-index --exit-code master && npm run --silent rebuild && npm run --silent test\"\n  },\n  \"dependencies\": {\n    \"array-non-uniq\": \"^1.0.0\",\n    \"bluebird\": \"^3.7.2\",\n    \"chalk\": \"^5.2.0\",\n    \"engine-check\": \"^1.0.1\",\n    \"filter-obj\": \"^3.0.0\",\n    \"find-up\": \"^6.3.0\",\n    \"map-obj\": \"^5.0.2\",\n    \"read-pkg-up\": \"^9.1.0\",\n    \"sort-keys\": \"^5.0.0\",\n    \"stream-to-promise\": \"^3.0.0\",\n    \"uvc-control\": \"github:joelpurra/node-uvc-control#v2\",\n    \"yargs\": \"^17.7.1\"\n  },\n  \"devDependencies\": {\n    \"@sindresorhus/tsconfig\": \"^2.0.0\",\n    \"@types/bluebird\": \"^3.5.38\",\n    \"@types/engine-check\": \"^1.1.1\",\n    \"@types/stream-to-promise\": \"^2.2.1\",\n    \"@types/yargs\": \"^17.0.22\",\n    \"eslint-config-joelpurra\": \"github:joelpurra/eslint-config-joelpurra#semver:^v11.0.1\",\n    \"husky\": \"^4.3.8\",\n    \"rimraf\": \"^3.0.2\",\n    \"type-fest\": \"^2.19.0\",\n    \"typescript\": \"^4.9.5\",\n    \"usb\": \"^2.8.0\",\n    \"xo\": \"^0.48.0\"\n  },\n  \"engines\": {\n    \"node\": \"^16.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0\"\n  },\n  \"keywords\": [\n    \"usb\",\n    \"usb video class\",\n    \"uvc\",\n    \"camera\",\n    \"webcam\",\n    \"webcamera\",\n    \"controls\",\n    \"configuration\",\n    \"libusb\",\n    \"libuvc\",\n    \"uvc-control\"\n  ],\n  \"bugs\": {\n    \"url\": \"https://github.com/joelpurra/uvcc/issues\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/joelpurra/uvcc.git\"\n  },\n  \"author\": {\n    \"name\": \"Joel Purra\",\n    \"email\": \"mig@joelpurra.se\",\n    \"url\": \"https://joelpurra.com/\"\n  },\n  \"license\": \"GPL-3.0\",\n  \"husky\": {\n    \"hooks\": {\n      \"pre-commit\": \"npm run --silent test\",\n      \"pre-push\": \"npm run --silent test\"\n    }\n  }\n}\n"
  },
  {
    "path": "src/camera-control-helper-factory.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera, {\n\tUvcControl,\n} from \"uvc-control\";\n\nimport CameraControlHelperClass from \"./camera-control-helper.js\";\n\nexport default class CameraControlHelperFactory {\n\tconstructor(\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly UvcControl: ReadonlyDeep<UvcControl>,\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly CameraControlHelper: typeof CameraControlHelperClass,\n\t) {\n\t\tassert.strictEqual(arguments.length, 2);\n\t\tassert(typeof this.UvcControl === \"function\");\n\t\tassert(typeof this.CameraControlHelper === \"function\");\n\t}\n\n\tasync get(camera: ReadonlyDeep<Camera>): Promise<CameraControlHelperClass> {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof camera === \"object\");\n\n\t\tconst cameraControlHelper = new this.CameraControlHelper(this.UvcControl, camera);\n\n\t\treturn cameraControlHelper;\n\t}\n}\n"
  },
  {
    "path": "src/camera-control-helper.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport arrayNonUniq from \"array-non-uniq\";\nimport filterObject from \"filter-obj\";\nimport assert from \"node:assert\";\nimport sortKeys from \"sort-keys\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera,\n{\n\tCameraControl,\n\tUvcControl,\n} from \"uvc-control\";\n\nimport WrappedError from \"./utilities/wrapped-error.js\";\n\ninterface ControlFlags {\n\treadonly isGettable: boolean;\n\treadonly isRanged: boolean;\n\treadonly isSettable: boolean;\n}\n\ntype ControlsFlags = Record<string, ControlFlags>;\n\nexport default class CameraControlHelper {\n\tprivate cachedMappedSupportedControls: ReadonlyDeep<ControlsFlags> | null = null;\n\n\tconstructor(\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly UvcControl: ReadonlyDeep<UvcControl>,\n\t\tprivate readonly camera: ReadonlyDeep<Camera>,\n\t) {\n\t\tassert.strictEqual(arguments.length, 2);\n\t\tassert(typeof this.UvcControl === \"function\");\n\t\tassert(typeof this.camera === \"object\");\n\t}\n\n\tasync getControlNames(): Promise<readonly string[]> {\n\t\tconst controls = await this.getSupportedControls();\n\n\t\treturn Object.keys(controls);\n\t}\n\n\tasync getGettableControlNames(): Promise<readonly string[]> {\n\t\tconst gettableControls = await this.getGettableControls();\n\n\t\treturn Object.keys(gettableControls);\n\t}\n\n\tasync getRangedControlNames(): Promise<readonly string[]> {\n\t\tconst rangedControls = await this.getRangedControls();\n\n\t\treturn Object.keys(rangedControls);\n\t}\n\n\tasync getSettableControlNames(): Promise<readonly string[]> {\n\t\tconst settableControls = await this.getSettableControls();\n\n\t\treturn Object.keys(settableControls);\n\t}\n\n\tprivate isGettableControl(control: ReadonlyDeep<CameraControl>) {\n\t\t// NOTE: relies on uvc-control internals.\n\t\treturn control.requests.includes(this.UvcControl.REQUEST.GET_CUR);\n\t}\n\n\tprivate isRangedControl(control: ReadonlyDeep<CameraControl>) {\n\t\t// NOTE: relies on uvc-control internals.\n\t\treturn control.requests.includes(this.UvcControl.REQUEST.GET_MIN)\n\t\t\t&& control.requests.includes(this.UvcControl.REQUEST.GET_MAX);\n\t}\n\n\tprivate isSettableControl(control: ReadonlyDeep<CameraControl>) {\n\t\t// NOTE: relies on uvc-control internals.\n\t\treturn control.requests.includes(this.UvcControl.REQUEST.SET_CUR)\n\t\t\t|| (\n\t\t\t\t// TODO: treat optionally settable controls separately?\n\t\t\t\tArray.isArray(control.optional_requests)\n\t\t\t\t&& control.optional_requests.includes(this.UvcControl.REQUEST.SET_CUR)\n\t\t\t);\n\t}\n\n\tprivate async mapSupportedControls() {\n\t\tconst supportedControls = this.camera.supportedControls\n\t\t\t.map((supportedControlName) => this.UvcControl.controls[supportedControlName])\n\t\t\t// TODO: proper ducktyping function.\n\t\t\t.filter((t): t is CameraControl => Boolean(t));\n\n\t\tconst missingControls = supportedControls.filter((control) => !control);\n\n\t\tif (missingControls.length > 0) {\n\t\t\tthrow new Error(`Controls were not found: ${JSON.stringify(missingControls)}`);\n\t\t}\n\n\t\tconst nonUniqueControls = arrayNonUniq(supportedControls);\n\n\t\tif (nonUniqueControls.length > 0) {\n\t\t\tthrow new Error(`Controls were already found: ${JSON.stringify(nonUniqueControls)}`);\n\t\t}\n\n\t\tconst mappedControls = supportedControls.map((control) => {\n\t\t\ttry {\n\t\t\t\tconst uvccControl: [string, ControlFlags] = [\n\t\t\t\t\tcontrol.name,\n\t\t\t\t\t{\n\t\t\t\t\t\t// NOTE: minimal uvcc-specific mapping.\n\t\t\t\t\t\tisGettable: this.isGettableControl(control),\n\t\t\t\t\t\tisRanged: this.isRangedControl(control),\n\t\t\t\t\t\tisSettable: this.isSettableControl(control),\n\t\t\t\t\t},\n\t\t\t\t];\n\n\t\t\t\treturn uvccControl;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst wrappedError = new WrappedError(error, `Could not map control: ${JSON.stringify(control.name)}`);\n\n\t\t\t\t\tthrow wrappedError;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\n\t\tconst controlsObject: ControlsFlags = {};\n\n\t\tfor (const mappedControl of mappedControls) {\n\t\t\tcontrolsObject[mappedControl[0]] = mappedControl[1];\n\t\t}\n\n\t\tconst sortedControls = sortKeys(controlsObject);\n\n\t\treturn sortedControls;\n\t}\n\n\tprivate async getSupportedControls() {\n\t\tif (this.cachedMappedSupportedControls === null) {\n\t\t\tthis.cachedMappedSupportedControls = await this.mapSupportedControls();\n\t\t}\n\n\t\treturn this.cachedMappedSupportedControls;\n\t}\n\n\tprivate async getGettableControls() {\n\t\tconst controls = await this.getSupportedControls();\n\n\t\treturn filterObject(controls, (_key, control) => control.isGettable);\n\t}\n\n\tprivate async getRangedControls() {\n\t\tconst controls = await this.getSupportedControls();\n\n\t\treturn filterObject(controls, (_key, control) => control.isRanged);\n\t}\n\n\tprivate async getSettableControls() {\n\t\tconst controls = await this.getSupportedControls();\n\n\t\treturn filterObject(controls, (_key, control) => control.isSettable);\n\t}\n}\n"
  },
  {
    "path": "src/camera-factory.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera, {\n\tConstructorOptions,\n\tUvcControl,\n} from \"uvc-control\";\n\nimport Output from \"./output.js\";\nimport toFormattedHex from \"./utilities/to-formatted-hex.js\";\nimport WrappedError from \"./utilities/wrapped-error.js\";\n\ninterface GetFunctionArguments {\n\taddress: number | null;\n\tproduct: number | null;\n\tvendor: number | null;\n}\n\nexport default class CameraFactory {\n\tconstructor(\n\t\tprivate readonly output: Output,\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly UvcControl: UvcControl,\n\t) {\n\t\tassert.strictEqual(arguments.length, 2);\n\t\tassert(typeof this.UvcControl === \"function\");\n\t}\n\n\tasync get(vendor: number | null, product: number | null, address: number | null): Promise<Camera> {\n\t\tassert.strictEqual(arguments.length, 3);\n\t\tassert(vendor === null || (typeof vendor === \"number\" && vendor >= 0));\n\t\tassert(product === null || (typeof product === \"number\" && product >= 0));\n\t\tassert(address === null || (typeof address === \"number\" && address >= 0));\n\n\t\tconst constructorOptions: ConstructorOptions = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tdeviceAddress: address || undefined,\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tpid: product || undefined,\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tvid: vendor || undefined,\n\t\t};\n\n\t\ttry {\n\t\t\tconst camera = new this.UvcControl(constructorOptions);\n\n\t\t\tif (vendor && vendor !== camera.device.deviceDescriptor.idVendor) {\n\t\t\t\tthis.output.warning(\"Camera vendor id mismatch.\", \"Input\", vendor, `(${toFormattedHex(vendor, 4)})`, \"Actual\", camera.device.deviceDescriptor.idVendor, `(${toFormattedHex(camera.device.deviceDescriptor.idVendor, 4)})`);\n\t\t\t}\n\n\t\t\tif (product && product !== camera.device.deviceDescriptor.idProduct) {\n\t\t\t\tthis.output.warning(\"Camera product id mismatch.\", \"Input\", product, `(${toFormattedHex(product, 4)})`, \"Actual\", camera.device.deviceDescriptor.idProduct, `(${toFormattedHex(camera.device.deviceDescriptor.idProduct, 4)})`);\n\t\t\t}\n\n\t\t\tif (address && address !== camera.device.deviceAddress) {\n\t\t\t\tthis.output.warning(\"Camera device address mismatch.\", \"Input\", address, `(${toFormattedHex(address, 1)})`, \"Actual\", camera.device.deviceAddress, `(${toFormattedHex(camera.device.deviceAddress, 1)})`);\n\t\t\t}\n\n\t\t\treturn camera;\n\t\t} catch (error: unknown) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\t// NOTE: basically a duplicate of both the arguments to this function and to the uvc-control constructor.\n\t\t\t\tconst getFunctionArguments: GetFunctionArguments = {\n\t\t\t\t\taddress,\n\t\t\t\t\tproduct,\n\t\t\t\t\tvendor,\n\t\t\t\t};\n\n\t\t\t\tconst wrappedError = this.createWrappedError(error, getFunctionArguments, constructorOptions);\n\n\t\t\t\tthrow wrappedError;\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate createWrappedError(error: ReadonlyDeep<Error>, getFunctionArguments: ReadonlyDeep<GetFunctionArguments>, constructorOptions: ReadonlyDeep<ConstructorOptions>) {\n\t\tlet errorMessage = null;\n\n\t\t// NOTE: relies on uvc-control internals.\n\t\t// NOTE: may rely on user locale.\n\t\tconst guessThatUvcDeviceWasNotFound = typeof error.name === \"string\"\n\t\t\t&& error.name === \"TypeError\"\n\t\t\t&& typeof error.message === \"string\"\n\t\t\t&& (\n\t\t\t\t// NOTE: message formatting differs across versions; could use a regular expression instead.\n\t\t\t\terror.message === \"Cannot read property 'interfaces' of undefined\"\n\t\t\t\t|| error.message === \"Cannot read properties of undefined (reading 'interfaces')\"\n\t\t\t);\n\n\t\terrorMessage = guessThatUvcDeviceWasNotFound ? `Could not find UVC device. Is a compatible camera connected? ${JSON.stringify(getFunctionArguments)}` : `Could create uvc-control object: ${JSON.stringify(constructorOptions)}`;\n\n\t\terrorMessage += ` (${JSON.stringify(String(error))})`;\n\n\t\tconst wrappedError = new WrappedError(error, errorMessage);\n\n\t\treturn wrappedError;\n\t}\n}\n"
  },
  {
    "path": "src/camera-helper-factory.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera from \"uvc-control\";\n\nimport CameraControlHelperFactory from \"./camera-control-helper-factory.js\";\nimport CameraHelperClass from \"./camera-helper.js\";\nimport Output from \"./output.js\";\n\nexport default class CameraHelperFactory {\n\tconstructor(\n\t\tprivate readonly output: ReadonlyDeep<Output>,\n\t\tprivate readonly cameraControlHelperFactory: ReadonlyDeep<CameraControlHelperFactory>,\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly CameraHelper: typeof CameraHelperClass,\n\t) {\n\t\tassert.strictEqual(arguments.length, 3);\n\t\tassert(typeof this.output === \"object\");\n\t\tassert(typeof this.cameraControlHelperFactory === \"object\");\n\t\tassert(typeof this.CameraHelper === \"function\");\n\t}\n\n\tasync get(camera: ReadonlyDeep<Camera>): Promise<CameraHelperClass> {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof camera === \"object\");\n\n\t\tconst cameraControlHelper = await this.cameraControlHelperFactory.get(camera);\n\t\tconst cameraHelper = new this.CameraHelper(this.output, cameraControlHelper, camera);\n\n\t\treturn cameraHelper;\n\t}\n}\n"
  },
  {
    "path": "src/camera-helper.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport Bluebird from \"bluebird\";\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera, {\n\tControlName,\n\tControlRange,\n\tControlValue,\n\tControlValues,\n} from \"uvc-control\";\n\nimport CameraControlHelper from \"./camera-control-helper.js\";\nimport Output from \"./output.js\";\nimport {\n\tUvccControls,\n} from \"./types/controls.js\";\nimport isUvccControlValue from \"./utilities/is-uvcc-control-value.js\";\n\nexport type ControlsValues = Record<string, ControlValues>;\nexport type ControlRanges = Record<string, ControlRange>;\n\nexport default class CameraHelper {\n\tconstructor(private readonly output: ReadonlyDeep<Output>, private readonly cameraControlHelper: ReadonlyDeep<CameraControlHelper>, private readonly camera: ReadonlyDeep<Camera>) {\n\t\tassert.strictEqual(arguments.length, 3);\n\t\tassert(typeof this.output === \"object\");\n\t\tassert(typeof this.cameraControlHelper === \"object\");\n\t\tassert(typeof this.camera === \"object\");\n\t}\n\n\tasync getValues(controlName: ControlName): Promise<ReadonlyDeep<ControlValues>> {\n\t\tconst gettableControlNames = await this.cameraControlHelper.getGettableControlNames();\n\n\t\tif (!gettableControlNames.includes(controlName)) {\n\t\t\tthrow new Error(`Could not find a gettable control named ${JSON.stringify(controlName)}.`);\n\t\t}\n\n\t\tconst valueObject = await this.camera.get(controlName);\n\n\t\treturn valueObject;\n\t}\n\n\tasync getRange(controlName: ControlName): Promise<ReadonlyDeep<ControlRange>> {\n\t\tconst rangedControlNames = await this.cameraControlHelper.getRangedControlNames();\n\n\t\tif (!rangedControlNames.includes(controlName)) {\n\t\t\tthrow new Error(`Could not find a ranged control named ${JSON.stringify(controlName)}.`);\n\t\t}\n\n\t\tconst range = this.camera.range(controlName);\n\n\t\treturn range;\n\t}\n\n\tasync setValues(controlName: ControlName, values: readonly ControlValue[]): Promise<void> {\n\t\tconst settableControlNames = await this.cameraControlHelper.getSettableControlNames();\n\n\t\tif (!settableControlNames.includes(controlName)) {\n\t\t\tthrow new Error(`Could not find a settable control named ${JSON.stringify(controlName)}.`);\n\t\t}\n\n\t\tawait this.camera.set(controlName, ...values);\n\n\t\treturn undefined;\n\t}\n\n\tasync getControlNames(): Promise<readonly ControlName[]> {\n\t\treturn this.cameraControlHelper.getControlNames();\n\t}\n\n\tasync getRanges(): Promise<ReadonlyDeep<ControlRanges>> {\n\t\t// TODO: replace with Object.fromEntries(...);\n\t\treturn Bluebird.reduce(\n\t\t\tthis.cameraControlHelper.getRangedControlNames(),\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n\t\t\tasync (object, controlName) => {\n\t\t\t\ttry {\n\t\t\t\t\tobject[controlName] = await this.getRange(controlName);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t// TODO: ignore only specific errors, such as usb.LIBUSB_TRANSFER_STALL?\n\t\t\t\t\tthis.output.verbose(\"Error getting range, ignoring.\", controlName, error);\n\t\t\t\t}\n\n\t\t\t\treturn object;\n\t\t\t},\n\t\t\t{} as ControlRanges,\n\t\t);\n\t}\n\n\tasync getSettableControls(): Promise<ReadonlyDeep<ControlsValues>> {\n\t\t// TODO: replace with Object.fromEntries(...);\n\t\treturn Bluebird.reduce(\n\t\t\tthis.cameraControlHelper.getSettableControlNames(),\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n\t\t\tasync (object, controlName) => {\n\t\t\t\ttry {\n\t\t\t\t\tobject[controlName] = await this.getValues(controlName);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t// TODO: ignore only specific errors, such as usb.LIBUSB_TRANSFER_STALL?\n\t\t\t\t\tthis.output.verbose(\"Error getting settable value, ignoring.\", controlName, error);\n\t\t\t\t}\n\n\t\t\t\treturn object;\n\t\t\t},\n\t\t\t{} as ControlsValues,\n\t\t);\n\t}\n\n\tasync setControls(configuration: ReadonlyDeep<UvccControls>): Promise<void> {\n\t\tconst controlNames = Object.keys(configuration);\n\t\tconst settableControlNames = await this.cameraControlHelper.getSettableControlNames();\n\n\t\t// NOTE: checking all control names before attempting to set any.\n\t\tconst nonSettableNames = controlNames.filter((controlName) => !settableControlNames.includes(controlName));\n\n\t\tif (nonSettableNames.length > 0) {\n\t\t\tthrow new Error(`Could not find a settable controls, aborting setting values: ${JSON.stringify(nonSettableNames)}`);\n\t\t}\n\n\t\tawait Bluebird.map(\n\t\t\tcontrolNames,\n\t\t\t// eslint-disable-next-line unicorn/no-array-method-this-argument\n\t\t\tasync (controlName) => {\n\t\t\t\tconst controlValues = configuration[controlName];\n\n\t\t\t\tif (!isUvccControlValue(controlValues)) {\n\t\t\t\t\tthrow new TypeError(`Expected number value for configuration ${controlName}, got ${typeof controlValues} ${JSON.stringify(controlValues)}.`);\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-spread\n\t\t\t\tconst controlValuesArray = new Array<number>().concat(controlValues);\n\n\t\t\t\ttry {\n\t\t\t\t\tawait this.setValues(controlName, controlValuesArray);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t// TODO: ignore only specific errors, such as usb.LIBUSB_TRANSFER_STALL?\n\t\t\t\t\tthis.output.verbose(\"Error setting value, ignoring.\", controlName, controlValues, error);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/controls.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\n\nexport default class ControlsCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<unknown> {\n\t\tassert.strictEqual(arguments.length, 1);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\n\t\tconst controlNames = await cameraHelper.getControlNames();\n\n\t\treturn controlNames;\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/devices.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\n\nimport {\n\tCommand,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\nimport UvcDeviceLister from \"../uvc-device-lister.js\";\n\nexport default class DevicesCommand implements Command {\n\tconstructor(private readonly uvcDeviceLister: UvcDeviceLister) {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof this.uvcDeviceLister === \"object\");\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [];\n\t}\n\n\tasync execute(): Promise<unknown> {\n\t\tassert.strictEqual(arguments.length, 0);\n\n\t\tconst devices = await this.uvcDeviceLister.get();\n\n\t\treturn devices;\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/export.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport mapObj from \"map-obj\";\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\nimport {\n\tUvccControls,\n} from \"../types/controls.js\";\nimport flattenControlValues from \"../utilities/flatten-control-values.js\";\n\nexport default class ExportCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<ReadonlyDeep<UvccControls>> {\n\t\tassert.strictEqual(arguments.length, 1);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\n\t\t// NOTE: exporting un-settable values breaks imports because of strict settable value checks.\n\t\t// TODO: export also un-settable values with --all flag?\n\t\tconst settableControls = await cameraHelper.getSettableControls();\n\t\tconst values = mapObj(\n\t\t\tsettableControls,\n\t\t\t(\n\t\t\t\tsettableControlName,\n\t\t\t\tsettableControlValue,\n\t\t\t) => [\n\t\t\t\tsettableControlName,\n\t\t\t\tflattenControlValues(settableControlValue),\n\t\t\t],\n\t\t);\n\n\t\treturn values;\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/get.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport {\n\tControlName,\n} from \"uvc-control\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\nimport flattenControlValues from \"../utilities/flatten-control-values.js\";\n\nexport default class GetCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t\t\"control\",\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<number | readonly number[]> {\n\t\tassert.strictEqual(arguments.length, 2);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\t\tconst controlName = args[1] as ControlName;\n\n\t\tconst valueObject = await cameraHelper.getValues(controlName);\n\t\tconst value = flattenControlValues(valueObject);\n\n\t\treturn value;\n\t}\n}\n\n"
  },
  {
    "path": "src/command-handlers/import.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport Bluebird from \"bluebird\";\nimport assert from \"node:assert\";\nimport process from \"node:process\";\nimport streamToPromise from \"stream-to-promise\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\nimport isUvccControls from \"../utilities/is-uvcc-controls.js\";\n\nexport default class ImportCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<void> {\n\t\tassert.strictEqual(arguments.length, 1);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\n\t\tconst stdinTimeout = 1000;\n\n\t\tconst controlValues = await Bluebird.try(async () => {\n\t\t\tconst buffer = await streamToPromise(process.stdin);\n\t\t\tconst json = JSON.parse(buffer.toString()) as unknown;\n\n\t\t\tassert(typeof json === \"object\");\n\t\t\tassert(json !== null);\n\n\t\t\treturn json;\n\t\t})\n\t\t\t.timeout(stdinTimeout, `Could not read uvcc configuration from stdin within the ${stdinTimeout} millisecond timeout. Was any data piped in?`)\n\t\t\t.tapCatch((error) => {\n\t\t\t\tprocess.stdin.destroy(error);\n\t\t\t});\n\n\t\tassert(isUvccControls(controlValues));\n\n\t\treturn cameraHelper.setControls(controlValues);\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/range.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport {\n\tControlName,\n\tControlRange,\n} from \"uvc-control\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\n\nexport default class RangeCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t\t\"control\",\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<ReadonlyDeep<ControlRange>> {\n\t\tassert.strictEqual(args.length, 2);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\t\tconst controlName = args[1] as ControlName;\n\n\t\tconst range = await cameraHelper.getRange(controlName);\n\n\t\treturn range;\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/ranges.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nimport CameraHelper,\n{\n\tControlRanges,\n} from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\n\nexport default class RangesCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<ReadonlyDeep<ControlRanges>> {\n\t\tassert.strictEqual(arguments.length, 1);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\n\t\tconst ranges = await cameraHelper.getRanges();\n\n\t\treturn ranges;\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers/set.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport {\n\tControlName,\n\tControlValue,\n} from \"uvc-control\";\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tCommand,\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentNames,\n} from \"../types/command.js\";\n\nexport default class SetCommand implements Command {\n\tconstructor() {\n\t\tassert.strictEqual(arguments.length, 0);\n\t}\n\n\tasync getArguments(): Promise<CommandHandlerArgumentNames[]> {\n\t\treturn [\n\t\t\tCommandHandlerArgumentCameraHelper,\n\t\t\t\"control\",\n\t\t\t\"values\",\n\t\t];\n\t}\n\n\tasync execute(...args: readonly unknown[]): Promise<void> {\n\t\tassert(args.length >= 2);\n\n\t\tconst cameraHelper = args[0] as ReadonlyDeep<CameraHelper>;\n\t\tconst controlName = args[1] as ControlName;\n\t\tconst values = args[2] as readonly ControlValue[];\n\n\t\treturn cameraHelper.setValues(controlName, values);\n\t}\n}\n"
  },
  {
    "path": "src/command-handlers.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nimport Output from \"./output.js\";\nimport {\n\tCommandHandlerArgumentNames,\n\tCommandName,\n\tCommands,\n} from \"./types/command.js\";\n\nexport default class CommandHandlers {\n\tconstructor(private readonly output: Output, private readonly commands: ReadonlyDeep<Commands>) {\n\t\tassert.strictEqual(arguments.length, 2);\n\t\tassert(typeof this.output === \"object\");\n\t\tassert(typeof this.commands === \"object\");\n\t}\n\n\tasync has(commandName: CommandName): Promise<boolean> {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof commandName === \"string\");\n\n\t\tconst command = this.commands[commandName];\n\n\t\treturn Boolean(command);\n\t}\n\n\tasync execute(commandName: CommandName, ...args: readonly unknown[]): Promise<unknown> {\n\t\tassert(typeof commandName === \"string\");\n\t\tassert(Array.isArray(args));\n\n\t\tconst command = this.commands[commandName];\n\n\t\tassert(typeof command === \"object\");\n\n\t\tconst output = await command.execute(...args);\n\n\t\treturn output;\n\t}\n\n\tasync getArguments(commandName: CommandName): Promise<CommandHandlerArgumentNames[]> {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof commandName === \"string\");\n\n\t\tconst command = this.commands[commandName];\n\n\t\tassert(typeof command === \"object\");\n\n\t\treturn command.getArguments();\n\t}\n}\n"
  },
  {
    "path": "src/command-manager.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport Camera from \"uvc-control\";\n\nimport CameraFactory from \"./camera-factory.js\";\nimport CameraHelperFactory from \"./camera-helper-factory.js\";\nimport CommandHandlers from \"./command-handlers.js\";\nimport Output from \"./output.js\";\nimport {\n\tRuntimeConfiguration,\n} from \"./runtime-configurator.js\";\nimport {\n\tCommandHandlerArgumentCameraHelper,\n\tCommandHandlerArgumentTypes,\n\tCommandHandlerLookup,\n} from \"./types/command.js\";\n\nexport default class CommandManager {\n\tconstructor(private readonly output: Output, private readonly cameraFactory: CameraFactory, private readonly cameraHelperFactory: CameraHelperFactory, private readonly commandHandlers: CommandHandlers) {\n\t\tassert.strictEqual(arguments.length, 4);\n\t\tassert(typeof this.output === \"object\");\n\t\tassert(typeof this.cameraFactory === \"object\");\n\t\tassert(typeof this.cameraHelperFactory === \"object\");\n\t\tassert(typeof this.commandHandlers === \"object\");\n\t}\n\n\tasync execute(runtimeConfig: ReadonlyDeep<RuntimeConfiguration>): Promise<void> {\n\t\tthis.output.verbose(\"Parsed arguments:\", JSON.stringify(runtimeConfig, null, 2));\n\n\t\tconst commandName = runtimeConfig.cmd;\n\t\tconst commandHandlerExists = await this.commandHandlers.has(commandName);\n\n\t\tif (!commandHandlerExists) {\n\t\t\tthis.output.error(\"Unknown command:\", commandName);\n\t\t\treturn;\n\t\t}\n\n\t\tlet camera: Camera | null = null;\n\n\t\tconst closeCamera = async () => {\n\t\t\tif (camera) {\n\t\t\t\tawait camera.close();\n\t\t\t}\n\t\t};\n\n\t\tconst commandArguments = await this.commandHandlers.getArguments(commandName);\n\n\t\t// TODO: smarter solution.\n\t\tif (commandArguments.includes(CommandHandlerArgumentCameraHelper)) {\n\t\t\tconst {\n\t\t\t\tvendor,\n\t\t\t\tproduct,\n\t\t\t\taddress,\n\t\t\t} = runtimeConfig;\n\n\t\t\tassert(typeof vendor === \"number\");\n\t\t\tassert(typeof product === \"number\");\n\t\t\tassert(typeof address === \"number\");\n\n\t\t\tcamera = await this.cameraFactory.get(vendor, product, address);\n\t\t}\n\n\t\ttry {\n\t\t\t// NOTE HACK: don't mix \"injection\" with other arguments.\n\t\t\tconst argumentValues: CommandHandlerArgumentTypes[] = commandArguments\n\t\t\t\t.filter((commandArgument) => commandArgument !== CommandHandlerArgumentCameraHelper)\n\t\t\t\t.map((commandArgument) => (runtimeConfig as CommandHandlerLookup)[commandArgument]);\n\n\t\t\t// TODO: smarter solution.\n\t\t\tif (commandArguments.includes(CommandHandlerArgumentCameraHelper)) {\n\t\t\t\tassert(camera !== null);\n\n\t\t\t\tconst cameraHelper = await this.cameraHelperFactory.get(camera);\n\n\t\t\t\targumentValues.unshift(cameraHelper);\n\t\t\t}\n\n\t\t\tconst output = await this.commandHandlers.execute(commandName, ...argumentValues);\n\n\t\t\t// NOTE: could separate of types of commands -- those with output, and those without.\n\t\t\tif (typeof output !== \"undefined\") {\n\t\t\t\tconst json = JSON.stringify(output, null, 2);\n\n\t\t\t\tthis.output.normal(json);\n\t\t\t}\n\n\t\t\tawait closeCamera();\n\t\t} catch (error: unknown) {\n\t\t\ttry {\n\t\t\t\tawait closeCamera();\n\t\t\t} catch {\n\t\t\t\t// NOTE: if there were previous errors, ignore errors when closing the camera connection.\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/index.ts",
    "content": "#!/usr/bin/env node\n/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport engineCheck from \"engine-check\";\nimport {\n\tdirname,\n\tjoin,\n} from \"node:path\";\nimport process from \"node:process\";\nimport {\n\tfileURLToPath,\n} from \"node:url\";\nimport UvcControl from \"uvc-control\";\n\nimport CameraControlHelper from \"./camera-control-helper.js\";\nimport CameraControlHelperFactory from \"./camera-control-helper-factory.js\";\nimport CameraFactory from \"./camera-factory.js\";\nimport CameraHelper from \"./camera-helper.js\";\nimport CameraHelperFactory from \"./camera-helper-factory.js\";\nimport CommandHandlers from \"./command-handlers.js\";\nimport ControlsCommand from \"./command-handlers/controls.js\";\nimport DevicesCommand from \"./command-handlers/devices.js\";\nimport ExportCommand from \"./command-handlers/export.js\";\nimport GetCommand from \"./command-handlers/get.js\";\nimport ImportCommand from \"./command-handlers/import.js\";\nimport RangeCommand from \"./command-handlers/range.js\";\nimport RangesCommand from \"./command-handlers/ranges.js\";\nimport SetCommand from \"./command-handlers/set.js\";\nimport CommandManager from \"./command-manager.js\";\nimport Output from \"./output.js\";\nimport runtimeConfigurator from \"./runtime-configurator.js\";\nimport {\n\tCommands,\n} from \"./types/command.js\";\nimport UvcDeviceLister from \"./uvc-device-lister.js\";\n\n// TODO: load package.json at compile time, use process.cwd() for resolving other paths.\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst mainAsync = async () => {\n\ttry {\n\t\t// NOTE: ignoring unhandled rejections and exceptions, as there is (practically) nothing to gracefully shut down.\n\t\tconst runtimeConfig = await runtimeConfigurator();\n\t\tconst output = new Output(runtimeConfig.verbose);\n\n\t\tprocess.on(\"unhandledRejection\", (...args: readonly unknown[]) => {\n\t\t\toutput.error(...args);\n\n\t\t\tprocess.exitCode = 1;\n\t\t});\n\t\tprocess.on(\"uncaughtException\", (...args: readonly unknown[]) => {\n\t\t\toutput.error(...args);\n\n\t\t\tprocess.exitCode = 1;\n\t\t});\n\n\t\tconst cameraFactory = new CameraFactory(output, UvcControl);\n\t\tconst cameraControlHelperFactory = new CameraControlHelperFactory(UvcControl, CameraControlHelper);\n\t\tconst cameraHelperFactory = new CameraHelperFactory(output, cameraControlHelperFactory, CameraHelper);\n\t\tconst uvcDeviceLister = new UvcDeviceLister(UvcControl);\n\t\tconst commands: Commands = {\n\t\t\tcontrols: new ControlsCommand(),\n\t\t\tdevices: new DevicesCommand(uvcDeviceLister),\n\t\t\t\"export\": new ExportCommand(),\n\t\t\tget: new GetCommand(),\n\t\t\t\"import\": new ImportCommand(),\n\t\t\trange: new RangeCommand(),\n\t\t\tranges: new RangesCommand(),\n\t\t\tset: new SetCommand(),\n\t\t};\n\t\tconst commandHandlers = new CommandHandlers(output, commands);\n\t\tconst commandManager = new CommandManager(output, cameraFactory, cameraHelperFactory, commandHandlers);\n\n\t\tawait commandManager.execute(runtimeConfig);\n\t} catch (error: unknown) {\n\t\t// NOTE: root error handler for asynchronous errors.\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(error);\n\n\t\tprocess.exitCode = 1;\n\t}\n};\n\nconst main = () => {\n\ttry {\n\t\tengineCheck({\n\t\t\tsearchRoot: join(__dirname, \"..\"),\n\t\t});\n\n\t\tvoid mainAsync();\n\t} catch (error: unknown) {\n\t\t// NOTE: root error handler for synchronous errors.\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(error);\n\n\t\tprocess.exitCode = 1;\n\t}\n};\n\nmain();\n"
  },
  {
    "path": "src/output.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\n\nexport default class Output {\n\tconstructor(public enableVerboseOutput: boolean) {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof this.enableVerboseOutput === \"boolean\");\n\t}\n\n\tnormal(...args: readonly unknown[]): void {\n\t\tthis.consoleLog(...args);\n\t}\n\n\terror(...args: readonly unknown[]): void {\n\t\tthis.consoleError(...args);\n\t}\n\n\twarning(...args: readonly unknown[]): void {\n\t\tthis.consoleWarn(...args);\n\t}\n\n\tverbose(...args: readonly unknown[]): void {\n\t\tif (!this.enableVerboseOutput) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.consoleError(...args);\n\t}\n\n\tprivate consoleLog(...args: readonly unknown[]) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.log(...args);\n\t}\n\n\tprivate consoleError(...args: readonly unknown[]) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(...args);\n\t}\n\n\tprivate consoleWarn(...args: readonly unknown[]) {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.warn(...args);\n\t}\n}\n"
  },
  {
    "path": "src/runtime-configurator.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport chalk from \"chalk\";\nimport {\n\tfindUpSync,\n} from \"find-up\";\nimport assert from \"node:assert\";\nimport fs from \"node:fs\";\nimport {\n\tdirname,\n\tjoin,\n} from \"node:path\";\nimport process from \"node:process\";\nimport {\n\tfileURLToPath,\n} from \"node:url\";\nimport {\n\treadPackageUp,\n} from \"read-pkg-up\";\nimport {\n\tJsonValue,\n\tReadonlyDeep,\n} from \"type-fest\";\nimport yargs, {\n\tArgv,\n} from \"yargs\";\n\n// TODO: load package.json at compile time, use process.cwd() for resolving other paths.\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst getJsonSync = (fileRelativePath: string): JsonValue => {\n\tconst resolvedPath = join(__dirname, fileRelativePath);\n\n\ttry {\n\t\t// eslint-disable-next-line no-sync\n\t\tconst json = JSON.parse(fs.readFileSync(resolvedPath).toString()) as JsonValue;\n\n\t\treturn json;\n\t} catch (error: unknown) {\n\t\tthrow new Error(`Could not read JSON file ${JSON.stringify(resolvedPath)}: ${JSON.stringify(String(error))}`);\n\t}\n};\n\nexport type RuntimeConfiguration = {\n\taddress: number;\n\tcmd: string;\n\tcontrol?: string;\n\tproduct: number;\n\tvalues: readonly number[];\n\tvendor: number;\n\tverbose: boolean;\n};\nexport type RuntimeConfigurationKeys = keyof RuntimeConfiguration;\nexport type RuntimeConfigurationTypes = readonly number[] | number | string | boolean | undefined;\n\nconst getYargsArgv = async (): Promise<ReadonlyDeep<Argv[\"argv\"]>> => {\n\tconst packageJsonResult = await readPackageUp({\n\t\tcwd: __dirname,\n\t});\n\n\tassert(typeof packageJsonResult !== \"undefined\");\n\n\tconst {\n\t\tbin,\n\t\tdescription,\n\t\thomepage,\n\t\tversion,\n\t} = packageJsonResult.packageJson;\n\n\tassert(typeof bin === \"object\");\n\tassert(typeof description === \"string\");\n\tassert(typeof homepage === \"string\");\n\tassert(!version.startsWith(\"v\"));\n\n\tconst appBinaryName = Object.keys(bin)[0];\n\n\tassert(typeof appBinaryName === \"string\");\n\n\tconst epilogue = chalk.dim`uvcc Copyright © 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\\n\\nThis program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See GPL-3.0 license for details.\\n\\nSee also: ${homepage}`;\n\n\tlet fromImplicitConfigFile = null;\n\n\tconst hasConfigFlag = process.argv.includes(\"--config\");\n\n\tif (hasConfigFlag) {\n\t\tfromImplicitConfigFile = {};\n\t} else {\n\t\tconst nearestConfigPath = findUpSync([\n\t\t\t`.${appBinaryName}rc`,\n\t\t\t`.${appBinaryName}rc.json`,\n\t\t]);\n\t\tconst configFromNearestConfigPath = nearestConfigPath ? getJsonSync(nearestConfigPath) : {};\n\n\t\tfromImplicitConfigFile = configFromNearestConfigPath;\n\n\t\tassert(typeof fromImplicitConfigFile === \"object\");\n\t\tassert(fromImplicitConfigFile !== null);\n\t}\n\n\tconst parserRoot: Argv = yargs(process.argv.slice(2));\n\n\t/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */\n\tconst parser = parserRoot\n\t\t.strict()\n\t\t.wrap(parserRoot.terminalWidth())\n\t\t.config(fromImplicitConfigFile)\n\t\t.config(\"config\", \"Load command arguments from a JSON file.\", (argumentConfigPath) => {\n\t\t\tconst fromExplicitConfigFile = argumentConfigPath ? getJsonSync(argumentConfigPath) : {};\n\n\t\t\tassert(typeof fromExplicitConfigFile === \"object\");\n\t\t\tassert(fromExplicitConfigFile !== null);\n\n\t\t\treturn fromExplicitConfigFile;\n\t\t})\n\t\t.env(appBinaryName.toUpperCase())\n\t\t.version(`v${version}`)\n\t\t.usage(`${chalk.bold(\"$0\")}: ${description}`)\n\t\t.command(\"get <control>\", \"Get current control value.\", (yargsToApplyTo) => {\n\t\t\tyargsToApplyTo\n\t\t\t\t.positional(\"control\", {\n\t\t\t\t\tdemandOption: true,\n\t\t\t\t\tdescribe: \"Name of the control.\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t});\n\t\t})\n\t\t.command(\"set <control> <value1> [value2]\", \"Set control value(s).\", (yargsToApplyTo) => {\n\t\t\tyargsToApplyTo\n\t\t\t\t.positional(\"control\", {\n\t\t\t\t\tdemandOption: true,\n\t\t\t\t\tdescribe: \"Name of the control.\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t})\n\t\t\t\t.positional(\"value1\", {\n\t\t\t\t\tdemandOption: true,\n\t\t\t\t\tdescribe: \"Value to set.\",\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t})\n\t\t\t\t.positional(\"value2\", {\n\t\t\t\t\tdemandOption: false,\n\t\t\t\t\tdescribe: \"Second value to set, if supported by the control.\",\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t});\n\t\t})\n\t\t.command(\"range <control>\", \"Get possible range (min and max) for a control.\", (yargsToApplyTo) => {\n\t\t\tyargsToApplyTo\n\t\t\t\t.positional(\"control\", {\n\t\t\t\t\tdemandOption: true,\n\t\t\t\t\tdescribe: \"Name of the control.\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t});\n\t\t})\n\t\t.command(\"ranges\", \"Get all ranges (min and max).\")\n\t\t.command(\"devices\", \"List connected UVC devices.\")\n\t\t.command(\"controls\", \"List all supported controls for the camera.\")\n\t\t.command(\"export\", \"Output configuration in JSON format, on stdout.\")\n\t\t.command(\"import\", \"Input configuration in JSON format, from stdin.\")\n\t\t.option(\"vendor\", {\n\t\t\t\"default\": 0,\n\t\t\tdescribe: \"Camera vendor id (vId).\",\n\t\t\ttype: \"number\",\n\t\t})\n\t\t.option(\"product\", {\n\t\t\t\"default\": 0,\n\t\t\tdescribe: \"Camera product id (pId).\",\n\t\t\ttype: \"number\",\n\t\t})\n\t\t.option(\"address\", {\n\t\t\t\"default\": 0,\n\t\t\tdescribe: \"Camera device address.\",\n\t\t\ttype: \"number\",\n\t\t})\n\t\t.option(\"verbose\", {\n\t\t\t\"default\": false,\n\t\t\tdescribe: \"Enable verbose output.\",\n\t\t\ttype: \"boolean\",\n\t\t})\n\t\t.demandCommand(1, 1, chalk.red(\"Please provide a single command.\"), chalk.red(\"Please provide a single command.\"))\n\t\t.group(\n\t\t\t[\n\t\t\t\t\"vendor\",\n\t\t\t\t\"product\",\n\t\t\t\t\"address\",\n\t\t\t],\n\t\t\tchalk.bold(\"Device selection for multi-camera setups.\") + \"\\n  \" + chalk.dim(\"Numbers in hex (0x000) or decimal (0000) format.\"))\n\t\t.help()\n\t\t.example(\"\", \"\")\n\t\t.example(chalk.bold(\"Basic usage:\"), \"\")\n\t\t.example(\"$0 controls\", \"Available controls for the camera.\")\n\t\t.example(\"$0 set auto_white_balance_temperature 0\", \"Turn off automatic color correction.\")\n\t\t.example(\"$0 set saturation 64\", \"Low color saturation (near grayscale).\")\n\t\t.example(\"$0 ranges\", \"List possible control ranges.\")\n\t\t.example(\"$0 set absolute_zoom 200\", \"Zoom in.\")\n\t\t.example(\"\", \"\")\n\t\t.example(chalk.bold(\"Automate config:\"), \"\")\n\t\t.example(chalk.dim(\"- Not all controls can be imported.\"), \"\")\n\t\t.example(chalk.dim(\"- Control order matters.\"), \"\")\n\t\t.example(\"$0 export > my-uvcc-export.json\", \"Save to file.\")\n\t\t.example(\"cat my-uvcc-export.json | $0 import\", \"Load from file.\")\n\t\t.example(\"\", \"\")\n\t\t.example(chalk.bold(\"Target a specific device:\"), \"\")\n\t\t.example(chalk.dim(\"- Only useful for multi-camera setups.\"), \"\")\n\t\t.example(chalk.dim(\"- For same-model cameras, also specify address.\"), \"\")\n\t\t.example(chalk.dim(\"- Alt. use system USB settings to find devices.\"), \"\")\n\t\t.example(\"$0 devices\", \"List available cameras.\")\n\t\t.example(\"sudo $0 devices\", \"Avoid LIBUSB_ERROR_ACCESS.\")\n\t\t.example(\"$0 --vendor 0x46d --product 0x82d export\", \"\")\n\t\t.epilogue(epilogue);\n\t/* eslint-enable @typescript-eslint/prefer-readonly-parameter-types */\n\n\treturn parser.parseAsync();\n};\n\nconst mapArgv = async (argv: ReadonlyDeep<Argv[\"argv\"]>): Promise<RuntimeConfiguration> => {\n\t// NOTE HACK: workaround yargs not being consistent with yargs.cmd versus yargs._ for defined/non-defined commands.\n\tconst cmd = \"cmd\" in argv && typeof argv[\"cmd\"] === \"string\"\n\t\t? argv[\"cmd\"]\n\t\t: (\n\t\t\t\"_\" in argv && typeof argv._[0] === \"string\"\n\t\t\t\t? argv._[0]\n\t\t\t\t: null\n\t\t);\n\n\tconst {\n\t\taddress,\n\t\tcontrol,\n\t\tproduct,\n\t\tvalue1,\n\t\tvalue2,\n\t\tvendor,\n\t\tverbose,\n\t} = argv as Record<string, unknown>;\n\n\tassert(typeof address === \"number\");\n\tassert(typeof cmd === \"string\");\n\tassert(typeof product === \"number\");\n\tassert(typeof vendor === \"number\");\n\tassert(typeof verbose === \"boolean\");\n\n\t// NOTE: accept one value if the first is a number, two if both are numbers.\n\tlet values: readonly number[] = [];\n\n\tif (typeof value1 === \"number\") {\n\t\tvalues = typeof value2 === \"number\" ? [\n\t\t\tvalue1,\n\t\t\tvalue2,\n\t\t] : [\n\t\t\tvalue1,\n\t\t];\n\t}\n\n\tconst mappedArgv: RuntimeConfiguration = {\n\t\taddress,\n\t\tcmd,\n\t\tcontrol: typeof control === \"string\" ? control : undefined,\n\t\tproduct,\n\t\tvalues,\n\t\tvendor,\n\t\tverbose,\n\t};\n\n\treturn mappedArgv;\n};\n\nexport default async function runtimeConfigurator(): Promise<RuntimeConfiguration> {\n\tconst rawArgv = await getYargsArgv();\n\tconst argv = await mapArgv(rawArgv);\n\n\treturn argv;\n}\n"
  },
  {
    "path": "src/types/command.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport CameraHelper from \"../camera-helper.js\";\nimport {\n\tRuntimeConfigurationKeys,\n\tRuntimeConfigurationTypes,\n} from \"../runtime-configurator.js\";\n\nexport type CommandName = string;\n\n// NOTE HACK: magic string hack so the command manager can inject camera helper to command handlers which need it.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const CommandHandlerArgumentCameraHelper = \"cameraHelper\";\nexport type CommandHandlerArgumentNames = RuntimeConfigurationKeys | typeof CommandHandlerArgumentCameraHelper;\nexport type CommandHandlerArgumentTypes = RuntimeConfigurationTypes | CameraHelper;\nexport type CommandHandlerLookup = Record<CommandHandlerArgumentNames, CommandHandlerArgumentTypes>;\n\nexport interface Command {\n\texecute: (...args: readonly unknown[]) => Promise<unknown>;\n\tgetArguments: () => Promise<CommandHandlerArgumentNames[]>;\n}\n\nexport type Commands = Record<string, Command>;\n"
  },
  {
    "path": "src/types/controls.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nexport type UvccControlValue = number | readonly number[];\nexport type UvccControls = ReadonlyDeep<Record<string, UvccControlValue>>;\n"
  },
  {
    "path": "src/types/uvc-control.d.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\ndeclare module \"uvc-control\" {\n\t// TODO: move type declarations to uvc-control.\n\timport UvcControlModule from \"uvc-control\";\n\timport {\n\t\tReadonlyDeep,\n\t} from \"type-fest\";\n\n\timport {\n\t\tusb,\n\t} from \"usb\";\n\n\t/* eslint-disable @typescript-eslint/member-ordering */\n\texport default class Camera {\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tpublic static readonly REQUEST: ReadonlyDeep<RequestTypes>;\n\t\tpublic static readonly controls: ReadonlyDeep<CameraControls>;\n\n\t\tpublic readonly supportedControls: readonly ControlName[];\n\t\tpublic readonly device: usb.Device;\n\n\t\tconstructor(options: ConstructorOptions);\n\n\t\tpublic static discover(): Promise<readonly UvcDevice[]>;\n\n\t\tget(name: ControlName): Promise<ReadonlyDeep<ControlValues>>;\n\t\trange(name: ControlName): Promise<ReadonlyDeep<ControlRange>>;\n\t\tset(name: ControlName, ...values: readonly ControlValue[]): Promise<readonly number[]>;\n\t\tclose(): Promise<void>;\n\t}\n\t/* eslint-enable @typescript-eslint/member-ordering */\n\n\texport type UvcControl = typeof Camera;\n\n\texport interface UvcDevice {\n\t\treadonly name: string;\n\t\treadonly deviceDescriptor: {\n\t\t\treadonly idVendor: number;\n\t\t\treadonly idProduct: number;\n\t\t};\n\t\treadonly deviceAddress: number;\n\t}\n\n\texport type RequestType = number;\n\n\texport interface RequestTypes {\n\t\treadonly \"GET_CUR\": RequestType;\n\t\treadonly \"GET_MAX\": RequestType;\n\t\treadonly \"GET_MIN\": RequestType;\n\t\treadonly \"SET_CUR\": RequestType;\n\t}\n\n\texport interface ConstructorOptions {\n\t\treadonly deviceAddress?: number;\n\t\treadonly pid?: number;\n\t\treadonly vid?: number;\n\t}\n\n\texport interface CameraControl {\n\t\treadonly name: ControlName;\n\t\treadonly requests: readonly RequestType[];\n\t\treadonly optional_requests: readonly RequestType[];\n\t}\n\n\texport type CameraControls = Record<string, CameraControl>;\n\n\texport type ControlName = string;\n\texport type ControlValue = number;\n\texport type ControlValues = Record<string, ControlValue>;\n\texport interface ControlRange {\n\t\treadonly max: number;\n\t\treadonly min: number;\n\t}\n}\n"
  },
  {
    "path": "src/utilities/flatten-control-values.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport {\n\tControlValues,\n} from \"uvc-control\";\n\nexport default function flattenControlValues(valueObject: ReadonlyDeep<ControlValues>): number | readonly number[] {\n\tconst values = Object.values(valueObject);\n\tconst firstValue = values[0];\n\n\tconst value = values.length === 1 && typeof firstValue === \"number\"\n\t\t? firstValue\n\t\t// NOTE: presumably the same order has to be used when setting values later.\n\t\t: values;\n\n\treturn value;\n}\n"
  },
  {
    "path": "src/utilities/is-uvcc-control-value.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport {\n\tUvccControlValue,\n} from \"../types/controls.js\";\n\nexport default function isUvccControlValue(controlValues: unknown): controlValues is UvccControlValue {\n\treturn typeof controlValues === \"number\"\n\t\t|| (\n\t\t\tArray.isArray(controlValues)\n\t\t\t\t&& controlValues.every((controlValue) => typeof controlValue === \"number\")\n\t\t);\n}\n"
  },
  {
    "path": "src/utilities/is-uvcc-controls.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport {\n\tUvccControls,\n} from \"../types/controls.js\";\nimport isUvccControlValue from \"./is-uvcc-control-value.js\";\n\nexport default function isUvccControls(controlValues: unknown): controlValues is UvccControls {\n\treturn typeof controlValues === \"object\"\n\t\t&& controlValues !== null\n\t\t&& Object\n\t\t\t.entries(controlValues)\n\t\t\t.every(\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n\t\t\t\t([\n\t\t\t\t\tcontrolName,\n\t\t\t\t\tcontrolValues,\n\t\t\t\t]) => typeof controlName === \"string\" && isUvccControlValue(controlValues),\n\t\t\t);\n}\n"
  },
  {
    "path": "src/utilities/to-formatted-hex.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nexport default function toFormattedHex(i: number, minimumDigits: number): string {\n\treturn `0x${i.toString(16).padStart(minimumDigits, \"0\")}`;\n}\n"
  },
  {
    "path": "src/utilities/wrapped-error.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\n\nexport default class WrappedError extends Error {\n\tconstructor(public readonly innerError: ReadonlyDeep<Error>,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\n\t\tassert(this.innerError instanceof Error);\n\t}\n\n\toverride toString(): string {\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\treturn `${super.toString()} (${JSON.stringify(String(this.innerError))})`;\n\t}\n}\n"
  },
  {
    "path": "src/uvc-device-lister.ts",
    "content": "/*\nThis file is part of uvcc -- USB Video Class (UVC) device configurator.\nCopyright (C) 2018, 2019, 2020, 2021, 2022 Joel Purra <https://joelpurra.com/>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n*/\n\nimport assert from \"node:assert\";\nimport {\n\tReadonlyDeep,\n} from \"type-fest\";\nimport {\n\tUvcControl,\n} from \"uvc-control\";\n\nexport interface MappedUvcDevice {\n\treadonly name: string;\n\treadonly vendor: number;\n\treadonly product: number;\n\treadonly address: number;\n}\n\nexport default class UvcDeviceLister {\n\tconstructor(\n\t\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\t\tprivate readonly UvcControl: ReadonlyDeep<UvcControl>,\n\t) {\n\t\tassert.strictEqual(arguments.length, 1);\n\t\tassert(typeof this.UvcControl === \"function\");\n\t}\n\n\tasync get(): Promise<readonly MappedUvcDevice[]> {\n\t\tconst devices = await this.UvcControl.discover();\n\t\tconst output = devices.map((device) =>\n\t\t\t({\n\t\t\t// NOTE: outputting in human-readable \"logical\" non-alphabetical order.\n\t\t\t\tname: device.name,\n\t\t\t\tvendor: device.deviceDescriptor.idVendor,\n\t\t\t\t// eslint-disable-next-line sort-keys\n\t\t\t\tproduct: device.deviceDescriptor.idProduct,\n\t\t\t\t// eslint-disable-next-line sort-keys\n\t\t\t\taddress: device.deviceAddress,\n\t\t\t}));\n\n\t\treturn output;\n\t}\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"extends\": \"@sindresorhus/tsconfig\",\n  \"compilerOptions\": {\n    \"module\": \"es2020\",\n    \"outDir\": \"dist\",\n    \"target\": \"es2018\",\n    \"lib\": [\"es2018\"],\n    \"esModuleInterop\": true\n  },\n  \"include\": [\"./src/**/*\"]\n}\n"
  }
]