diff --git a/avr/send.c b/avr/send.c index 4178196..5610fed 100644 --- a/avr/send.c +++ b/avr/send.c @@ -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