Skip to content

Commit

Permalink
Add LBP3010 support
Browse files Browse the repository at this point in the history
  • Loading branch information
missla committed Oct 30, 2015
1 parent 768976c commit e50f0a2
Showing 1 changed file with 60 additions and 21 deletions.
81 changes: 60 additions & 21 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 @@ -86,15 +89,19 @@ static const uint8_t magicbuf_2[] = {
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]);
lbp2900_wait_ready(state->ops);
send_job_start();
send_job_start(1,0);
lbp2900_wait_ready(state->ops);
}

Expand All @@ -104,20 +111,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 +142,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 +173,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,13 +211,15 @@ 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,
Expand Down

0 comments on commit e50f0a2

Please sign in to comment.