Esempio n. 1
0
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
               CameraFileType type, CameraFile *file, void *data,
               GPContext *context)
{
        Camera *camera = data;
        unsigned long image_id;
        char image_id_string[] = {0, 0, 0, 0, 0, 0, 0};
        unsigned int size;
        CameraFileInfo info;
        int r;
	KncCamRes cr;
	KncCntrlRes cntrl_res = KNC_CNTRL_OK;

        if (strlen (filename) != 11) return (GP_ERROR_FILE_NOT_FOUND);
        if (strcmp (folder, "/")) return (GP_ERROR_DIRECTORY_NOT_FOUND);

        /* Check if we can get the image id from the filename. */
        strncpy (image_id_string, filename, 6);
        image_id = atol (image_id_string);

        /* Get information about the image */
        C (gp_filesystem_get_info (camera->fs, folder,
                                        filename, &info, context));

        /*
         * Remove the timeout, get the image and start the timeout
         * afterwards.
         */
        gp_camera_stop_timeout (camera, camera->pl->timeout);
	knc_cntrl_set_func_data (camera->pl->c, data_func, file);
        switch (type) {
        case GP_FILE_TYPE_PREVIEW:
                size = 2048;
                cntrl_res = knc_get_image (camera->pl->c, &cr,
                        image_id, KNC_SOURCE_CARD, KNC_IMAGE_THUMB);
                break;
        case GP_FILE_TYPE_NORMAL:
                size = info.file.size;
                cntrl_res = knc_get_image (camera->pl->c, &cr,
                        image_id, KNC_SOURCE_CARD, KNC_IMAGE_EXIF);
                break;
        default:
                r = GP_ERROR_NOT_SUPPORTED;
        }
        camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT,
                                                       timeout_func);
        CR (cntrl_res, context);
	CCR (cr, context);

        C (gp_file_set_mime_type (file, GP_MIME_JPEG));

        return (GP_OK);
}
Esempio n. 2
0
int
main (int argc, char **argv)
{
    GPPort *p;
    KncCntrl *c;
    KncCamRes r;
    KncInfo ki;
    KncImageInfo kii;
    KncBitRate br;
    KncBitFlag bf;
    GPPortSettings s;

    printf ("Connecting to camera...\n");
    c = gpknc_cntrl_new_from_path ("serial:/dev/ttyS0");
    if (!c) {
        printf ("... failed.\n");
        return 1;
    }
    knc_cntrl_set_func_data (c, test_data, NULL);
    knc_cntrl_set_func_log  (c, test_log , NULL);
    printf ("... done.\n");

    printf ("Setting speed to 115200...\n");
    p = gpknc_cntrl_get_port (c);
    br = KNC_BIT_RATE_115200;
    bf = KNC_BIT_FLAG_8_BITS;
    CR (knc_set_io_pref (c, NULL, &br, &bf));
    gp_port_get_settings (p, &s);
    s.serial.speed = 115200;
    gp_port_set_settings (p, s);

    printf ("Requesting information about the camera...\n");
    CR (knc_get_info (c, &r, &ki));
    if (r) printf ("### Error %i: '%s'!\n", r, knc_cam_res_name (r));
    else {
        printf (" - Model '%s'\n", ki.model);
        printf (" - Serial number '%s'\n", ki.serial_number);
        printf (" - Name '%s'\n", ki.name);
        printf (" - Manufacturer '%s'\n", ki.manufacturer);
    }

    printf ("Capturing preview...\n");
    CR (knc_get_preview (c, &r, KNC_PREVIEW_NO));

    printf ("Requesting information about the first image...\n");
    CR (knc_get_image_info (c, &r, 1, &kii));
    if (r) printf ("### Error 0x%04x: '%s!\n", r, knc_cam_res_name (r));
    else {
        printf (" - ID %li\n", kii.id);
        printf (" - Size %i\n", kii.size);
        printf (" - Protected: %s\n", kii.prot ? "yes" : "no");
    }

    printf ("Downloading preview of first image...\n");
    CR (knc_get_image (c, NULL, kii.id, KNC_SOURCE_CARD, KNC_IMAGE_THUMB));
    knc_cntrl_unref (c);

    return 0;
}