def set_f_number(f_number): """Changes the current aperture size when using manual mode. TODO(jordanhuus): confirm when this works and doesn't work. Args: param1 (float): TODO(jordanhuus): determine unit of measurement """ ptpTransport = PtpUsbTransport( PtpUsbTransport.findptps(PtpUsbTransport.USB_CLASS_PTP)) bulk_in, bulk_out, interrupt_in = \ PtpUsbTransport.retrieve_device_endpoints( PtpUsbTransport.findptps(PtpUsbTransport.USB_CLASS_PTP)) ptpSession = PtpSession(ptpTransport) vendorId = PtpValues.Vendors.STANDARD try: # Open device session ptpSession.OpenSession() ptpSession.SetFNumber(f_number) except PtpException as e: raise PtpException( "PTP Exception: %s" % PtpValues.ResponseNameById(e.responsecode, vendorId), ptpSession, ptpTransport) except Exception as e: raise Exception(e) # Close the session del ptpSession del ptpTransport
from ptp import PtpValues ptpTransport = PtpUsbTransport(PtpUsbTransport.findptps()[0]) ptpSession = PtpSession(ptpTransport) vendorId = PtpValues.Vendors.STANDARD try: ptpSession.OpenSession() deviceInfo = ptpSession.GetDeviceInfo() vendorId = deviceInfo.VendorExtensionID # Read all the possible fstops fstops = ptpSession.GetDevicePropInfo( PtpValues.StandardProperties.F_NUMBER).Enumeration for fstop in fstops: ptpSession.SetFNumber(fstop) print "Capturing %i" % fstop ptpSession.InitiateCapture( objectFormatId=PtpValues.StandardObjectFormats.EXIF_JPEG) while True: evt = ptpSession.CheckForEvent(None) if evt.eventcode == PtpValues.StandardEvents.OBJECT_ADDED: break except PtpException, e: print "PTP Exception: %s" % PtpValues.ResponseNameById( e.responsecode, vendorId) except Exception, e: print "An exception occurred: %s" % e traceback.print_exc()
def get_f_number_options(): """TODO(jordanhuus): add doc string """ ptpTransport = PtpUsbTransport( PtpUsbTransport.findptps(PtpUsbTransport.USB_CLASS_PTP)) bulk_in, bulk_out, interrupt_in = \ PtpUsbTransport.retrieve_device_endpoints( PtpUsbTransport.findptps(PtpUsbTransport.USB_CLASS_PTP)) ptpSession = PtpSession(ptpTransport) vendorId = PtpValues.Vendors.STANDARD minimum_f_stop = None maximum_f_stop = None f_stop_type_index = None try: # Open device session ptpSession.OpenSession() # Available f-stop values # Start with the most granular option (1/3rd stops) f_numbers_third_stops = [ 100, 110, 120, 140, 160, 180, 200, 220, 250, 280, 320, 350, 400, 450, 500, 560, 630, 710, 800, 900, 1000, 1100, 1300, 1400, 1600, 1800, 2000, 2200, 2500, 2900, 3200, 3600 ] f_numbers_half_stops = [ 100, 120, 140, 170, 200, 240, 280, 330, 400, 480, 560, 670, 800, 950, 1100, 1300, 1600, 1900, 2200, 2700, 3200 ] f_numbers_full_stops = [ 100, 140, 200, 280, 400, 560, 800, 1100, 1600, 2200, 3200 ] f_stops = [ f_numbers_third_stops, f_numbers_half_stops, f_numbers_full_stops ] # Attempt to find min/max f-stop values for i in range(len(f_stops)): if minimum_f_stop and maximum_f_stop: break # Find min for f_number in f_stops[i]: try: ptpSession.SetFNumber(f_number) if not minimum_f_stop: minimum_f_stop = f_number f_stop_type_index = i break except PtpException as ptpe: if ptpe.args[0] == 8220: continue # Find max for f_number in f_stops[i][::-1]: try: ptpSession.SetFNumber(f_number) if not maximum_f_stop: maximum_f_stop = f_number f_stop_type_index = i break except PtpException as ptpe: if ptpe.args[0] == 8220: continue except PtpException as e: raise PtpException( "PTP Exception: %s" % PtpValues.ResponseNameById(e.responsecode, vendorId), ptpSession, ptpTransport) except Exception as e: raise Exception(e) # Close the session del ptpSession del ptpTransport if f_stop_type_index == 0: f_stop_type = "third_stops" elif f_stop_type_index == 1: f_stop_type = "half_stops" elif f_stop_type_index == 2: f_stop_type = "full_stops" return (f_stop_type, f_stops[f_stop_type_index].index(minimum_f_stop), f_stops[f_stop_type_index].index(maximum_f_stop))