Esempio n. 1
0
int main(int argc, char *argv[]){
        Camera		*camera;
        GPContext	*context = gp_context_new();
        int		retval;
	CameraEventType evttype;
	void    	*evtdata;
	CameraFile	*file;

        gp_camera_new(&camera);
	retval = gp_camera_init(camera, context);
        if(retval != GP_OK)
        {
                printf("Error: %s\n", gp_result_as_string(retval));
                return 1;
        }

	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

	retval = gp_file_new(&file);
	if (retval != GP_OK) {
		printf("gp_file_new: %d\n", retval);
		return 1;
	}
	/*retval = gp_camera_capture_preview(camera, file, context); */
	if (retval != GP_OK) {
		printf("gp_camera_capture_preview: %d\n", retval);
		return 1;
	}
	gp_file_free (file);

        if(argc == 1)
        {
                retval = camera_auto_focus(camera, context);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
        else if(argc == 2)
        {
                int value = atoi(argv[1]);
                retval = camera_manual_focus(camera, value, context);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

        gp_camera_exit(camera, context);
        return 0;
}
int waitForCaptureComplete() {
	pthread_mutex_lock(&lock);

	int waitTime = 2000;
	CameraEventType type;
	void *data;

	while(1) {
		if(gp_camera_wait_for_event(camera, waitTime, &type, &data, context) == GP_ERROR_NOT_SUPPORTED) {
			printf("camera doesn't support wait.");
			sleep(500); // hopefully this will be enough.
			break;
		}
		if(type == GP_EVENT_TIMEOUT) {
			break;
		}
		else if (type == GP_EVENT_CAPTURE_COMPLETE) {
			waitTime = 100;
		}
		else if (type != GP_EVENT_UNKNOWN) {
			printf("Unexpected event received from camera: %d\n", (int)type);
		}
	}
	pthread_mutex_unlock(&lock);
	return 0;

}
Esempio n. 3
0
CameraEvent Camera::wait_event(int timeout_msec) {
    std::lock_guard<std::mutex> g(mutex);
    CameraEventType eventtype;
	void* eventdata = nullptr;
	int ret = gp_camera_wait_for_event(camera, timeout_msec, &eventtype, &eventdata, ctx->context);
	if (ret < GP_OK)
		throw Exception("gp_camera_wait_for_event", ret);

	CameraEvent::EventType t;
	switch (eventtype) {
	case GP_EVENT_UNKNOWN:
		t = CameraEvent::EVENT_UNKNOWN; break;
	case GP_EVENT_TIMEOUT:
		t = CameraEvent::EVENT_TIMEOUT; break;
	case GP_EVENT_FILE_ADDED:
		t = CameraEvent::EVENT_FILE_ADDED; break;
	case GP_EVENT_FOLDER_ADDED:
		t = CameraEvent::EVENT_FOLDER_ADDED; break;
	case GP_EVENT_CAPTURE_COMPLETE:
		t = CameraEvent::EVENT_CAPTURE_COMPLETE; break;
	default:
		throw std::runtime_error("bad camera event type: " + std::to_string(eventtype));
	}

	return CameraEvent(t, eventdata);
}
void GPhotoCameraWorker::waitForOperationCompleted()
{
    CameraEventType type;
    void *data;
    int ret;

    do {
        ret = gp_camera_wait_for_event(m_camera, 10, &type, &data, m_context);
    } while ((ret == GP_OK) && (type != GP_EVENT_TIMEOUT));
}
Esempio n. 5
0
	int capture_to_file(std::string file_prefix, float exposure,
			std::string iso="1600", std::string aperture="0",
			bool gen_fits=true) {
		int aborted = 0;
		int fd, retval;
		CameraFile *canonfile;
		CameraFilePath camera_file_path;
		set_config_value_string(camera, "iso", iso.c_str(), context);
		if (aperture=="0")
			set_config_value_index(camera, "aperture", 0, context);
		else
			set_config_value_string(camera, "aperture", aperture.c_str(), context);

		printf("Capturing.\n");
		//press shutter, wait for "exposure" seconds, release shutter
		CameraEventType eventtype;
		void* eventdata;
		set_config_value_string(camera, "eosremoterelease", "Press Full", context);
		usleep(exposure*1e6);
		if (errno == EINTR) aborted = 1;
		set_config_value_string(camera, "eosremoterelease", "Release Full", context);

		std::cout << "Waiting for file...\n";
		eventtype = GP_EVENT_UNKNOWN;
		while (eventtype != GP_EVENT_FILE_ADDED) {
			gp_camera_wait_for_event(camera, TIMEOUT, &eventtype, &eventdata, context);
		}
		camera_file_path = *((CameraFilePath*) eventdata);

		printf("Pathname on the camera: %s/%s\n", camera_file_path.folder,
				camera_file_path.name);

		fd = open((file_prefix+".cr2").c_str(),
				O_CREAT | O_WRONLY, 0644);
		retval = gp_file_new_from_fd(&canonfile, fd);
		if (retval != GP_OK) return retval;

		retval = gp_camera_file_get(camera, camera_file_path.folder,
				camera_file_path.name, GP_FILE_TYPE_NORMAL, canonfile,
				context);
		if (retval != GP_OK) return retval;

		retval = gp_camera_file_delete(camera, camera_file_path.folder,
				camera_file_path.name, context);
		if (retval != GP_OK) return retval;

		gp_file_free(canonfile);
		if (gen_fits) produce_fits(file_prefix, aborted);
		return GP_OK;
	}
Esempio n. 6
0
void _camera_poll_events(const dt_camctl_t *c,const dt_camera_t *cam)
{
  CameraEventType event;
  gpointer data;
  if( gp_camera_wait_for_event( cam->gpcam, 30, &event, &data, c->gpcontext ) == GP_OK )
  {
    if( event == GP_EVENT_UNKNOWN )
    {
      /* this is really some undefined behavior, seems like its
      camera driver dependent... very ugly! */
      if( strstr( (char *)data, "4006" ) || // Nikon PTP driver
        (strstr((char *)data, "PTP Property") && strstr((char *)data, "changed"))  // Some Canon driver maybe all ??
      )
      {
        // Property change event occured on camera
        // let's update cache and signalling
        dt_print(DT_DEBUG_CAMCTL, "[camera_control] Camera configuration change event, lets update internal configuration cache.\n");
        _camera_configuration_update(c,cam);
      }
    }
    else if( event == GP_EVENT_FILE_ADDED )
    {
      if( cam->is_tethering )
      {
        dt_print(DT_DEBUG_CAMCTL,"[camera_control] Camera file added event\n");
        CameraFilePath *fp = (CameraFilePath *)data;
        CameraFile *destination;
        const char *output_path = _dispatch_request_image_path(c,cam);
        if( !output_path ) output_path="/tmp";
        const char *fname = _dispatch_request_image_filename(c,fp->name,cam);
        if( !fname ) fname=fp->name;

        char *output = g_build_filename(output_path,fname,(char *)NULL);

        int handle = open( output, O_CREAT | O_WRONLY,0666);
        gp_file_new_from_fd( &destination , handle );
        gp_camera_file_get( cam->gpcam, fp->folder , fp->name, GP_FILE_TYPE_NORMAL, destination,  c->gpcontext);
        close( handle );

        // Notify listerners of captured image
        _dispatch_camera_image_downloaded(c,cam,output);
        g_free(output);
      }
    }
  }
}
Esempio n. 7
0
//GET THREAD
//Gets Files over USB. Camera -> Memory
void * GetEvents(void*aaa){
    CameraFile* my_File;
    CameraEventType my_Type;
    void* retevent;
    struct timespec time;
    char filename[40];
    while(1){
        CameraControl();
        do{
            //Wait for camera to fire an event. Most are useless/not used by us
            //When a picture is taken (triggered on camera), FILE_ADDED event fired
            //retevent will contain a CameraFilePath object with name/loc on camera of file
            //Timeout is 100 <units, probably ms>
            gp_camera_wait_for_event(getMyCamera(), 100, &my_Type, &retevent, getMyContext());
            if(my_Type == GP_EVENT_FILE_ADDED){
                CameraFilePath* my_FP = (CameraFilePath*)retevent;

                gp_file_new(&my_File);

                //Get the file from the given location to memory
                gp_camera_file_get(getMyCamera(), my_FP->folder, my_FP->name, GP_FILE_TYPE_NORMAL, my_File, getMyContext());

                //Get time in ms since Epoch -> used for filename for Skynet purposes
                clock_gettime(CLOCK_REALTIME, &time);
                long long time_millis = time.tv_sec * 1000 + time.tv_nsec / 1000000; 
                sprintf(filename, "%s/%llu.jpg", ImagesFolder.c_str(), time_millis);
                
                AddFile(my_File, filename);

                //Save the last obtained Telemetry/GPS to disk, with the same filename we just used
                saveLast(time_millis);

                //Tell the Save Thread that there is a new CameraFile enqueued
                sem_post(&NewFileSem);
                free(my_FP);
            }
        } while(decrementWaitCounter() > 0); 
        //WaitCounter is a variable used to cycle through images possibly still on the camera
        //Used to cycle out images before switching quality, see CameraControl.c
        setWaitCounter(0); 
    }
    return NULL;
}
Esempio n. 8
0
int main(int argc, char **argv) {
	Camera		*camera = NULL;
	int		ret;
	GPContext	*context;
	CameraWidget	*rootwidget;
	char		buf[200];
	CameraText	summary;

        gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL);

	context = sample_create_context (); /* see context.c */

	strcpy(buf,"usb:");
	if (argc > 1)
		strcat (buf, argv[1]);

	fprintf(stderr,"setting path %s.\n", buf);

	ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context);
        if (ret < GP_OK) {
		fprintf(stderr,"camera %s not found.\n", buf);
		goto out;
	}

	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		fprintf(stderr,"No camera auto detected.\n");
		goto out;
	}

	/* AFL PART STARTS HERE */

	ret = recursive_directory(camera, "/", context, NULL);
	if (ret < GP_OK) {
		printf ("Could not recursive list files.\n");
		goto out;
	}

	ret = gp_camera_get_summary (camera, &summary, context);
	if (ret < GP_OK) {
		printf ("Could not get summary.\n");
		goto out;
	}

#if 1
	ret = gp_camera_get_config (camera, &rootwidget, context);
	if (ret < GP_OK) {
		fprintf (stderr,"Could not get config.\n");
		goto out;
	}
#endif
	printf ("OK, %s\n", summary.text);
	while (1) {
		CameraEventType evttype;
		void *data = NULL;

		ret = gp_camera_wait_for_event(camera, 1, &evttype, &data, context);
		if (ret < GP_OK) break;
		if (data) free (data);
		if (evttype == GP_EVENT_TIMEOUT) break;
	}

	/* AFL PART ENDS HERE */
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}