A totally not-working WIP

This commit is contained in:
XANTRONIX Development 2016-06-06 01:42:17 -05:00
parent f8a3cf8d6b
commit 7059d688ac
3 changed files with 67 additions and 33 deletions

View file

@ -63,7 +63,10 @@ static uint16_t checksum(tabby_printer_packet *header, uint8_t *body) {
return sum;
}
static void spi_send_packet(uint8_t type, uint8_t *body, uint16_t size) {
static void spi_send_packet(uint8_t type,
uint8_t *body,
uint16_t size,
tabby_printer_response *response) {
tabby_printer_packet header = {
.preamble = { TABBY_PRINTER_SYNC_1, TABBY_PRINTER_SYNC_2 },
.type = type,
@ -86,41 +89,44 @@ static void spi_send_packet(uint8_t type, uint8_t *body, uint16_t size) {
(void)spi_send_byte( sum & 0x00ff);
(void)spi_send_byte((sum & 0xff00) >> 8);
(void)spi_send_byte(0);
(void)spi_send_byte(0);
response->device = spi_send_byte(0);
response->status = spi_send_byte(0);
}
static void spi_send_init() {
spi_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0);
static void spi_send_init(tabby_printer_response *response) {
spi_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0, response);
}
static void spi_send_job(uint8_t sheets,
uint8_t linefeeds,
uint8_t palette,
uint8_t density) {
uint8_t job[4] = {
sheets, linefeeds, palette, density
};
spi_send_packet(TABBY_PRINTER_PACKET_JOB, job, sizeof(job));
static void spi_send_inquiry(tabby_printer_response *response) {
spi_send_packet(TABBY_PRINTER_PACKET_INQUIRY, NULL, 0, response);
}
static void spi_send_data(uint8_t *data, uint16_t size) {
spi_send_packet(TABBY_PRINTER_PACKET_DATA, data, size);
static void spi_send_job(tabby_printer_job *job,
tabby_printer_response *response) {
spi_send_packet(TABBY_PRINTER_PACKET_JOB,
job->data,
sizeof(job),
response);
}
static void spi_send_sheet(uint8_t *sheet, uint16_t size) {
static void spi_send_data(uint8_t *data,
uint16_t size,
tabby_printer_response *response) {
spi_send_packet(TABBY_PRINTER_PACKET_DATA, data, size, response);
}
static void spi_send_sheet(uint8_t *sheet,
uint16_t size,
tabby_printer_response *response) {
int i;
spi_send_init();
spi_send_init(response);
for (i=0; i<size; i+=TABBY_PRINTER_BAND_SIZE) {
spi_send_data(sheet + i, TABBY_PRINTER_BAND_SIZE);
spi_send_data(sheet + i, TABBY_PRINTER_BAND_SIZE, response);
}
spi_send_data(NULL, 0);
spi_send_job(1, 0x13, 0x00, 0x40);
spi_send_data(NULL, 0, response);
}
int main() {
@ -134,6 +140,13 @@ int main() {
.size = 0
};
tabby_printer_response response = {
.device = TABBY_PRINTER_DEVICE_ID,
.status = TABBY_PRINTER_OK
};
tabby_printer_job job;
uint8_t sheet[TABBY_PRINTER_SHEET_SIZE];
uart_init();
@ -226,7 +239,12 @@ int main() {
default: {
if (b < header.size) {
if (header.type == TABBY_PRINTER_PACKET_JOB) {
job.data[b] = c;
} else if (header.type == TABBY_PRINTER_PACKET_DATA) {
sheet[sheet_offset++] = c;
}
b++;
} else if (b == header.size) {
b++;
@ -234,18 +252,18 @@ int main() {
i = 0;
b = 0;
switch (header.type) {
case TABBY_PRINTER_PACKET_DATA: {
if (header.size == 0) {
spi_send_sheet(sheet, sheet_offset);
if (header.type == TABBY_PRINTER_PACKET_JOB) {
spi_send_sheet(sheet, sheet_offset, &response);
spi_send_job(&job, &response);
sheet_offset = 0;
}
}
} else if (header.type == TABBY_PRINTER_PACKET_INQUIRY) {
spi_send_inquiry(&response);
}
uart_putchar(TABBY_PRINTER_DEVICE_ID, NULL);
uart_putchar(0x00, NULL);
uart_putchar(response.device, NULL);
uart_putchar(response.status, NULL);
}
}
}

View file

@ -77,6 +77,8 @@ int main(int argc, char **argv) {
printf("Sent sheet, got response %02x%02x\n",
response.device, response.status);
tabby_printer_job_start(fd, 1, 0x13, 0x00, 0x40, &response);
while (response.status & TABBY_PRINTER_UNTRAN) {
tabby_printer_send_inquiry(fd, &response);

View file

@ -23,7 +23,8 @@ typedef enum {
TABBY_PRINTER_UNTRAN = (1 << 3),
TABBY_PRINTER_FULL = (1 << 2),
TABBY_PRINTER_BUSY = (1 << 1),
TABBY_PRINTER_SUM = (1 << 0)
TABBY_PRINTER_SUM = (1 << 0),
TABBY_PRINTER_OK = 0
} tabby_printer_status;
typedef enum {
@ -56,6 +57,19 @@ typedef struct _tabby_printer_packet {
};
} tabby_printer_packet;
typedef struct _tabby_printer_job {
union {
struct {
uint8_t sheets,
linefeeds,
palette,
density;
};
uint8_t data[4];
};
} tabby_printer_job;
typedef struct _tabby_printer_buffer {
tabby_printer_packet header;
uint8_t body[TABBY_PRINTER_PACKET_MAX_SIZE];