Created
September 28, 2022 18:09
-
-
Save petabyt/698e38f6e62bdeb7f58ee42f7e50642e to your computer and use it in GitHub Desktop.
ml-liveview-ptp-module
This file contains hidden or 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
#include <stdio.h> | |
#include <dryos.h> | |
#include <module.h> | |
#include <menu.h> | |
#include <config.h> | |
#include <bmp.h> | |
#include <console.h> | |
#include <math.h> | |
#include <ptp.h> | |
uint8_t *vram = NULL; | |
void ptpview_task() {} | |
struct menu_entry ptpview_menu[] = { | |
{ | |
.name = "PTP Liveview", | |
.select = NULL, | |
.help = "View screen from USB", | |
}, | |
}; | |
int send_ptp_data(struct ptp_context *data, const char *buf, int size) | |
// repeated calls per transaction are *not* ok | |
{ | |
int tmpsize; | |
tmpsize = size; | |
while ( size >= BUF_SIZE ) { | |
if ( data->send_data(data->handle,(void *)buf,BUF_SIZE,tmpsize,0,0,0) ) { | |
return 0; | |
} | |
tmpsize = 0; | |
size -= BUF_SIZE; | |
buf += BUF_SIZE; | |
} | |
if ( size != 0 ) { | |
if ( data->send_data(data->handle,(void *)buf,size,tmpsize,0,0,0) ) { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
static int ptpview_handler(void *priv, struct ptp_context *context, | |
uint32_t opcode, uint32_t session, uint32_t transaction, | |
uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4, uint32_t param5) | |
{ | |
send_ptp_data(context, (const char*)vram, 720 * 480); | |
struct ptp_msg msg = { | |
.id = 0x2001, | |
.session = session, | |
.transaction = transaction, | |
.param_count = 0, | |
}; | |
context->send_resp(context->handle, &msg); | |
return 0; | |
} | |
unsigned int ptpview_init() | |
{ | |
vram = bmp_vram(); | |
menu_add("Display", ptpview_menu, COUNT(ptpview_menu)); | |
ptp_register_handler(0x9997, &ptpview_handler, 0); | |
return 0; | |
} | |
unsigned int ptpview_deinit() | |
{ | |
return 0; | |
} | |
MODULE_INFO_START() | |
MODULE_INIT(ptpview_init) | |
MODULE_DEINIT(ptpview_deinit) | |
MODULE_INFO_END() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment