Skip to content

Commit

Permalink
LBP2900, LBP3000 support improvements
Browse files Browse the repository at this point in the history
Improve page size support by matching page parameters used on Windows driver for LBP3000 and LBP2900

Add LBP2900 and 3000 button LED support, LBP2900 button now works

Handle job cancellation gracefully with SIGTERM handler. Signals are now handled with POSIX's sigaction(). A fallback to the ISO-specified signal() is available, see std.h

Implement 10mm hardware margin for envelope sizes

Miscellaneous fixes in PPD source file

Add experimental Pause After Each Page option

Use cupsInteger0 instead to toggle Toner Save
  • Loading branch information
mounaiban committed Nov 16, 2020
1 parent 0b71004 commit 711d4a5
Show file tree
Hide file tree
Showing 14 changed files with 568 additions and 885 deletions.
353 changes: 0 additions & 353 deletions Canon-LBP2900.ppd

This file was deleted.

353 changes: 0 additions & 353 deletions Canon-LBP3000.ppd

This file was deleted.

2 changes: 1 addition & 1 deletion configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([captdriver], [0.1.3])
AC_INIT([captdriver], [0.1.4])

AC_CONFIG_SRCDIR([src/std.h])

Expand Down
223 changes: 120 additions & 103 deletions src/canon-lbp.drv
Expand Up @@ -15,122 +15,139 @@
Copyright "(C)2020 Moses Chong"
ColorModel "Gray/Grayscale" k chunky 2
Filter application/vnd.cups-raster 1 rastertocapt
*Manufacturer "Canon Inc"
Version 0.1.3
*Manufacturer "Canon"
Version 0.1.4-m5
{
Font *

// Common Sizes
*MediaSize A4
MediaSize A5
MediaSize A6
MediaSize B6
MediaSize C6
MediaSize EnvC5
MediaSize EnvC6
MediaSize EnvChou3
MediaSize EnvDL
MediaSize Env10
MediaSize EnvItalian
MediaSize Executive // US 7.25x10.5 inch
MediaSize Folio // SE Asian F4
MediaSize Legal
MediaSize Letter
MediaSize SISG5
MediaSize SISE5
MediaSize SAC16K
MediaSize SAC32K

// Less Common Sizes
/*
* Sizes A6 and larger, and no wider than US Legal have
* been included here.
*
* PROTIP: Delete this section and recompile PPD, for a
* less cluttered Paper Size menu in most applications,
* if you don't use these sizes. If you use any of them,
* move the sizes you need from below to the section above,
* then delete the rest.
*
* NOTE: Some of the sizes appear to be identical to
* another at least in terms of width and length. There
* could be other differences, and may be useful in managing
* multiple trays on printers that support them.
*
*/
MediaSize 7x9
MediaSize 8x10
MediaSize A4Small // Same dimensions as A4
MediaSize A4Plus // Longer than Folio (F4) by just one point
MediaSize A5Extra
MediaSize B5
MediaSize B7
MediaSize DoublePostcard
MediaSize Env9
MediaSize Env11
MediaSize Env12
MediaSize Env14
MediaSize EnvC65
MediaSize EnvChou4
MediaSize EnvISOB5
MediaSize EnvISOB6
MediaSize EnvKaku3
MediaSize EnvMonarch
MediaSize EnvPersonal
MediaSize EnvPRC1
MediaSize EnvPRC2
MediaSize EnvPRC3
MediaSize EnvPRC4
MediaSize EnvPRC5
MediaSize EnvPRC6
MediaSize EnvPRC7
MediaSize EnvPRC8
MediaSize EnvYou4
MediaSize FanFoldGerman
MediaSize FanFoldGermanLegal
MediaSize ISOB5
MediaSize ISOB5Extra
MediaSize ISOB6
MediaSize ISOB7
MediaSize LetterPlus
MediaSize Note // Same dimensions as Letter (US)
MediaSize Postcard
MediaSize PRC16K
MediaSize PRC32K
MediaSize PRC32KBig
MediaSize Quarto
MediaSize Statement
// End Less Common Sizes

// Toner Save Option
/* Toner Save Option */
Option "captTonerSave/Toner Save" Boolean AnySetup 10
*Choice False/Disabled "<</cupsCompression 0>>setpagedevice"
Choice True/Enabled "<</cupsCompression 1>>setpagedevice"
*Choice False/Disabled "<</cupsInteger0 0>>setpagedevice"
Choice True/Enabled "<</cupsInteger0 1>>setpagedevice"

/* Pause After Each Page Option */
Option "pauseAfterEachPage/Pause After Each Page" Boolean AnySetup 11
*Choice False/No "<</cupsInteger1 0>>setpagedevice"
Choice True/Yes "<</cupsInteger1 1>>setpagedevice"

*Resolution k 1 70 592 0 "600dpi/600 DPI"
MaxSize 215.9mm 355.6mm // US Legal
MediaType 0 "Plain/Plain Paper"
MediaType 1 "Heavy/Heavy Paper"
MediaType 2 "PlainL/Plain Paper L"
MediaType 3 "HeavyH/Heavy Paper H"
MediaType 4 "Transparency"
MediaType 5 "Envelope"
VariablePaperSize yes
{
// nearly matched to Alexey Galakhov's original 2011 specs
/* LBP 3010 */
/* nearly matched to Alexey Galakhov's original 2011 specs */
*ModelName "LBP2900/LBP3010 r2c"
FileName "Canon-LBP2900.ppd"
*MediaSize A4
FileName "Canon-LBP3010.ppd"
MinSize 75mm 105mm
HWmargins 4.7095835mm 4.7095835mm 4.709583mm 4.709583mm
PCFileName "CNLB2K9.ppd"
PCFileName "CNLB3K10.ppd"
}

{
*ModelName "LBP3000 r2c"
FileName "Canon-LBP3000.ppd"
HWmargins 5mm 5mm 5mm 5mm
MinSize 75mm 105mm
PCFileName "CNLB3K.ppd"
/* LBP 2900/3000, with multi-page size and type support */
MediaType 0 "Plain/Plain Paper"
MediaType 1 "Heavy/Heavy Paper"
MediaType 2 "PlainL/Plain Paper L"
MediaType 3 "HeavyH/Heavy Paper H"
MediaType 4 "Transparency"
MediaType 5 "Envelope"

MinSize 76.2mm 127.0mm
MaxSize 215.9mm 355.6mm // US Legal
HWmargins 5mm 5mm 5mm 5mm

/*
* NOTE: Some of the sizes appear to be identical to
* another at least in terms of width and length. There
* could be other differences, and may be useful in managing
* multiple trays on printers that support them.
*
*/

/* Common Document Sizes */
VariablePaperSize yes
*MediaSize A4
MediaSize A5
MediaSize B5
MediaSize Executive // US 7.25x10.5 inch
MediaSize Folio // SE Asian F4
MediaSize Legal
MediaSize Letter
MediaSize SISG5
MediaSize SISE5
MediaSize SAC16K
MediaSize SAC32K

/* Less Common Document Sizes
*
* PROTIP: Delete this section and recompile PPD, if page size
* menus in your most used apps clutter up and cannot be managed.
* Any size below may be moved to the list above, before deleting
* this section.
*/
MediaSize 8x10
MediaSize A4Small // Same dimensions as A4
MediaSize A4Plus // Longer than Folio (F4) by just one point
MediaSize A5Extra
MediaSize A6
MediaSize B6
MediaSize B7
MediaSize DoublePostcard
MediaSize FanFoldGerman
MediaSize FanFoldGermanLegal
MediaSize ISOB5
MediaSize ISOB5Extra
MediaSize ISOB6
MediaSize ISOB7
MediaSize LetterPlus
MediaSize Note // Same dimensions as Letter (US)
MediaSize Postcard
MediaSize PRC16K
MediaSize PRC32K
MediaSize PRC32KBig
MediaSize Quarto
MediaSize Statement

/* Common Envelope Sizes */
HWmargins 10mm 10mm 10mm 10mm
MediaSize Env10
MediaSize EnvC5
MediaSize EnvChou4
MediaSize EnvDL
MediaSize EnvItalian

/* Less Common Envelope Sizes */
/*
* PROTIP: Delete this section as necessary. If any size below
* is needed, move it to the list above before deleting this section.
*
*/
MediaSize 7x9
MediaSize C6
MediaSize Env9
MediaSize Env11
MediaSize Env12
MediaSize Env14
MediaSize EnvC6
MediaSize EnvC65
MediaSize EnvChou3
MediaSize EnvISOB5
MediaSize EnvISOB6
MediaSize EnvKaku3
MediaSize EnvMonarch
MediaSize EnvPersonal
MediaSize EnvPRC1
MediaSize EnvPRC2
MediaSize EnvPRC3
MediaSize EnvPRC4
MediaSize EnvPRC5
MediaSize EnvPRC6
MediaSize EnvPRC7
MediaSize EnvPRC8
MediaSize EnvYou4

*ModelName "LBP2900/LBP3000 r2c"
FileName "Canon-LBP2900-3000.ppd"
PCFileName "CNLB2K9.ppd"
}
}

45 changes: 40 additions & 5 deletions src/capt-command.c
Expand Up @@ -30,6 +30,8 @@

static uint8_t capt_iobuf[0x10000];
static size_t capt_iosize;
static cups_sc_status_t last_send_status = CUPS_SC_STATUS_NONE;
static bool sendrecv_started = false;

static void capt_debug_buf(const char *level, size_t size)
{
Expand Down Expand Up @@ -57,7 +59,6 @@ static void capt_send_buf(void)
}

while (iosize) {
cups_sc_status_t status;
uint8_t tmpbuf[128];
size_t tmpsize = sizeof(tmpbuf);
size_t sendsize = iosize;
Expand All @@ -69,15 +70,16 @@ static void capt_send_buf(void)
iosize -= sendsize;
fflush(stdout);

status = cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT,
last_send_status = cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT,
(char *) tmpbuf, (int *) &tmpsize, 1.0);
if (status != CUPS_SC_STATUS_OK) {
if (status == CUPS_SC_STATUS_TIMEOUT) {

if (last_send_status != CUPS_SC_STATUS_OK) {
if (last_send_status == CUPS_SC_STATUS_TIMEOUT) {
/* Overcome race conditions in usb backend */
fprintf(stderr, "DEBUG: CAPT: output already empty, not drained\n");
} else {
fprintf(stderr, "ERROR: CAPT: no reply from backend, err=%i\n",
(int) status);
(int) last_send_status);
exit(1);
}
}
Expand Down Expand Up @@ -145,6 +147,9 @@ void capt_send(uint16_t cmd, const void *buf, size_t size)

void capt_sendrecv(uint16_t cmd, const void *buf, size_t size, void *reply, size_t *reply_size)
{
sendrecv_started = true;
last_send_status = CUPS_SC_STATUS_NONE;

capt_send(cmd, buf, size);
capt_recv_buf(0, 6);
if (capt_iosize != 6 || WORD(capt_iobuf[0], capt_iobuf[1]) != cmd) {
Expand Down Expand Up @@ -182,6 +187,9 @@ void capt_sendrecv(uint16_t cmd, const void *buf, size_t size, void *reply, size
}
if (reply_size)
*reply_size = capt_iosize;

sendrecv_started = false;
last_send_status = CUPS_SC_STATUS_NONE;
}

void capt_multi_begin(uint16_t cmd)
Expand All @@ -202,3 +210,30 @@ void capt_multi_send(void)
capt_iobuf[3] = HI(capt_iosize);
capt_send_buf();
}

void capt_cleanup(void)
{
/* For use with handling job cancellations */
if (sendrecv_started) {

if (last_send_status != CUPS_SC_STATUS_OK) {
capt_send_buf();
fprintf(stderr, "DEBUG: CAPT: finished interrupted send\n");
}

/* not else because recv cleanup is needed after finishing send */
if (last_send_status == CUPS_SC_STATUS_OK) {
size_t bytes = 0x10000;
size_t bs = 64;
while(bytes > 0) {
bytes -= bs;
cupsBackChannelRead(NULL, bs, 0.01);
}
fprintf(stderr, "DEBUG: CAPT: finished interrupted recv\n");
}

capt_iosize = 0;
sendrecv_started = false;
}
}

2 changes: 1 addition & 1 deletion src/capt-command.h
Expand Up @@ -54,7 +54,6 @@ enum capt_command {
CAPT_GPIO = 0xE1A2,
};


const char *capt_identify(void);

void capt_send(uint16_t cmd, const void *data, size_t size);
Expand All @@ -63,3 +62,4 @@ void capt_sendrecv(uint16_t cmd, const void *buf, size_t size, void *reply, size
void capt_multi_begin(uint16_t cmd);
void capt_multi_add(uint16_t cmd, const void *data, size_t size);
void capt_multi_send(void);
void capt_cleanup(void);
2 changes: 2 additions & 0 deletions src/generic-ops.c
Expand Up @@ -39,6 +39,8 @@ size_t ops_compress_band_hiscoa(struct printer_state_s *state,

void ops_send_band_hiscoa(struct printer_state_s *state, const void *data, size_t size)
{
(void) job_cancel; /* suppress unused static variable warning */

const uint8_t *pdata = (const uint8_t *) data;
while (size) {
size_t send = 0xFF00;
Expand Down
13 changes: 6 additions & 7 deletions src/paper.c
Expand Up @@ -23,13 +23,12 @@
void page_set_dims(struct page_dims_s *dims, const struct cups_page_header2_s *header)
{
dims->media_type = header->cupsMediaType;
dims->paper_width_pts = header->PageSize[0];
dims->paper_height_pts = header->PageSize[1];
dims->paper_width = header->PageSize[0] * header->HWResolution[0] / 72;
dims->paper_height = header->PageSize[1] * header->HWResolution[1] / 72;
/*
The use of cupsCompression to toggle toner save was inspired by the
use of the same attribute to control darkness in label printer drivers.
*/
dims->toner_save = header->cupsCompression;
dims->margin_height = header->Margins[0];
dims->margin_width = header->Margins[1];
dims->h_dpi = header->HWResolution[0];
dims->w_dpi = header->HWResolution[1];
dims->pause = (header->cupsInteger[1] != 0);
dims->toner_save = header->cupsInteger[0];
}

0 comments on commit 711d4a5

Please sign in to comment.