-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional desktop app connecting/disconnecting
- Loading branch information
Showing
22 changed files
with
911 additions
and
1,016 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | ||
<assemblyIdentity | ||
version="1.0.0.0" | ||
processorArchitecture="*" | ||
name="CompanyName.ProductName.YourApplication" | ||
type="win32" | ||
/> | ||
<description>Your application description here.</description> | ||
<!-- we DO need comctl6 in the static case --> | ||
<dependency> | ||
<dependentAssembly> | ||
<assemblyIdentity | ||
type="win32" | ||
name="Microsoft.Windows.Common-Controls" | ||
version="6.0.0.0" | ||
processorArchitecture="*" | ||
publicKeyToken="6595b64144ccf1df" | ||
language="*" | ||
/> | ||
</dependentAssembly> | ||
</dependency> | ||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> | ||
<application> | ||
<!--The ID below indicates application support for Windows Vista --> | ||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> | ||
<!--The ID below indicates application support for Windows 7 --> | ||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> | ||
</application> | ||
</compatibility> | ||
</assembly> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,151 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdarg.h> | ||
#include <camlib.h> | ||
#include <fuji.h> | ||
#include <app.h> | ||
#include <fujiptp.h> | ||
#include <lua.h> | ||
#include <camlua.h> | ||
#include <pthread.h> | ||
#include "desktop.h" | ||
|
||
void app_get_file_path(char buffer[256], const char *filename) { | ||
snprintf(buffer, 256, "%s", filename); | ||
static struct PtpRuntime *ptp = NULL; | ||
|
||
// TODO: System to manage a list of cameras connected | ||
struct PtpRuntime *ptp_get() { | ||
return ptp; | ||
} | ||
|
||
struct PtpRuntime *luaptp_get_runtime(lua_State *L) { | ||
return ptp_get(); | ||
} | ||
|
||
int luaopen_libuilua(lua_State *L); | ||
int cam_lua_setup(lua_State *L) { | ||
luaL_requiref(L, "ui", luaopen_libuilua, 1); | ||
return 0; | ||
} | ||
|
||
void app_get_tether_file_path(char buffer[256]) { | ||
snprintf(buffer, 256, "TETHER.JPG"); | ||
int fudge_usb_connect(struct PtpRuntime *r) { | ||
static int attempts = 0; | ||
app_log_clear(); | ||
int rc = fujiusb_try_connect(r); | ||
if (rc) { | ||
const char *msg = "No Fujifilm device found"; | ||
if (attempts) { | ||
app_print("%s (%d)", msg, attempts); | ||
} else { | ||
app_print("%s", msg); | ||
} | ||
attempts++; | ||
return rc; | ||
} | ||
attempts = 0; | ||
|
||
rc = ptp_open_session(r); | ||
if (rc != PTP_CHECK_CODE && rc) return rc; | ||
|
||
ptp = r; | ||
|
||
return 0; | ||
} | ||
|
||
void fudge_disconnect_all(void) { | ||
struct PtpRuntime *r = ptp_get(); | ||
if (r == NULL) { | ||
// 0 cameras connected | ||
return; | ||
} | ||
printf("Disconnecting\n"); | ||
ptp_report_error(r, "Intentional", 0); | ||
ptp = NULL; | ||
} | ||
|
||
int fudge_main_app_thread(struct PtpRuntime *r) { | ||
struct PtpDeviceInfo di; | ||
int rc = ptp_get_device_info(r, &di); | ||
if (rc) return rc; | ||
|
||
app_print("Connected to %s %s", di.manufacturer, di.model); | ||
app_send_cam_name(di.model); | ||
|
||
struct PtpArray *arr; | ||
rc = ptp_fuji_get_object_handles(r, &arr); | ||
app_print("%d files on card", arr->length); | ||
|
||
while (r->io_kill_switch == 0) { | ||
if (ptpusb_get_status(r)) { | ||
app_print("USB cable disconnected."); | ||
break; | ||
} | ||
usleep(100000); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void *fudge_backup_settings(void *arg) { | ||
return NULL; | ||
} | ||
|
||
void *fudge_usb_connect_thread(void *arg) { | ||
struct PtpRuntime *r = ptp_new(PTP_USB); | ||
int rc = fudge_usb_connect(r); | ||
if (rc) goto exit; | ||
|
||
app_update_connected_status(1); | ||
rc = fudge_main_app_thread(r); | ||
app_update_connected_status(0); | ||
|
||
ptp = NULL; | ||
|
||
exit:; | ||
ptp_close(r); | ||
pthread_exit(NULL); | ||
return NULL; | ||
} | ||
|
||
int fudge_run_lua(struct PtpRuntime *r, const char *text) { | ||
cam_run_lua_script_async(text); | ||
} | ||
|
||
static char *read_file(const char *filename) { | ||
FILE* file = fopen(filename, "rb"); | ||
if (!file) return NULL; | ||
|
||
fseek(file, 0, SEEK_END); | ||
long file_size = ftell(file); | ||
fseek(file, 0, SEEK_SET); | ||
|
||
char* buffer = (char*)malloc(file_size + 1); | ||
if (!buffer) return NULL; | ||
|
||
fread(buffer, 1, file_size, file); | ||
buffer[file_size] = '\0'; | ||
|
||
fclose(file); | ||
return buffer; | ||
} | ||
|
||
int fuji_connect_run_script(const char *filename) { | ||
const char *text = read_file(filename); | ||
if (text == NULL) { | ||
printf("%s not found\n", filename); | ||
return -1; | ||
} | ||
|
||
struct PtpRuntime *r = ptp_new(PTP_USB); | ||
int rc = fudge_usb_connect(r); | ||
if (rc) return rc; | ||
|
||
rc = cam_run_lua_script_async(text); | ||
if (rc) { | ||
printf("%s\n", cam_lua_get_error()); | ||
printf("Lua err %d\n", rc); | ||
} | ||
return rc; | ||
// leak r | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <stdlib.h> | ||
#include <ui.h> | ||
#include <object.h> | ||
#include <object.h> | ||
#include <app.h> | ||
|
||
struct MyTableModelHandler { | ||
uiTableModelHandler mh; | ||
struct PtpRuntime *r; | ||
struct PtpObjectCache *oc; | ||
}; | ||
|
||
static inline struct MyTableModelHandler *my_handler(uiTableModelHandler *mh) { | ||
return (struct MyTableModelHandler *)mh; | ||
} | ||
|
||
static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m) { | ||
return 3; | ||
} | ||
|
||
static uiTableValueType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column) | ||
{ | ||
switch (column) { | ||
case 0: | ||
return uiTableValueTypeString; | ||
case 1: | ||
return uiTableValueTypeString; | ||
default: | ||
return uiTableValueTypeString; | ||
} | ||
} | ||
|
||
static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m) { | ||
return ptp_object_service_length( | ||
my_handler(mh)->r, | ||
my_handler(mh)->oc | ||
); | ||
} | ||
|
||
static uiTableValue *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column) | ||
{ | ||
struct MyTableModelHandler *h = my_handler(mh); | ||
|
||
if (column == 0) { | ||
struct PtpObjectInfo *oi = ptp_object_service_get_index(h->r, h->oc, row); | ||
return uiNewTableValueString(oi->filename); | ||
} | ||
|
||
return uiNewTableValueString("TODO"); | ||
} | ||
|
||
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int column, const uiTableValue *val) { | ||
// This list is not editable | ||
} | ||
|
||
uiControl *create_files_tab(struct PtpRuntime *r, struct PtpObjectCache *oc) { | ||
struct MyTableModelHandler *mh = (struct MyTableModelHandler *)malloc(sizeof(struct MyTableModelHandler)); | ||
mh->mh.NumColumns = modelNumColumns; | ||
mh->mh.ColumnType = modelColumnType; | ||
mh->mh.NumRows = modelNumRows; | ||
mh->mh.CellValue = modelCellValue; | ||
mh->mh.SetCellValue = modelSetCellValue; | ||
mh->r = r; | ||
mh->oc = oc; | ||
|
||
uiTableModel *m = uiNewTableModel((uiTableModelHandler *)mh); | ||
|
||
uiTableParams p = { | ||
.Model = m, | ||
.RowBackgroundColorModelColumn = 3, | ||
}; | ||
|
||
uiTable *t = uiNewTable(&p); | ||
|
||
uiTableAppendTextColumn(t, "Filename", 0, uiTableModelColumnNeverEditable, NULL); | ||
uiTableAppendTextColumn(t, "Last Modified", 1, uiTableModelColumnNeverEditable, NULL); | ||
|
||
return uiControl(t); | ||
} |
Oops, something went wrong.