Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Created March 7, 2021 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ma2shita/a6ad200bea550f7211636783f17539b9 to your computer and use it in GitHub Desktop.
Save ma2shita/a6ad200bea550f7211636783f17539b9 to your computer and use it in GitHub Desktop.
Focus control for Arducam B0176 "Motorized focus camera for Raspberry Pi"
#!/bin/env python3
"""
Focus control for Arducam B0176 "Motorized focus camera for Raspberry Pi"
See: TBC
Copyright (c) 2021 Kohei MATSUSHITA
This software is released under the The 3-Clause BSD License.
https://opensource.org/licenses/BSD-3-Clause
"""
import sys
import argparse
class range_check():
def __init__(self):
self.min = 0
self.max = 1023
def __contains__(self, val):
return (self.min <= val and val <= self.max)
def __iter__(self):
return iter(("Integer", "{} <= N <= {}".format(self.min, self.max)))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--focus", type=int, dest="focus", required=True, choices=range_check(), help="Camera focus 0(far)..1023(near)")
args = parser.parse_args()
print("Focus set to {}".format(args.focus), file=sys.stderr)
from ctypes import CDLL
arducam_vcm = CDLL('libarducam_vcm.so')
arducam_vcm.vcm_init()
arducam_vcm.vcm_write(args.focus)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment