<commit_before>#include <stdio.h>
#include <string.h>
#include <gphoto2.h>
#include <gpio.h>

#include "dc240.h"
#include "library.h"

int camera_id (CameraText *id) {

	strcpy(id->text, "kodak-dc240");

	return (GP_OK);
}

int camera_abilities (CameraAbilitiesList *list) {

	CameraAbilities *a;

	a = gp_abilities_new();

	strcpy(a->model, "Kodak DC240");
	a->port     = GP_PORT_SERIAL | GP_PORT_USB;
	a->speed[0] = 9600;
	a->speed[1] = 19200;
	a->speed[2] = 38400;
	a->speed[3] = 57600;
	a->speed[4] = 115200;
	a->speed[5] = 0;
        a->usb_vendor  = 0x040A;
        a->usb_product = 0x0120;
        a->capture  = GP_CAPTURE_IMAGE;
	a->config   = 0;
	a->file_delete  = 1;
	a->file_preview = 1;
	a->file_put = 0;

	gp_abilities_list_append(list, a);

	return (GP_OK);
}

int camera_init (Camera *camera, CameraInit *init) {

    gpio_device_settings settings;
    DC240Data *dd;

    if (!camera)
        return (GP_ERROR);

    dd = (DC240Data*)malloc(sizeof(DC240Data));
    if (!dd)
        return (GP_ERROR);

    /* First, set up all the function pointers */
    camera->functions->id 		= camera_id;
    camera->functions->abilities 	= camera_abilities;
    camera->functions->init 	        = camera_init;
    camera->functions->exit 	        = camera_exit;
    camera->functions->folder_list      = camera_folder_list;
    camera->functions->file_list	= camera_file_list;
    camera->functions->file_get 	= camera_file_get;
    camera->functions->file_get_preview = camera_file_get_preview;
    camera->functions->file_put 	= camera_file_put;
    camera->functions->file_delete 	= camera_file_delete;
    camera->functions->config           = camera_config;
    camera->functions->capture 	        = camera_capture;
    camera->functions->summary	        = camera_summary;
    camera->functions->manual 	        = camera_manual;
    camera->functions->about 	        = camera_about;

    switch (init->port.type) {
    case GP_PORT_SERIAL:
        dd->dev = gpio_new(GPIO_DEVICE_SERIAL);
        if (!dd->dev) {
            free(dd);
            return (GP_ERROR);
        }
        strcpy(settings.serial.port, init->port.path);
        settings.serial.speed    = 9600;
        settings.serial.bits     = 8;
        settings.serial.parity   = 0;
        settings.serial.stopbits = 1;
        break;
    case GP_PORT_USB:
        dd->dev = gpio_new(GPIO_DEVICE_USB);
        if (!dd->dev) {
            free(dd);
            return (GP_ERROR);
        }
        if (gpio_usb_find_device(dd->dev, 0x040A, 0x0120) == GPIO_ERROR) {
            gpio_free(dd->dev);
            free (dd);
            return (GP_ERROR);
        }
        settings.usb.inep       = 0x82;
        settings.usb.outep      = 0x01;
        settings.usb.config     = 1;
        settings.usb.interface  = 0;
        settings.usb.altsetting = 0;
        break;
    default:
        return (GP_ERROR);
    }

    if (gpio_set_settings(dd->dev, settings) == GPIO_ERROR) {
        gpio_free(dd->dev);
        free(dd);
        return (GP_ERROR);
    }

    if (gpio_open(dd->dev) == GPIO_ERROR) {
        gpio_free(dd->dev);
        free(dd);
        return (GP_ERROR);
    }

    gpio_set_timeout(dd->dev, TIMEOUT);

    if (init->port.type == GP_PORT_SERIAL) {<commit_msg>#ifdef GPIO_USB for usb related code.<commit_after>#include <stdio.h>
#include <string.h>
#include <gphoto2.h>
#include <gpio.h>

#include "dc240.h"
#include "library.h"

int camera_id (CameraText *id) {

	strcpy(id->text, "kodak-dc240");

	return (GP_OK);
}

int camera_abilities (CameraAbilitiesList *list) {

	CameraAbilities *a;

	a = gp_abilities_new();

	strcpy(a->model, "Kodak DC240");
	a->port     = GP_PORT_SERIAL | GP_PORT_USB;
	a->speed[0] = 9600;
	a->speed[1] = 19200;
	a->speed[2] = 38400;
	a->speed[3] = 57600;
	a->speed[4] = 115200;
	a->speed[5] = 0;
        a->usb_vendor  = 0x040A;
        a->usb_product = 0x0120;
        a->capture  = GP_CAPTURE_IMAGE;
	a->config   = 0;
	a->file_delete  = 1;
	a->file_preview = 1;
	a->file_put = 0;

	gp_abilities_list_append(list, a);

	return (GP_OK);
}

int camera_init (Camera *camera, CameraInit *init) {

    gpio_device_settings settings;
    DC240Data *dd;

    if (!camera)
        return (GP_ERROR);

    dd = (DC240Data*)malloc(sizeof(DC240Data));
    if (!dd)
        return (GP_ERROR);

    /* First, set up all the function pointers */
    camera->functions->id 		= camera_id;
    camera->functions->abilities 	= camera_abilities;
    camera->functions->init 	        = camera_init;
    camera->functions->exit 	        = camera_exit;
    camera->functions->folder_list      = camera_folder_list;
    camera->functions->file_list	= camera_file_list;
    camera->functions->file_get 	= camera_file_get;
    camera->functions->file_get_preview = camera_file_get_preview;
    camera->functions->file_put 	= camera_file_put;
    camera->functions->file_delete 	= camera_file_delete;
    camera->functions->config           = camera_config;
    camera->functions->capture 	        = camera_capture;
    camera->functions->summary	        = camera_summary;
    camera->functions->manual 	        = camera_manual;
    camera->functions->about 	        = camera_about;

    switch (init->port.type) {
    case GP_PORT_SERIAL:
        dd->dev = gpio_new(GPIO_DEVICE_SERIAL);
        if (!dd->dev) {
            free(dd);
            return (GP_ERROR);
        }
        strcpy(settings.serial.port, init->port.path);
        settings.serial.speed    = 9600;
        settings.serial.bits     = 8;
        settings.serial.parity   = 0;
        settings.serial.stopbits = 1;
        break;
#ifdef GPIO_USB
    case GP_PORT_USB:
        dd->dev = gpio_new(GPIO_DEVICE_USB);
        if (!dd->dev) {
            free(dd);
            return (GP_ERROR);
        }
        if (gpio_usb_find_device(dd->dev, 0x040A, 0x0120) == GPIO_ERROR) {
            gpio_free(dd->dev);
            free (dd);
            return (GP_ERROR);
        }
        settings.usb.inep       = 0x82;
        settings.usb.outep      = 0x01;
        settings.usb.config     = 1;
        settings.usb.interface  = 0;
        settings.usb.altsetting = 0;
        break;
    default:
#endif
        return (GP_ERROR);
    }

    if (gpio_set_settings(dd->dev, settings) == GPIO_ERROR) {
        gpio_free(dd->dev);
        free(dd);
        return (GP_ERROR);
    }

    if (gpio_open(dd->dev) == GPIO_ERROR) {
        gpio_free(dd->dev);
        free(dd);
        return (GP_ERROR);
    }

    gpio_set_timeout(dd->dev, TIMEOUT);

    if (init->port.type == GP_PORT_SERIAL) {
{'fraction_non_alphanumeric': 0.13559322033898305, 'fraction_numerical': 0.027179722094976332, 'mean_word_length': 2.3658787255909557, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2731534', 'n_tokens_mistral': 2450, 'n_tokens_neox': 2255, 'n_words': 400}