Implement stuff to print like, a thing

This commit is contained in:
XANTRONIX Development 2016-06-04 20:33:10 -05:00
parent 75dd5b3c9b
commit 6dd486d5f3
2 changed files with 138 additions and 0 deletions

View file

@ -3,6 +3,12 @@
#define TABBY_PRINTER_MAX_PACKET_SIZE 640 #define TABBY_PRINTER_MAX_PACKET_SIZE 640
#define TABBY_PRINTER_BAND_SIZE 640
#define TABBY_PRINTER_SHEET_BANDS 9
#define TABBY_PRINTER_SHEET_SIZE \
(TABBY_PRINTER_SHEET_BANDS * TABBY_PRINTER_BAND_SIZE)
typedef enum { typedef enum {
TABBY_PRINTER_LOWBAT = (1 << 7), TABBY_PRINTER_LOWBAT = (1 << 7),
TABBY_PRINTER_ER2 = (1 << 6), TABBY_PRINTER_ER2 = (1 << 6),
@ -14,6 +20,19 @@ typedef enum {
TABBY_PRINTER_SUM = (1 << 0) TABBY_PRINTER_SUM = (1 << 0)
} tabby_printer_status; } tabby_printer_status;
typedef enum {
TABBY_PRINTER_PACKET_INIT = 0x01,
TABBY_PRINTER_PACKET_JOB = 0x02,
TABBY_PRINTER_PACKET_DATA = 0x04,
TABBY_PRINTER_PACKET_CANCEL = 0x08,
TABBY_PRINTER_PACKET_INQUIRY = 0x0f
} tabby_printer_packet_type;
typedef enum {
TABBY_PRINTER_COMPRESSION_NONE = 0x00,
TABBY_PRINTER_COMPRESSION_RLE = 0x01
} tabby_printer_compression;
/* /*
* Data definitions for packets sent from Game Boy to printer * Data definitions for packets sent from Game Boy to printer
*/ */
@ -31,6 +50,15 @@ typedef struct _tabby_printer_packet {
}; };
} tabby_printer_packet; } tabby_printer_packet;
typedef struct _tabby_printer_job_packet {
tabby_printer_packet header;
uint8_t sheets,
linefeeds,
palette,
density;
} tabby_printer_job_packet;
typedef struct _tabby_printer_response { typedef struct _tabby_printer_response {
uint8_t device; uint8_t device;
uint8_t status; uint8_t status;
@ -53,4 +81,25 @@ int tabby_printer_packet_send(int fd,
void *body, void *body,
tabby_printer_response *response); tabby_printer_response *response);
int tabby_printer_init(int fd,
tabby_printer_response *response);
int tabby_printer_send_inquiry(int fd,
tabby_printer_response *response);
int tabby_printer_job_start(int fd, uint8_t sheets,
uint8_t linefeeds,
uint8_t palette,
uint8_t density,
tabby_printer_response *response);
int tabby_printer_job_finish(int fd,
tabby_printer_response *response);
int tabby_printer_job_cancel(int fd,
tabby_printer_response *response);
int tabby_printer_send_sheet(int fd, void *data,
tabby_printer_response *response);
#endif /* _TABBY_PRINTER_H */ #endif /* _TABBY_PRINTER_H */

View file

@ -136,3 +136,92 @@ int tabby_printer_packet_send(int fd,
error_io: error_io:
return -1; return -1;
} }
static void init_header(tabby_printer_packet *header,
tabby_printer_packet_type type, size_t size) {
header->preamble[0] = 0x88;
header->preamble[1] = 0x33;
header->type = type;
header->compression = TABBY_PRINTER_COMPRESSION_NONE;
header->size = (uint16_t)size;
}
int tabby_printer_init(int fd,
tabby_printer_response *response) {
tabby_printer_packet header;
init_header(&header, TABBY_PRINTER_PACKET_INIT, 0);
return tabby_printer_packet_send(fd, &header, NULL, response);
}
int tabby_printer_send_inquiry(int fd,
tabby_printer_response *response) {
tabby_printer_packet header;
init_header(&header, TABBY_PRINTER_PACKET_INQUIRY, 0);
return tabby_printer_packet_send(fd, &header, NULL, response);
}
int tabby_printer_job_start(int fd, uint8_t sheets,
uint8_t linefeeds,
uint8_t palette,
uint8_t density,
tabby_printer_response *response) {
tabby_printer_packet header;
uint8_t body[4] = {
sheets, linefeeds, palette, density
};
init_header(&header, TABBY_PRINTER_PACKET_INQUIRY, sizeof(body));
return tabby_printer_packet_send(fd, &header, &body, response);
}
int tabby_printer_job_finish(int fd,
tabby_printer_response *response) {
tabby_printer_packet header;
init_header(&header, TABBY_PRINTER_PACKET_DATA, 0);
return tabby_printer_packet_send(fd, &header, NULL, response);
}
int tabby_printer_job_cancel(int fd,
tabby_printer_response *response) {
tabby_printer_packet header;
init_header(&header, TABBY_PRINTER_PACKET_CANCEL, 0);
return tabby_printer_packet_send(fd, &header, NULL, response);
}
int tabby_printer_send_sheet(int fd, void *data,
tabby_printer_response *response) {
int i;
size_t offset = 0;
for (i=0; i<TABBY_PRINTER_SHEET_BANDS; i++) {
tabby_printer_packet header;
tabby_printer_response current;
init_header(&header,
TABBY_PRINTER_PACKET_DATA,
TABBY_PRINTER_BAND_SIZE);
if (tabby_printer_packet_send(fd, &header,
((uint8_t *)data) + offset,
&current) < 0) {
goto error_packet_send;
}
offset += TABBY_PRINTER_BAND_SIZE;
}
return 0;
error_packet_send:
return -1;
}