Created
August 9, 2021 16:07
-
-
Save natxopedreira/c647b334acf6356ad4ebef6691140867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GPhoto::initialize(int id) { | |
connected = false; | |
GPContext *context; | |
context = gp_context_new(); | |
CameraList *list; | |
Camera **cams; | |
int ret, count; | |
ret = gp_list_new (&list); | |
GPPortInfoList *port_info_list = nullptr; | |
CameraAbilitiesList *camera_abilities_list = nullptr; | |
gp_port_info_list_new(&port_info_list); | |
gp_port_info_list_load(port_info_list); | |
gp_abilities_list_new(&camera_abilities_list); | |
gp_abilities_list_load(camera_abilities_list, context); | |
int num_cams = gp_camera_autodetect(list, context); | |
const char *name, *port; | |
gp_list_get_name(list, id, &name); | |
gp_list_get_value(list, id, &port); | |
cams = (Camera**) calloc (sizeof(Camera*),2); | |
camera = cams[id]; | |
gp_camera_new(&camera); | |
CameraAbilities abilities; | |
int model_index = gp_abilities_list_lookup_model(camera_abilities_list, name); | |
gp_abilities_list_get_abilities(camera_abilities_list, model_index, &abilities); | |
gp_camera_set_abilities(camera, abilities); | |
int port_index = gp_port_info_list_lookup_path(port_info_list, port); | |
GPPortInfo port_info; | |
gp_port_info_list_get_info(port_info_list, port_index, &port_info); | |
gp_camera_set_port_info(camera, port_info); | |
int retval = gp_camera_init(camera, context); | |
cout << "port" << port << endl; | |
if (retval != GP_OK) { | |
ofLogError("ofxGphoto::setup") << "Camera initialisation error - " << retval << " " << gp_result_as_string(retval)<<endl; | |
}else { | |
ofLogNotice("ofxGphoto::setup","Camera initialised successfully!"); | |
// get camera information | |
CameraText text; | |
retval = gp_camera_get_summary(camera,&text,cameracontext); | |
if (retval == GP_OK) { | |
ofLogNotice("ofxGphoto::setup") << "camera information"; | |
ofLogNotice("========================================="); | |
ofBuffer cText(text.text,30*1024); | |
int count = 0; | |
for(auto& l:cText.getLines()){ | |
ofLogNotice() << l; | |
if (count>=5){ | |
break; | |
} | |
++count; | |
} | |
} | |
else{ | |
ofLogError("ofxGphoto::setup") << "Failed to get Camera information - " << retval << " " << gp_result_as_string(retval)<<endl; | |
} | |
connected = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment