Skip to content

Commit

Permalink
Update everything to new function names
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Dec 2, 2023
1 parent 3efef3d commit 61b3058
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 92 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Unix only makefile
-include config.mak

CFLAGS=-Isrc/ -DVERBOSE -g -fpic -Wall -Wshadow -Wcast-qual -Wpedantic -Werror=incompatible-pointer-types
CFLAGS=-Isrc/ -g -fpic -Wall -Wshadow -Wcast-qual -Wpedantic -Werror=incompatible-pointer-types -Werror=deprecated-declarations
CFLAGS+=-D CAMLIB_NO_COMPAT -D VERBOSE

# All platforms need these object files
CAMLIB_CORE=operations.o packet.o enums.o data.o enum_dump.o lib.o canon.o liveview.o bind.o ip.o ml.o log.o conv.o generic.o canon_adv.o
Expand All @@ -17,7 +18,7 @@ COMMIT=$(shell git rev-parse HEAD)
CFLAGS+='-DCAMLIB_COMMIT="$(COMMIT)"'

libcamlib.so: $(FILES)
$(CC) -shared $(FILES) $(LDFLAGS) -o libcamlib.so
$(CC) -shared $(FILES) -o libcamlib.so

%.o: %.c src/*.h
$(CC) -c $(CFLAGS) $< -o $@
Expand Down
21 changes: 14 additions & 7 deletions src/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

#include <camlib.h>

#ifndef CAMLIB_VERSION
#ifdef __DATE__
#define CAMLIB_VERSION __DATE__
#else
#define CAMLIB_VERSION "Unknown"
#endif
#endif

// TODO: func to access these
static int bind_connected = 0;
static int bind_initialized = 0;
static int bind_capture_type = 0;
int bind_connected = 0;
int bind_initialized = 0;

int bind_status(struct BindReq *bind, struct PtpRuntime *r) {
return sprintf(bind->buffer, "{\"error\": 0, \"initialized\": %d, \"connected\": %d, "
Expand All @@ -24,11 +31,11 @@ int bind_status(struct BindReq *bind, struct PtpRuntime *r) {

int bind_init(struct BindReq *bind, struct PtpRuntime *r) {
if (bind_initialized) {
ptp_generic_close(r);
ptp_close(r);
if (r->di != NULL) free(r->di);
}

ptp_generic_init(r);
ptp_init(r);
bind_initialized = 1;

return sprintf(bind->buffer, "{\"error\": %d, \"buffer\": %d}", 0, r->data_length);
Expand Down Expand Up @@ -145,9 +152,9 @@ int bind_custom(struct BindReq *bind, struct PtpRuntime *r) {

int x = 0;
if (bind->bytes_length) {
x = ptp_generic_send_data(r, &cmd, bind->bytes, bind->bytes_length);
x = ptp_send_data(r, &cmd, bind->bytes, bind->bytes_length);
} else {
x = ptp_generic_send(r, &cmd);
x = ptp_send(r, &cmd);
}

if (x) {
Expand Down
50 changes: 31 additions & 19 deletions src/camlib.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Main header file for Camlib - these are not Standard PTP definitions
// Main header file for Camlib
// Copyright 2022 by Daniel C (https://github.com/petabyt/camlib)
#ifndef PTP_LIB_H
#define PTP_LIB_H
Expand All @@ -9,21 +9,10 @@

#include "ptp.h"

#define ptp_get_last_transaction(...) DEPRECATED_USE_ptp_get_last_transaction_id

// Used in dumps, should be set to the git commit hash
#ifndef CAMLIB_VERSION
#ifdef __DATE__
#define CAMLIB_VERSION __DATE__
#else
#define CAMLIB_VERSION "Unknown"
#endif
#endif

// Max timeout for command read/writes
#define PTP_TIMEOUT 1000

// How much ms to wait for wait_for_response
// How much ms to wait for r->wait_for_response
#define CAMLIB_WAIT_MS 1000

// Conforms to POSIX 2001, some compilers may not have it
Expand Down Expand Up @@ -97,11 +86,14 @@ enum ImageFormats {
};

enum PtpConnType {
PTP_IP,
PTP_IP_USB, // TCP-based, but using USB-style packets (Fujifilm)
PTP_USB,
PTP_IP = (1 << 0),
PTP_IP_USB = (1 << 1), // TCP-based, but using USB-style packets (Fujifilm)
PTP_USB = (1 << 2),
};

// TODO: less confusing name
//#define PtpRuntime PtpLib

struct PtpRuntime {
// Set to 1 to kill all IO operations. By default, this is 1. When a valid connection
// is achieved by libusb, libwpd, and tcp backends, it will be set to 0. On IO error, it
Expand Down Expand Up @@ -222,9 +214,18 @@ int ptp_generic_send(struct PtpRuntime *r, struct PtpCommand *cmd);
int ptp_generic_send_data(struct PtpRuntime *r, struct PtpCommand *cmd, void *data, int length);

// Generic runtime setup - allocate default memory
void ptp_generic_reset(struct PtpRuntime *r);
void ptp_generic_init(struct PtpRuntime *r);
void ptp_generic_close(struct PtpRuntime *r);
void ptp_generic_reset(struct PtpRuntime *r) __attribute__ ((deprecated));
void ptp_reset(struct PtpRuntime *r);
void ptp_generic_init(struct PtpRuntime *r) __attribute__ ((deprecated));
void ptp_init(struct PtpRuntime *r);
void ptp_generic_close(struct PtpRuntime *r) __attribute__ ((deprecated));
void ptp_close(struct PtpRuntime *r);
struct PtpRuntime *ptp_generic_new() __attribute__ ((deprecated));
struct PtpRuntime *ptp_new(int options);
int ptp_generic_send(struct PtpRuntime *r, struct PtpCommand *cmd) __attribute__ ((deprecated));
int ptp_generic_send_data(struct PtpRuntime *r, struct PtpCommand *cmd, void *data, int length) __attribute__ ((deprecated));
int ptp_send(struct PtpRuntime *r, struct PtpCommand *cmd);
int ptp_send_data(struct PtpRuntime *r, struct PtpCommand *cmd, void *data, int length);

int ptp_get_event(struct PtpRuntime *r, struct PtpEventContainer *ec);

Expand All @@ -246,4 +247,15 @@ int ptp_dump(struct PtpRuntime *r);
#include "cl_enum.h"
#include "cl_bind.h"

// Backwards compatibility
#ifndef CAMLIB_NO_COMPAT
#define ptp_get_last_transaction(...) ptp_get_last_transaction_id(__VA_ARGS__)
#define ptp_generic_new(...) ptp_new(__VA_ARGS__)
#define ptp_generic_close(...) ptp_close(__VA_ARGS__)
#define ptp_generic_reset(...) ptp_reset(__VA_ARGS__)
#define ptp_generic_init(...) ptp_init(__VA_ARGS__)
#define ptp_generic_send(...) ptp_send(__VA_ARGS__)
#define ptp_generic_send_data(...) ptp_send_data(__VA_ARGS__)
#endif

#endif
40 changes: 20 additions & 20 deletions src/canon.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ int ptp_eos_get_storage_ids(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_GetStorageIDs;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_get_storage_info(struct PtpRuntime *r, int id) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_GetStorageInfo;
cmd.param_length = 1;
cmd.params[0] = id;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_remote_release_on(struct PtpRuntime *r, int mode) {
Expand All @@ -31,22 +31,22 @@ int ptp_eos_remote_release_on(struct PtpRuntime *r, int mode) {
cmd.param_length = 2;
cmd.params[0] = mode;
cmd.params[1] = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_remote_release_off(struct PtpRuntime *r, int mode) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_RemoteReleaseOff;
cmd.param_length = 1;
cmd.params[0] = mode;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_cancel_af(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_AfCancel;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_drive_lens(struct PtpRuntime *r, int steps) {
Expand All @@ -59,23 +59,23 @@ int ptp_eos_drive_lens(struct PtpRuntime *r, int steps) {
cmd.code = PTP_OC_EOS_DriveLens;
cmd.param_length = 1;
cmd.params[0] = steps;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_set_event_mode(struct PtpRuntime *r, int mode) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_SetEventMode;
cmd.param_length = 1;
cmd.params[0] = mode;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_set_remote_mode(struct PtpRuntime *r, int mode) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_SetRemoteMode;
cmd.param_length = 1;
cmd.params[0] = mode;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_get_viewfinder_data(struct PtpRuntime *r) {
Expand All @@ -85,15 +85,15 @@ int ptp_eos_get_viewfinder_data(struct PtpRuntime *r) {

cmd.params[0] = 0x200000;

return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_get_prop_value(struct PtpRuntime *r, int code) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_GetDevicePropValue;
cmd.param_length = 1;
cmd.params[0] = code;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_set_prop_value(struct PtpRuntime *r, int code, int value) {
Expand All @@ -103,7 +103,7 @@ int ptp_eos_set_prop_value(struct PtpRuntime *r, int code, int value) {

uint32_t dat[] = {0xc, code, value};

return ptp_generic_send_data(r, &cmd, dat, sizeof(dat));
return ptp_send_data(r, &cmd, dat, sizeof(dat));
}

int ptp_eos_set_prop_data(struct PtpRuntime *r, int code, void *data, int dlength) {
Expand All @@ -115,14 +115,14 @@ int ptp_eos_get_event(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_GetEvent;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_ping(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_KeepDeviceOn;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

// The HDD capacity is pushed/popped (for lack of a better term)
Expand All @@ -134,7 +134,7 @@ int ptp_eos_hdd_capacity_push(struct PtpRuntime *r) {
cmd.params[0] = 0xfffffff7;
cmd.params[1] = 0x1000;
cmd.params[2] = 0x0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_hdd_capacity_pop(struct PtpRuntime *r) {
Expand All @@ -144,36 +144,36 @@ int ptp_eos_hdd_capacity_pop(struct PtpRuntime *r) {
cmd.params[0] = 0x332d2d;
cmd.params[1] = 0x1000;
cmd.params[2] = 0x1;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_bulb_start(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_BulbStart;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_bulb_stop(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_BulbEnd;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_set_ui_lock(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_SetUILock;
cmd.param_length = 1;
cmd.params[0] = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

int ptp_eos_reset_ui_lock(struct PtpRuntime *r) {
struct PtpCommand cmd;
cmd.code = PTP_OC_EOS_ResetUILock;
cmd.param_length = 0;
return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

// Credit to lclevy/miniPtp for implementation
Expand Down Expand Up @@ -205,7 +205,7 @@ int ptp_eos_update_firmware(struct PtpRuntime *r, FILE *f, char *name) {

if (sent + size > s.st_size) size -= s.st_size - sent;

int rc = ptp_generic_send_data(r, &cmd, payload, size);
int rc = ptp_send_data(r, &cmd, payload, size);
if (rc) {
return rc;
}
Expand Down
6 changes: 3 additions & 3 deletions src/canon_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int ptp_eos_activate_command(struct PtpRuntime *r) {
cmd.code = PTP_OC_EOS_EnableEventProc;
cmd.param_length = 0;

int ret = ptp_generic_send(r, &cmd);
int ret = ptp_send(r, &cmd);
if (ret == PTP_IO_ERR) {
return ret;
}
Expand All @@ -38,7 +38,7 @@ int ptp_eos_exec_evproc(struct PtpRuntime *r, void *data, int length, int expect
// If 1, evproc struct parser will put 3 params before params specified by our code
cmd.params[1] = expect_return;

return ptp_generic_send_data(r, &cmd, data, length);
return ptp_send_data(r, &cmd, data, length);
}

int ptp_eos_evproc_return_data(struct PtpRuntime *r) {
Expand All @@ -50,7 +50,7 @@ int ptp_eos_evproc_return_data(struct PtpRuntime *r) {
cmd.params[1] = 0;
cmd.params[2] = 1;

return ptp_generic_send(r, &cmd);
return ptp_send(r, &cmd);
}

#define EOS_TOK_INT 2
Expand Down
Loading

0 comments on commit 61b3058

Please sign in to comment.