Merge pull request 'printer: Add setting to configure "printing time"' (#39) from Haruka/segatools:printerdelay into develop

Reviewed-on: Dniel97/segatools#39
This commit is contained in:
Dniel97 2024-10-04 12:53:26 +00:00
commit 8c24e04900
4 changed files with 33 additions and 8 deletions

View File

@ -89,6 +89,9 @@ enable=1
serial_no="5A-A123"
; Insert the path to the image output directory here.
printerOutPath="DEVICE\print"
; The length in milliseconds the printer should be busy printing.
; Set to 0 to instantly finish printing.
waitTime=20000
; -----------------------------------------------------------------------------
; LED settings

View File

@ -80,4 +80,6 @@ void printer_config_load(struct printer_config *cfg, const wchar_t *filename)
cfg->printer_out_path,
_countof(cfg->printer_out_path),
filename);
cfg->wait_time = GetPrivateProfileIntW(L"printer", L"waitTime", 0, filename);
}

View File

@ -58,6 +58,7 @@ static int32_t MTF[9];
/* Printer status */
static uint8_t STATUS = 0;
static ULONGLONG finishTime = 0;
/* C3XXFWDLusb API hooks */
@ -1244,6 +1245,10 @@ void printer_hook_insert_hooks(HMODULE target) {
proc_addr_table_push(target, "C300FWDLusb.dll", C3XXFWDLusb_hooks, _countof(C3XXFWDLusb_hooks));
}
static inline bool check_for_wait_time(){
return finishTime > 0 && GetTickCount64() < finishTime;
}
static void generate_rfid(void) {
for (int i = 0; i < sizeof(cardRFID); i++)
cardRFID[i] = rand();
@ -2403,7 +2408,11 @@ int WINAPI chcusb_copies(uint16_t copies, uint16_t *rResult) {
int WINAPI chcusb_status(uint16_t *rResult) {
// dprintf("Printer: C3XXusb: %s\n", __func__);
*rResult = 0;
if (check_for_wait_time()) {
*rResult = 2203;
} else {
*rResult = 0;
}
return 1;
}
@ -2439,6 +2448,10 @@ int WINAPI chcusb_startpage_300(uint16_t postCardState, uint16_t *rResult) {
int WINAPI chcusb_endpage(uint16_t *rResult) {
dprintf("Printer: C3XXusb: %s\n", __func__);
if (printer_config.wait_time > 0){
finishTime = GetTickCount64() + printer_config.wait_time;
dprintf("Printer: Waiting for %dms...\n", printer_config.wait_time);
}
awaitingCardExit = true;
*rResult = 0;
@ -2622,13 +2635,12 @@ int WINAPI chcusb_getPrintIDStatus(uint16_t pageId, uint8_t *rBuffer, uint16_t *
// dprintf("Printer: C3XXusb: %s\n", __func__);
memset(rBuffer, 0, 8);
if (STATUS > 1)
{
if (check_for_wait_time()) {
*((uint16_t*)(rBuffer + 6)) = 2203;
} else if (STATUS > 1) {
STATUS = 0;
*((uint16_t*)(rBuffer + 6)) = 2212;
}
else
{
} else {
*((uint16_t*)(rBuffer + 6)) = 2300;
}
@ -2658,6 +2670,7 @@ int WINAPI chcusb_setPrintStandby_300(uint16_t *rResult) {
*rResult = 0;
if (awaitingCardExit){ // 300 does not use exitCard, so reset this for getPrinterInfo.
awaitingCardExit = false;
finishTime = 0;
STATUS = 1;
}
if (STATUS == 0)
@ -2677,8 +2690,14 @@ int WINAPI chcusb_testCardFeed(uint16_t mode, uint16_t times, uint16_t *rResult)
int WINAPI chcusb_exitCard(uint16_t *rResult) {
dprintf("Printer: C3XXusb: %s\n", __func__);
awaitingCardExit = false;
generate_rfid();
if (check_for_wait_time()) {
*rResult = 2203;
return 0;
} else {
awaitingCardExit = false;
finishTime = 0;
generate_rfid();
}
*rResult = 0;
return 1;

View File

@ -12,6 +12,7 @@ struct printer_config {
wchar_t dsp_fw_path[MAX_PATH];
wchar_t param_fw_path[MAX_PATH];
wchar_t printer_out_path[MAX_PATH];
uint32_t wait_time;
};
void printer_hook_init(const struct printer_config *cfg, int rfid_port_no, HINSTANCE self);