Skip to content

Commit

Permalink
Merge pull request agalakhov#8 from missla/lbp3010
Browse files Browse the repository at this point in the history
Lbp3010
  • Loading branch information
agalakhov committed May 13, 2016
2 parents b1849a8 + 6938395 commit 75f78a8
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Canon-LBP-2900.ppd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*OpenUI *Resolution/Resolution: PickOne
*OrderDependency: 10 AnySetup *Resolution
*DefaultResolution: 600dpi
*Resolution 600dpi/600 DPI: "<</HWResolution[600 600]/cupsBitsPerColor 1/cupsRowCount 70/cupsRowFeed 592/cupsRowStep 0/cupsColorSpace 3>>setpagedevice"
*Resolution 600dpi/600 DPI: "<</HWResolution[600 400]/cupsBitsPerColor 1/cupsRowCount 70/cupsRowFeed 592/cupsRowStep 0/cupsColorSpace 3>>setpagedevice"
*CloseUI: *Resolution
*DefaultFont: Courier
*Font AvantGarde-Book: Standard "(1.05)" Standard ROM
Expand Down
1 change: 1 addition & 0 deletions src/capt-command.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum capt_command {
CAPT_JOB_END = 0xE0A9,

CAPT_JOB_SETUP = 0xE1A1,
CAPT_GPIO = 0xE1A2,
};


Expand Down
14 changes: 14 additions & 0 deletions src/capt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static void decode_status(const uint8_t *s, size_t size)
status.page_printing = WORD(s[16], s[17]);
status.page_out = WORD(s[18], s[19]);
status.page_completed = WORD(s[20], s[21]);
status.page_received = WORD(s[34], s[35]);

status.status[4] = WORD(s[24], s[25]);

Expand Down Expand Up @@ -99,6 +100,13 @@ const struct capt_status_s *capt_get_xstatus_only(void)
{
download_status(CAPT_CHKXSTATUS);
print_status();
/*
if (FLAG(&status, CAPT_FL_JOBSTAT_CHNG)) {
capt_sendrecv(CAPT_CHKJOBSTAT, NULL, 0, NULL, 0);
print_status();
}
*/

return &status;
}

Expand All @@ -121,3 +129,9 @@ void capt_wait_xready(void)
while (FLAG(capt_get_xstatus(), CAPT_FL_BUSY))
sleep(1);
}

void capt_wait_xready_only(void)
{
while (FLAG(capt_get_xstatus_only(), CAPT_FL_BUSY))
sleep(1);
}
2 changes: 2 additions & 0 deletions src/capt-status.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct capt_status_s {
uint16_t page_printing;
uint16_t page_out;
uint16_t page_completed;
uint16_t page_received;
};

#define _FL(s, b) ((s << 16) | (1 << b))
Expand Down Expand Up @@ -72,3 +73,4 @@ const struct capt_status_s *capt_get_xstatus_only(void);
const struct capt_status_s *capt_get_xstatus(void);
void capt_wait_ready(void);
void capt_wait_xready(void);
void capt_wait_xready_only(void);
116 changes: 91 additions & 25 deletions src/prn_lbp2900.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <time.h>
#include <unistd.h>

uint16_t job;

struct lbp2900_ops_s {
struct printer_ops_s ops;

Expand All @@ -52,25 +54,26 @@ static void lbp2900_wait_ready(const struct printer_ops_s *ops)
lops->wait_ready();
}

static void send_job_start()
static void send_job_start(uint8_t fg, uint16_t page)
{
uint16_t page = 1; /* nobody cares */
uint8_t nl = 16;
uint8_t fg = 0x01;
uint16_t job = 1; /* nobody cares */
uint8_t ml = 0x00; /* host name lenght */
uint8_t ul = 0x00; /* user name lenght */
uint8_t nl = 0x00; /* document name lenght */
time_t rawtime = time(NULL);
const struct tm *tm = localtime(&rawtime);
uint8_t buf[32 + 64 + nl];
uint8_t buf[32 + 40 + ml + ul + nl];
uint8_t head[32] = {
0x00, 0x00, 0x00, 0x00, LO(page), HI(page), 0x00, 0x00,
0x10, 0x00, 0x0C, 0x00, nl, 0x00, 0x00, 0x00,
fg, 0x01, LO(job), HI(job), /*-60*/ 0xC4, 0xFF, /*-120*/ 0x88, 0xFF,
ml, 0x00, ul, 0x00, nl, 0x00, 0x00, 0x00,
fg, 0x01, LO(job), HI(job),
/*-60 */ 0xC4, 0xFF,
/*-120*/ 0x88, 0xFF,
LO(tm->tm_year), HI(tm->tm_year), (uint8_t) tm->tm_mon, (uint8_t) tm->tm_mday,
(uint8_t) tm->tm_hour, (uint8_t) tm->tm_min, (uint8_t) tm->tm_sec,
0x01,
};
memcpy(buf, head, sizeof(head));
memset(buf + 32, 0, 64 + nl);
memset(buf + 32, 0, 40 + ml + ul + nl);
capt_sendrecv(CAPT_JOB_SETUP, buf, sizeof(buf), NULL, 0);
}

Expand All @@ -83,18 +86,38 @@ static const uint8_t magicbuf_2[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const uint8_t blinkonbuf[] = {
/* led */ 0x31, 0x00, 0x00, /* S6 */ 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* S7 */ 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};

static const uint8_t blinkoffbuf[] = {
/* led */ 0x13, 0x00, 0x00, /* S6 */ 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* S7 */ 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};


static void lbp2900_job_prologue(struct printer_state_s *state)
{
(void) state;
uint8_t buf[8];
size_t size;

capt_sendrecv(CAPT_IDENT, NULL, 0, NULL, 0);
sleep(1);
capt_init_status();
lbp2900_get_status(state->ops);

capt_sendrecv(CAPT_START_0, NULL, 0, NULL, 0);
capt_sendrecv(CAPT_JOB_BEGIN, magicbuf_0, ARRAY_SIZE(magicbuf_0), NULL, 0);
capt_sendrecv(CAPT_JOB_BEGIN, magicbuf_0, ARRAY_SIZE(magicbuf_0), buf, &size);
job=WORD(buf[2], buf[3]);

capt_sendrecv(CAPT_GPIO, blinkoffbuf, ARRAY_SIZE(blinkoffbuf), NULL, 0);
lbp2900_wait_ready(state->ops);
send_job_start();

send_job_start(1,0);
lbp2900_wait_ready(state->ops);
}

Expand All @@ -104,20 +127,28 @@ static bool lbp2900_page_prologue(struct printer_state_s *state, const struct pa
size_t s;
uint8_t buf[16];

uint8_t pt1 = 0x00;
uint8_t pt1 = 0x01;
uint8_t save = 0x00;
uint8_t pt2 = 0x01;

uint8_t pageparms[] = {
0x00, 0x00, 0x30, 0x2A, /* sz */ 0x02, 0x00, 0x00, 0x00,
0x1F, 0x1F, 0x1F, 0x1F, pt1, 0x11, 0x04, 0x00,
0x01, 0x01, 0x02, save, 0x00, 0x00, /*120*/ 0x78, 0x00,
/*96*/ 0x60, 0x00,
0x1C, 0x1C, 0x1C, 0x1C, pt1, /* adapt */ 0x81, 0x04, 0x00,
0x01, 0x01, /* img ref */ 0x00, save, 0x00, 0x00,
/* height margin 118 */ 0x76, 0x00,
/* width margin 78 */ 0x4e, 0x00,
LO(dims->line_size), HI(dims->line_size), LO(dims->num_lines), HI(dims->num_lines),
LO(dims->paper_width), HI(dims->paper_width),
LO(dims->paper_height), HI(dims->paper_height),
/* 34 bytes */
0x00, 0x00, pt2, 0x00, 0x00, 0x00,
/* 72 bytes */
/*
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
*/
};

(void) state;
Expand All @@ -127,6 +158,13 @@ static bool lbp2900_page_prologue(struct printer_state_s *state, const struct pa
capt_sendrecv(CAPT_START_1, NULL, 0, NULL, 0);
capt_sendrecv(CAPT_START_2, NULL, 0, NULL, 0);
capt_sendrecv(CAPT_START_3, NULL, 0, NULL, 0);

/* FIXME: wait for printer is free (could it be potentially dangerous or really mandatory?) */
while ( ! FLAG(lbp2900_get_status(state->ops), ((4 << 16) | (1 << 0)) ) )
sleep(1);
lbp2900_get_status(state->ops);


lbp2900_wait_ready(state->ops);
capt_sendrecv(CAPT_UPLOAD_2, magicbuf_2, ARRAY_SIZE(magicbuf_2), NULL, 0);
lbp2900_wait_ready(state->ops);
Expand All @@ -151,18 +189,33 @@ static bool lbp2900_page_prologue(struct printer_state_s *state, const struct pa

static bool lbp2900_page_epilogue(struct printer_state_s *state, const struct page_dims_s *dims)
{
uint8_t buf[2] = { LO(state->ipage), HI(state->ipage) };
(void) dims;
const struct capt_status_s *status;

capt_send(CAPT_PRINT_DATA_END, NULL, 0);

/* waiting until the page is received */
while (1) {
sleep(1);
status = lbp2900_get_status(state->ops);
if (status->page_received == status->page_decoding)
break;
}
send_job_start(2, status->page_decoding);
lbp2900_wait_ready(state->ops);

uint8_t buf[2] = { LO(status->page_decoding), HI(status->page_decoding) };
capt_sendrecv(CAPT_FIRE, buf, 2, NULL, 0);
lbp2900_wait_ready(state->ops);

send_job_start(6, status->page_decoding);

while (1) {
const struct capt_status_s *status = lbp2900_get_status(state->ops);
/* Interesting. Using page_printing here results in shifted print */
if (status->page_out >= state->ipage)
if (status->page_out == status->page_decoding)
return true;
if (FLAG(status, CAPT_FL_NOPAPER2)) {
if (FLAG(status, CAPT_FL_NOPAPER2) || FLAG(status, CAPT_FL_NOPAPER1)) {
fprintf(stderr, "DEBUG: CAPT: no paper\n");
if (FLAG(status, CAPT_FL_PRINTING) || FLAG(status, CAPT_FL_PROCESSING1))
continue;
Expand All @@ -174,21 +227,23 @@ static bool lbp2900_page_epilogue(struct printer_state_s *state, const struct pa

static void lbp2900_job_epilogue(struct printer_state_s *state)
{
uint8_t buf[2] = { LO(state->ipage), HI(state->ipage) };
uint8_t jbuf[2] = { LO(job), HI(job) };

while (1) {
if (lbp2900_get_status(state->ops)->page_completed >= state->ipage)
const struct capt_status_s *status = lbp2900_get_status(state->ops);
if (status->page_completed == status->page_decoding)
break;
sleep(1);
}
capt_sendrecv(CAPT_JOB_END, buf, 2, NULL, 0);
capt_sendrecv(CAPT_JOB_END, jbuf, 2, NULL, 0);
}

static void lbp2900_page_setup(struct printer_state_s *state,
struct page_dims_s *dims,
unsigned width, unsigned height)
{
/*
A4 4736x6784
A4 4736x6778 or 4736x4520
Letter 4864x6368
Legal 4864x8192
Executive 4128x6080
Expand All @@ -198,23 +253,34 @@ static void lbp2900_page_setup(struct printer_state_s *state,
(void) width;
dims->band_size = 70;
dims->line_size = 4736 / 8;
if (height > 6784)
dims->num_lines = 6784;
if (height > 4520)
dims->num_lines = 4520;
else
dims->num_lines = height;
}

static void lbp2900_wait_user(struct printer_state_s *state)
{
(void) state;

capt_sendrecv(CAPT_GPIO, blinkonbuf, ARRAY_SIZE(blinkonbuf), NULL, 0);
lbp2900_wait_ready(state->ops);

while (1) {
const struct capt_status_s *status = lbp2900_get_status(state->ops);
if (FLAG(status, CAPT_FL_BUTTON)) {
fprintf(stderr, "DEBUG: CAPT: button pressed\n");
// break;
}
if (FLAG(status, CAPT_FL_nERROR)) {
fprintf(stderr, "DEBUG: CAPT: virtual button pressed\n");
break;
}
sleep(1);
}

capt_sendrecv(CAPT_GPIO, blinkoffbuf, ARRAY_SIZE(blinkoffbuf), NULL, 0);
lbp2900_wait_ready(state->ops);
}

static struct lbp2900_ops_s lbp2900_ops = {
Expand Down Expand Up @@ -247,7 +313,7 @@ static struct lbp2900_ops_s lbp3010_ops = {
.wait_user = lbp2900_wait_user,
},
.get_status = capt_get_xstatus_only,
.wait_ready = capt_wait_xready,
.wait_ready = capt_wait_xready_only,
};

register_printer("LBP3010/LBP3018/LBP3050", lbp3010_ops.ops, EXPERIMENTAL);

0 comments on commit 75f78a8

Please sign in to comment.