Ejemplo n.º 1
0
void capture(const EdsCameraRef handle, \
			const double isoSpeedDouble, const double apertureValueDouble, \
			const double shutterSpeedDouble) {

	EdsError errorCode = EDS_ERR_OK;

	EdsUInt32 isoSpeed = isoSpeedDoubleToEds(isoSpeedDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_ISOSpeed, 0,
								sizeof(isoSpeed), &isoSpeed);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	EdsUInt32 apertureValue = apertureValueDoubleToEds(apertureValueDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_Av, 0,
								sizeof(apertureValue), &apertureValue);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	EdsUInt32 shutterSpeed = shutterSpeedDoubleToEds(shutterSpeedDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_Tv, 0,
								sizeof(shutterSpeed), &shutterSpeed);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	snap(handle);
}
Ejemplo n.º 2
0
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::beginLiveView(){
        printf("Begining live view\n");

        preCommand();
	

        EdsError err = EDS_ERR_OK;

		if(evfMode == 0){
			evfMode = 1;
			// Set to the camera.
			err = EdsSetPropertyData(theCamera, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode);			
		}

		if( err == EDS_ERR_OK){
			// Set the PC as the current output device.
			device = kEdsEvfOutputDevice_PC;

			// Set to the camera.
			err = EdsSetPropertyData(theCamera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
		}

		//Notification of error
		if(err != EDS_ERR_OK){
			// It doesn't retry it at device busy
			if(err == EDS_ERR_DEVICE_BUSY){
				printf("BeginLiveView - device is busy\n");
				//CameraEvent e("DeviceBusy");
				//_model->notifyObservers(&e);
			}else{
				printf("BeginLiveView - device is busy\n");
			}
			return false;
		}
    }
void
Controller::stopVideo()
{
    int result = EDS_ERR_OK;

    /*
     *  Check whether already not in movie recording mode.
     */
    if( camera->getRecordMode() == Map::RecordModeStop ) {
	return;
    }

    /*
     *  Stop movie shooting.
     */
    uint recordStop = Map::RecordModeStop;
    result = EdsSetPropertyData( camera->handle(),
		kEdsPropID_Record,
		0,
		sizeof(recordStop),
		&recordStop );

    /*
     *  Will also be set through a callback from the camera.
     */
    if( result == EDS_ERR_OK ) {
	camera->setRecordMode( Map::RecordModeStop );
    }

    /*
     *  Restore the previous setting for destination of images.
     */
    setPropertyCommand( kEdsPropID_SaveTo, saveSaveTo );
}
Ejemplo n.º 4
0
int CanonEDCamera::Shutdown()
{
   // save images on the memory card
   if (isLegacy_)
      EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UILock, 0);
   EdsSaveTo toCamera = kEdsSaveTo_Camera;
   EdsError err = EdsSetPropertyData(camera_,  kEdsPropID_SaveTo, 0 , sizeof(EdsSaveTo),  &toCamera);
   if (isLegacy_)
      EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UIUnLock, 0);

   // Close session with camera 
   err = EdsCloseSession(camera_); 
    
   // Release camera 
   if(camera_ != NULL) 
   { 
      EdsRelease(camera_); 
   } 
    
   // Terminate SDK 
   if(isSDKLoaded_) 
   { 
      EdsTerminateSDK(); 
   }

   return DEVICE_OK;
}
bool
Controller::startVideo()
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    /*
     *  Camera must be set to movie shooting mode.
     *  On some cameras video mode is a shooting mode;
     *  on others it is a separate switch.
     */
    if( (camera->getShootingMode() != kEdsAEMode_Movie) &&
	(camera->getEvfMode() != 2) ) {
	emit eventReport( new Event( Event::NotVideoMode ) );
	return( false );
    }

    /*
     *  Get current record mode.
     *  Nothing to do if already recording a movie.
     */
    int recordMode = camera->getRecordMode();
    if( recordMode == Map::RecordModeStart ) {
	return( true );
    }

    /*
     *  Save video on camera (as cannot transfer directly to PC).
     *  Remember the current setting so it can be restored when
     *  video recording is terminated.
     */
    saveSaveTo = camera->getSaveTo();
    if( !setPropertyCommand( kEdsPropID_SaveTo, kEdsSaveTo_Camera ) ) {
	setPropertyCommand( kEdsPropID_SaveTo, saveSaveTo );
	return( false );
    }

    int result = EDS_ERR_OK;

    /*
     *  Begin movie shooting.
     */
    uint recordStart = Map::RecordModeStart;
    result = EdsSetPropertyData( camera->handle(),
		kEdsPropID_Record,
		0,
		sizeof(recordStart),
		&recordStart );
    /*
     *  Will also be set through a callback from the camera.
     */
    if( result == EDS_ERR_OK ) {
	camera->setRecordMode( Map::RecordModeStart );
    }

    return( result == EDS_ERR_OK );
}
bool
Controller::setPropertyCommand( int property, QDateTime dateTime )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    if( property != kEdsPropID_DateTime ) {
	emit eventReport( new Event( Event::SetPropertyUnhandled, property ) );
	return( false );
    }

    /*
     *  Check camera model to ensure the new value is different
     *  from the current value.
     */
    if( dateTime == camera->getDateTime() ) {
	return( true );
    }

    /*
     *  Send the command to the camera.
     */
    EdsTime time;

    QDate d = dateTime.date();
    time.year = d.year();
    time.month = d.month();
    time.day = d.day();

    QTime t = dateTime.time();
    time.hour = t.hour();
    time.minute = t.minute();
    time.second = t.second();

    int result = EdsSetPropertyData(
			camera->handle(),
			property,
			0,
			28,
			&time );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
	    property, "setProperty" ) );
	return( false );
    }

    /*
     *  Update the camera model.
     */
    camera->setDateTime( dateTime );

    return( true );
}
bool
Controller::setFocusPropertyCommand( int selectionMode, int fp )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    /*
     *  Check camera model to ensure the new value is different
     *  from the current value.
     */
    EdsFocusInfo focusInfo = camera->getFocusInfo();
    if(    ((focusInfo.executeMode == Map::FP_AutomaticSelection) &&
	    (selectionMode == Map::FP_AutomaticSelection))
	|| ((focusInfo.executeMode == Map::FP_ManualSelection) &&
	    (selectionMode == Map::FP_ManualSelection) &&
	    (focusInfo.focusPoint[fp].selected == 1)) ) {
	return( true );
    }

    /*
     *  Send the command to the camera.
     *  If automatic selection mode, all focus points are selected.
     *  If manual selection mode, only one focus point is selected.
     */
    focusInfo.executeMode = selectionMode;
    const int mark = (selectionMode == Map::FP_AutomaticSelection);
    for( int i = 0; i < 128; i++ ) if( focusInfo.focusPoint[i].valid ) {
	focusInfo.focusPoint[i].selected = mark;
    }
    if( selectionMode == Map::FP_ManualSelection ) {
	focusInfo.focusPoint[fp].selected = 1;
    }

    int result = EdsSetPropertyData(
			camera->handle(),
			kEdsPropID_FocusInfo,
			0,
			4120,
			&focusInfo );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
	    kEdsPropID_FocusInfo, "setFocusProperty" ) );
	return( false );
    }

    /*
     *  Update the camera model.
     */
    camera->setFocusInfo( focusInfo );

    return( true );
}
Ejemplo n.º 8
0
    EdsError Camera::requestOpenSession(const Settings &settings) {
        if (mHasOpenSession) {
            return EDS_ERR_SESSION_ALREADY_OPEN;
        }
        
        EdsError error = EdsOpenSession(mCamera);
        if (error != EDS_ERR_OK) {
            std::cerr << "ERROR - failed to open camera session" << std::endl;
            return error;
        }
        mHasOpenSession = true;
        
        mShouldKeepAlive = settings.getShouldKeepAlive();
        EdsUInt32 saveTo = settings.getPictureSaveLocation();
        error = EdsSetPropertyData(mCamera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo);
        if (error != EDS_ERR_OK) {
            std::cerr << "ERROR - failed to set save destination host/device" << std::endl;
            return error;
        }
        

		//UI lock
		if (error == EDS_ERR_OK)
		{
			error = EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UILock, 0);
		}

		if (error == EDS_ERR_OK)
		{
			mIsLocked = true;
		}


        if (saveTo == kEdsSaveTo_Host) {
            // ??? - requires UI lock?
            EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
            error = EdsSetCapacity(mCamera, capacity);
            if (error != EDS_ERR_OK) {
                std::cerr << "ERROR - failed to set capacity of host" << std::endl;
                return error;
            }
        }
        
		//It releases it when locked
		if (mIsLocked)
		{
			EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UIUnLock, 0);
		}

        return EDS_ERR_OK;
    }
Ejemplo n.º 9
0
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::endLiveView(){
        printf("Ending live view\n");

        EdsError err = EDS_ERR_OK;

		if( err == EDS_ERR_OK){
			// Set the PC as the current output device.
			device = kEdsEvfOutputDevice_TFT;

			// Set to the camera.
			err = EdsSetPropertyData(theCamera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device);
		}

		if(evfMode == 1){
			evfMode = 0;
			// Set to the camera.
			err = EdsSetPropertyData(theCamera, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode);
		}

		bool success = true;

		//Notification of error
		if(err != EDS_ERR_OK){
			// It doesn't retry it at device busy
			if(err == EDS_ERR_DEVICE_BUSY){
				printf("EndLiveView - device is busy\n");
				//CameraEvent e("DeviceBusy");
				//_model->notifyObservers(&e);
			}else{
				printf("EndLiveView - device is busy\n");
			}
			success = false;
		}

		postCommand();

		return success;
    }
Ejemplo n.º 10
0
    void Camera::startLiveView()
    {
        std::cout << "start live view" << std::endl;
        EdsError err = EDS_ERR_OK;
		// Get the current output device.
		EdsUInt32 evfMode;
		err = EdsSetPropertyData(mCamera, kEdsPropID_Evf_Mode, 0, sizeof(evfMode), &evfMode);
        // Get the output device for the live view image
        EdsUInt32 device;
        err = EdsGetPropertyData(mCamera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device );
        
        // PC live view starts by setting the PC as the output device for the live view image.
        if(err == EDS_ERR_OK)
        {
            device |= kEdsEvfOutputDevice_PC;
            err = EdsSetPropertyData(mCamera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
            mIsLiveView = true;
			std::cout << "live Vido success" << std::endl;
			std::cout << err << std::endl;
        }
        
        // A property change event notification is issued from the camera if property settings are made successfully.
        // Start downloading of the live view image once the property change notification arrives.
    }
bool
Controller::setPropertyCommand( int property, int *s )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    if( property != kEdsPropID_WhiteBalanceShift ) {
	emit eventReport( new Event( Event::SetPropertyUnhandled, property ) );
	return( false );
    }

    /*
     *  Send the command to the camera.
     */
    int shift[256];	// unclear how large this needs to be, but > 8
    shift[0] = s[0];
    shift[1] = s[1];
    int result = EdsSetPropertyData(
			camera->handle(),
			property,
			0,
			8,	// size of data in bytes
			&shift );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
	    property, "setProperty" ) );
	return( false );
    }

    /*
     *  Commands are not accepted for a while when white
     *  balance has been shifted.
     */
    if( result == EDS_ERR_OK ) {
	Sleep( 250 );       // milliseconds
    }

    /*
     *  Update the camera model.
     */
    camera->setWhiteBalanceShift( shift );

    return( true );
}
Ejemplo n.º 12
0
 void Camera::endLiveView()
 {
     std::cout << "end live view" << std::endl;
     EdsError err = EDS_ERR_OK;
     
     // Get the output device for the live view image
     EdsUInt32 device;
     err = EdsGetPropertyData(mCamera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device );
     
     // PC live view ends if the PC is disconnected from the live view image output device.
     if(err == EDS_ERR_OK)
     {
         device &= ~kEdsEvfOutputDevice_PC;
         err = EdsSetPropertyData(mCamera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
     }
     
     mIsLiveView = false;
 }
/*
 *  Command to move the zoom rectangle in live view.
 */
bool
Controller::moveZoomRectCommand( int x, int y )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    int result = EDS_ERR_OK;

    /*
     *  Check camera model to ensure the new values are
     *  different from the current values.
     */
    QPoint currentPosition = camera->getEvfZoomPosition();
    if( (currentPosition.x() == x) && (currentPosition.y() == y) ) {
	return( true );
    }

    /*
     *  Send the command to the camera.
     */
    EdsPoint point;
    point.x = x;
    point.y = y;
    result = EdsSetPropertyData(
		    camera->handle(),
		    kEdsPropID_Evf_ZoomPosition,
		    0,
		    sizeof(point),
		    &point );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
		kEdsPropID_Evf_ZoomPosition, "moveZoomRect" ) );
	return( false );
    }

    /*
     *  Update the camera model.
     */
    camera->setEvfZoomPosition( QPoint(x, y) );

    return( true );
}
bool CanonTaskOpenSession::execute() {

  if(canon->isLegacy()) {
    RX_ERROR("We did not implement and tested the canon video capture implementation for legacy devices (<30D)");
    ::exit(EXIT_FAILURE);
  }

  if(canon->getState() != Canon::STATE_NONE) {
    RX_ERROR("The device hasn't been opened so we cannot open the session either");
    return false;
  }

  EdsError err = EdsOpenSession(canon->getCameraRef());
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }  
  
  EdsUInt32 save_to = kEdsSaveTo_Host;
  err = EdsSetPropertyData(canon->getCameraRef(), kEdsPropID_SaveTo, 0, sizeof(save_to), &save_to);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }
  
  if(!canon->lockUI()) {
    return false;
  }

  EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
  err = EdsSetCapacity(canon->getCameraRef(), capacity);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }

  if(!canon->unlockUI()) {
    return false;
  }

  canon->setStateOpened();

  return true;
}
EdsError CanonCamera::endLiveview()
{
	EdsError err = EDS_ERR_OK;

	// Get the output device for the live view image
	EdsUInt32 device;
	err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device );
	
	if(err == EDS_ERR_OK)
	{
		device &= ~kEdsEvfOutputDevice_PC;
		err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
	}

	cvDestroyWindow(windowName.c_str());

	liveView=false;

	return err;
}
EdsError CanonCamera::startLiveview()
{

	cvNamedWindow(windowName.c_str(),CV_WINDOW_AUTOSIZE);
	cvResizeWindow(windowName.c_str(),640,480);

	EdsError err = EDS_ERR_OK;

	EdsUInt32 device;
	err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device );
	
	if(err == EDS_ERR_OK)
	{
		device |= kEdsEvfOutputDevice_PC;
		err = EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , sizeof(device), &device);
	}

	liveView = true;
	return err;
}
Ejemplo n.º 17
0
boolean connectToFirstCamera(){
	
	EdsError err = EDS_ERR_OK;

	// Initialize SDK
	err = EdsInitializeSDK();
	if ( err == EDS_ERR_OK )
		isSDKLoaded = true;


/*	// Get first camera
	if(err == EDS_ERR_OK)
	{
		err = getFirstCamera();
	}*/

	EdsCameraListRef cameraList = NULL;
	EdsUInt32 count = 0;

	// Get camera list
	err = EdsGetCameraList(&cameraList);

	// Get number of cameras
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildCount(cameraList, &count);
		if(count == 0)
		{
			err = EDS_ERR_DEVICE_NOT_FOUND;
		}
	}

	// Get first camera retrieved
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildAtIndex(cameraList , 0 , &camera);
	}

	// Release camera list
	if(cameraList != NULL)
	{
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	//Open Session
	if(err == EDS_ERR_OK)
	{
		err = EdsOpenSession(camera);
	}

	//Set save to host
	if (err == EDS_ERR_OK ) {
		EdsUInt32 wkSaveTo = kEdsSaveTo_Host ;
		do {
			err = EdsSetPropertyData ( camera, kEdsPropID_SaveTo, 
				0, 4, (void*)&wkSaveTo ) ;
			if (err != EDS_ERR_OK) {
				std::cout << "warning: camera busy, waiting..." << std::endl;
				std::flush(std::cout);
				Sleep(100);
			}
		} while (err != EDS_ERR_OK);
	}

	// Set host capacity
	EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
	err = EdsSetCapacity ( camera, capacity );

	return err == EDS_ERR_OK;
}
Ejemplo n.º 18
0
 void Camera::captureLoop() {
     if(liveViewReady) {
         if(Eds::DownloadEvfData(camera, *liveBufferBack)) {
             lock();
             fps.tick();
             bytesPerFrame = ofLerp(bytesPerFrame, liveBufferBack->size(), .01);
             swap(liveBufferBack, liveBufferMiddle.back());
             liveBufferMiddle.push();
             unlock();
         }
     }
     
     if(needToTakePhoto) {
         try {
             
             if (shootNoCard) {
                 EdsUInt32 saveTo = kEdsSaveTo_Host;
                 EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo), &saveTo);
                 
                 EdsCapacity maxCapacity = {0x7FFFFFFF, 0x1000, 1};
                 EdsSetCapacity(camera, maxCapacity );
             } else {
                 EdsUInt32 saveTo = kEdsSaveTo_Camera;
                 EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo), &saveTo);
             }
             
             
             Eds::SendCommand(camera, kEdsCameraCommand_TakePicture, 0);
             lock();
             needToTakePhoto = false;
             unlock();
             //ofSendMessage("test");
         } catch (Eds::Exception& e) {
             ofLogError() << "Error while taking a picture: " << e.what();
             //ofSendMessage("Error: " + ofToString(e.what()));
         }
     }
     
     if(needToStartRecording) {
         try {
             EdsUInt32 saveTo = kEdsSaveTo_Camera;
             EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo);
             
             EdsUInt32 record_start = 4; // Begin movie shooting
             EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_start), &record_start);
             lock();
             needToStartRecording = false;
             unlock();
         } catch (Eds::Exception& e) {
             ofLogError() << "Error while beginning to record: " << e.what();
         }
     }
     
     if(needToStopRecording) {
         try {
             EdsUInt32 record_stop = 0; // End movie shooting
             EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_stop), &record_stop);
             lock();
             needToStopRecording = false;
             unlock();
         } catch (Eds::Exception& e) {
             ofLogError() << "Error while stopping to record: " << e.what();
         }
     }
     
     if(needToSendKeepAlive) {
         try {
             // always causes EDS_ERR_DEVICE_BUSY, even with live view disabled or a delay
             // but if it's not here, then the camera shuts down after 5 minutes.
             Eds::SendStatusCommand(camera, kEdsCameraCommand_ExtendShutDownTimer, 0);
         } catch (Eds::Exception& e) {
             ofLogError() << "Error while sending kEdsCameraCommand_ExtendShutDownTimer with Eds::SendStatusCommand: " << e.what();
         }
         lock();
         needToSendKeepAlive = false;
         unlock();
     }
     
     if(needToDownloadImage) {
         try {
             EdsDirectoryItemInfo dirItemInfo = Eds::DownloadImage(directoryItem, photoBuffer);
             ofLogVerbose() << "Downloaded item: " << (int) (photoBuffer.size() / 1024) << " KB";
             lock();
             photoDataReady = true;
             needToDecodePhoto = true;
             needToUpdatePhoto = true;
             needToDownloadImage = false;
             
             if (dirItemInfo.format == OFX_EDSDK_JPG_FORMAT) {
                 photoNew = true;
             } else if (dirItemInfo.format == OFX_EDSDK_MOV_FORMAT) {
                 movieNew = true;
             }
             
             unlock();
         } catch (Eds::Exception& e) {
             ofLogError() << "Error while downloading item: " << e.what();
         }
     }
     
     float timeSinceLastReset = ofGetElapsedTimef() - lastResetTime;
     if(timeSinceLastReset > resetIntervalMinutes * 60) {
         resetLiveView();
     }
     
 }
Ejemplo n.º 19
0
int CanonEDCamera::Initialize()
{
   EdsError err = EDS_ERR_OK; 
    
   // Initialize SDK 
   err = EdsInitializeSDK(); 
   if(err == EDS_ERR_OK) 
   { 
     isSDKLoaded_ = true; 
   } 
    
   // Get first camera 
   if(err == EDS_ERR_OK) 
   { 
      err = getFirstCamera (&camera_); 
   } 

   if (err == EDS_ERR_DEVICE_NOT_FOUND)
      return ERR_NO_CAMERA;
    

   // event handlers are static functions that need a reference to this camera object to function
   // provide that static ref here.  This approach will fail with multiple cameras.  In that case, 
   // consider making a map with cameras and references to our CanonEDCamera objects
   g_Self = this;

   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetObjectEventHandler(camera_,  kEdsObjectEvent_All, &CanonEDCamera::handleObjectEvent,  NULL); 
   } 
    
   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetPropertyEventHandler(camera_,  kEdsPropertyEvent_All, &CanonEDCamera::handlePropertyEvent,  NULL); 
   } 
    
   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetCameraStateEventHandler(camera_,  kEdsStateEvent_All, &CanonEDCamera::handleStateEvent,  NULL); 
   } 

   if(err == EDS_ERR_OK) 
   { 
      err = EdsOpenSession(camera_); 
   } 
     
   // Camera name
   if (err == EDS_ERR_OK)
   {
      EdsDeviceInfo  deviceInfo;
      err = EdsGetDeviceInfo(camera_, &deviceInfo);
      if (err == EDS_ERR_OK)
      {
         std::ostringstream os;
         os << "Canon SLR device subtype: " << deviceInfo.deviceSubType;
         LogMessage(os.str().c_str());
         if (deviceInfo.deviceSubType == 0)
            isLegacy_ = true;
         cameraModel_ = deviceInfo.szDeviceDescription;
         int nRet = CreateProperty("Model", cameraModel_.c_str(), MM::String, true);
         if (nRet != DEVICE_OK)
            return nRet;
      }

      // Set and Get various camera properties

      // lock the UI before setting properties - only needed on legacy cameras
      if (isLegacy_)
         EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UILock, 0);
      EdsSaveTo toPC = kEdsSaveTo_Host;
      err = EdsSetPropertyData(camera_,  kEdsPropID_SaveTo, 0 , sizeof(EdsSaveTo),  &toPC);
      if (isLegacy_)
         EdsSendStatusCommand (camera_, kEdsCameraStatusCommand_UIUnLock, 0);
   }

   if (err == EDS_ERR_OK)
   {
      CPropertyAction* pAct = new CPropertyAction(this, &CanonEDCamera::OnBinning);
      int nRet = CreateProperty(MM::g_Keyword_Binning, "1", MM::Integer, false, pAct);
      if (nRet != DEVICE_OK)
         return nRet;
   }

   if (err == EDS_ERR_OK)
   {
      return DEVICE_OK;
   }

   std::ostringstream os;
   os << "Error during initialization: " << std::hex << err;
   LogMessage(os.str().c_str());

   return err;
}
bool
Controller::setPropertyCommand( int property, QString string )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    if( (property != kEdsPropID_Artist) &&
	(property != kEdsPropID_Copyright) ) {
	emit eventReport( new Event( Event::SetPropertyUnhandled, property ) );
	return( false );
    }

    const int MAX_SIZE = 64;

    char s[MAX_SIZE];
    for( int i = 0; (i < string.size()) && (i < MAX_SIZE); i++ ) {
	s[i] = string.at(i).toAscii();
    }
    s[string.size()] = '\0';

    /*
     *  Check camera model to ensure the new value is different
     *  from the current value.
     */
    if( (property == kEdsPropID_Artist) &&
	(strncmp(s, camera->getAuthorName(), MAX_SIZE) == 0) ) {
	return( true );
    }
    else
    if( (property == kEdsPropID_Copyright) &&
	(strncmp(s, camera->getCopyright(), MAX_SIZE) == 0) ) {
	return( true );
    }

    int result = EDS_ERR_OK;

    /*
     *  Retry if camera device is busy.
     */
    do {

	/*
	 *  Send the command to the camera.
	 */
	result = EdsSetPropertyData(
			camera->handle(),
			property,
			0,
			MAX_SIZE,	// size in bytes
			&s );

	/*
	 *  If retry is required, the camera may become unstable if multiple
	 *  commands are issued in succession without an intervening interval.
	 *  So, put a delay in before command is reissued.
	 */
	if( result == EDS_ERR_DEVICE_BUSY ) {
	    emit eventReport( new Event( Event::CameraBusy, 0,
		QString( "setProperty" ) ) );
	    QCoreApplication::processEvents();
	    Sleep( 500 );	// milliseconds
	}

    } while( result == EDS_ERR_DEVICE_BUSY );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
	    property, "setProperty" ) );
	return( false );
    }

    /*
     *  Update the camera model.
     */
    if( result == EDS_ERR_OK ) {
	switch( property ) {
	    case kEdsPropID_Artist:    camera->setAuthorName( s ); break;
	    case kEdsPropID_Copyright: camera->setCopyright( s );  break;
	}
    }

    return( true );
}
bool
Controller::setPropertyCommand( int property, int newValue, int parameter )
{
    if( camera->handle() == 0 ) {
	return( false );
    }

    /*
     *  Check camera model to ensure the new value is different
     *  from the current value.
     */
    bool done = false;
    switch( property ) {
	case kEdsPropID_AEModeSelect:
	    done = (newValue == camera->getShootingMode());
	    break;
	case kEdsPropID_Av:
	    done = (newValue == camera->getAv());
	    break;
	case kEdsPropID_Tv:
	    done = (newValue == camera->getTv());
	    break;
	case kEdsPropID_ISOSpeed:
	    done = (newValue == camera->getISO());
	    break;
	case kEdsPropID_MeteringMode:
	    done = (newValue == camera->getMeteringMode());
	    break;
	case kEdsPropID_DriveMode:
	    done = (newValue == camera->getDriveMode());
	    break;
	case kEdsPropID_AFMode:
	    done = (newValue == camera->getAFMode());
	    break;
	case kEdsPropID_WhiteBalance:
	    done = (newValue == camera->getWhiteBalance());
	    break;
	case kEdsPropID_ColorSpace:
	    done = (newValue == camera->getColorSpace());
	    break;
	case kEdsPropID_PictureStyle:
	    done = (newValue == camera->getPictureStyle());
	    break;
	case kEdsPropID_ImageQuality:
	    done = (newValue == camera->getImageQuality());
	    break;
	case kEdsPropID_Evf_Zoom:
	    done = (newValue == camera->getEvfZoom());
	    break;
	case kEdsPropID_Evf_AFMode:
	    done = (newValue == camera->getEvfAFMode());
	    break;
	case kEdsPropID_Evf_DepthOfFieldPreview:
	    done = (newValue == camera->getEvfDepthOfFieldPreview());
	    break;
	case kEdsPropID_ExposureCompensation:
	    done = (newValue == camera->getExposureComp());
	    break;
	case kEdsPropID_SaveTo:
	    done = (newValue == camera->getSaveTo());
	    break;
	case kEdsPropID_CFn:
	    switch( parameter ) {
		case CFn_ExposureLevelIncrements:
		    done = (newValue == camera->getExposureLevelIncrements());
		    break;
		case CFn_FlashSyncSpeedInAvMode:
		    done = (newValue == camera->getFlashSyncSpeedInAvMode());
		    break;
		case CFn_LongExposureNoiseReduction:
		    done = (newValue == camera->getLongExposureNoiseReduction());
		    break;
		case CFn_HighISOSpeedNoiseReduction:
		    done = (newValue == camera->getHighISOSpeedNoiseReduction());
		    break;
		case CFn_AutoFocusAssistBeamFiring:
		    done = (newValue == camera->getAutoFocusAssistBeamFiring());
		    break;
		case CFn_MirrorLockup:
		    done = (newValue == camera->getMirrorLockup());
		    break;
		case CFn_ShutterAELockButton:
		    done = (newValue == camera->getShutterAELockButton());
		    break;
	    }
	    break;
	default:
	    emit eventReport( new Event( Event::SetPropertyUnhandled, property ) );
	    return( false );
    }
    if( done ) {
	return( true );
    }

    int result = EDS_ERR_OK;

    /*
     *  Retry if camera device is busy.
     */
    do {

	/*
	 *  Send the command to the camera.
	 */
	result = EdsSetPropertyData(
			camera->handle(),
			property,
			parameter,
			sizeof(newValue),
			&newValue );

	/*
	 *  Commands are not accepted for a while when depth
	 *  of field preview has been released.
	 */
	if( (result == EDS_ERR_OK) &&
	    (property == kEdsPropID_Evf_DepthOfFieldPreview) ) {
	    Sleep( 500 );       // milliseconds
	}

	/*
	 *  If retry is required, the camera may become unstable if multiple
	 *  commands are issued in succession without an intervening interval.
	 *  So, put a delay in before command is reissued.
	 */
	if( result == EDS_ERR_DEVICE_BUSY ) {
	    emit eventReport( new Event( Event::CameraBusy, 0,
		QString( "setProperty" ) ) );
	    QCoreApplication::processEvents();
	    Sleep( 500 );	// milliseconds
	}

    } while( result == EDS_ERR_DEVICE_BUSY );

    if( result != EDS_ERR_OK ) {
	emit eventReport( new Event( Event::SetPropertyFailure,
	    property, "setProperty" ) );
	return( false );
    }

    /*
     *  Set the capacity of the computer (false values are used).
     *
     *  typedef struct *  {
     *      EdsInt32        numberOfFreeClusters;
     *      EdsInt32        bytesPerSector;
     *      EdsBool         reset;
     *  } EdsCapacity;
     */
    if( (result == EDS_ERR_OK) &&
	(property == kEdsPropID_SaveTo) &&
       ((newValue == kEdsSaveTo_Host) || (newValue == kEdsSaveTo_Both)) ) {
	EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
	result = EdsSetCapacity( camera->handle(), capacity );
    }

    /*
     *  Update the camera model.
     */
    if( result == EDS_ERR_OK ) {
	switch( property ) {
	    case kEdsPropID_AEModeSelect:
		camera->setShootingMode( newValue );
		break;
	    case kEdsPropID_Av:
		camera->setAv( newValue );	
		break;
	    case kEdsPropID_Tv:
		camera->setTv( newValue );	
		break;
	    case kEdsPropID_ISOSpeed:
		camera->setISO( newValue );	
		break;
	    case kEdsPropID_MeteringMode:
		camera->setMeteringMode( newValue );
		break;
	    case kEdsPropID_DriveMode:
		camera->setDriveMode( newValue );
		break;
	    case kEdsPropID_AFMode:
		camera->setAFMode( newValue );
		break;
	    case kEdsPropID_WhiteBalance:
		camera->setWhiteBalance( newValue );
		break;
	    case kEdsPropID_ColorSpace:
		camera->setColorSpace( newValue );
		break;
	    case kEdsPropID_PictureStyle:
		camera->setPictureStyle( newValue );
		break;
	    case kEdsPropID_ImageQuality:
		camera->setImageQuality( newValue );
		break;
	    case kEdsPropID_Evf_Zoom:
		camera->setEvfZoom( newValue );
		break;
	    case kEdsPropID_Evf_AFMode:
		camera->setEvfAFMode( newValue );
		break;
	    case kEdsPropID_Evf_DepthOfFieldPreview:
		camera->setEvfDepthOfFieldPreview( newValue );
		break;
	    case kEdsPropID_ExposureCompensation:
		camera->setExposureComp( newValue );
		break;
	    case kEdsPropID_SaveTo:
		camera->setSaveTo( newValue );
		break;
	    case kEdsPropID_CFn:
		switch( parameter ) {
		    case CFn_ExposureLevelIncrements:
			camera->setExposureLevelIncrements( newValue );
			break;
		    case CFn_FlashSyncSpeedInAvMode:
			camera->setFlashSyncSpeedInAvMode( newValue );
			break;
		    case CFn_LongExposureNoiseReduction:
			camera->setLongExposureNoiseReduction( newValue );
			break;
		    case CFn_HighISOSpeedNoiseReduction:
			camera->setHighISOSpeedNoiseReduction( newValue );
			break;
		    case CFn_AutoFocusAssistBeamFiring:
			camera->setAutoFocusAssistBeamFiring( newValue );
			break;
		    case CFn_MirrorLockup:
			camera->setMirrorLockup( newValue );
			break;
		    case CFn_ShutterAELockButton:
			camera->setShutterAELockButton( newValue );
			break;
		}
		break;
	}
    }

    return( true );
}
Ejemplo n.º 22
0
bool setTv(int tv) {
	EdsError err = EdsSetPropertyData(camera, kEdsPropID_Tv, 0, sizeof(EdsInt32), &tv);
	return !err;
}
Ejemplo n.º 23
0
void setCameraProperty(const EdsCameraRef handle, \
							const CAMERA_PROPERTY property, \
							const mxArray* mxarr) {

	switch(property) {
		case CAMERA_AEMODE: {
			EdsUInt32 AEMode = AEModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_AEMode, 0,
													sizeof(AEMode),
													&AEMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_DRIVEMODE: {
			EdsUInt32 driveMode = driveModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_DriveMode, 0,
													sizeof(driveMode),
													&driveMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_IMAGEQUALITY: {
			EdsUInt32 imageQuality = imageQualityDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_ImageQuality, 0,
													sizeof(imageQuality),
													&imageQuality);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_ISOSPEED: {
			EdsUInt32 isoSpeed = isoSpeedDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_ISOSpeed, 0,
													sizeof(isoSpeed),
													&isoSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_APERTUREVALUE: {
			EdsUInt32 apertureValue = apertureValueDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Av, 0,
													sizeof(apertureValue),
													&apertureValue);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_SHUTTERSPEED: {
			EdsUInt32 shutterSpeed = shutterSpeedDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Tv, 0,
													sizeof(shutterSpeed),
													&shutterSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_EVFOUTPUTDEVICE: {
			EdsUInt32 evfOutputDevice = evfOutputDeviceDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_OutputDevice, 0,
													sizeof(evfOutputDevice),
													&evfOutputDevice);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_EVFMODE: {
			EdsUInt32 evfMode = evfModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_Mode, 0,
													sizeof(evfMode),
													&evfMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_SAVETO: {
			EdsUInt32 saveTo = saveToDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_Mode, 0,
													sizeof(saveTo),
													&saveTo);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		default:
		{
			char propertyName[canon_MAX_STRING_LENGTH];
			cameraPropertyToString(property, propertyName);
			mexErrMsgIdAndTxt(ERROR_ID, "Unknown or unsupported camera property: %s.", propertyName);
		}
	}
}