Why the fuck are you only printing the last line?
This commit is contained in:
parent
6dd486d5f3
commit
f1ef2fbb7c
4 changed files with 66 additions and 38 deletions
|
@ -82,7 +82,7 @@ static uint8_t spi_send_byte(uint8_t value) {
|
|||
_delay_us(60);
|
||||
}
|
||||
|
||||
_delay_us(270);
|
||||
_delay_us(210);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -103,8 +103,6 @@ static void spi_send_packet() {
|
|||
|
||||
response.device = spi_send_byte(0);
|
||||
response.status = spi_send_byte(0);
|
||||
|
||||
_delay_us(270);
|
||||
}
|
||||
|
||||
static uint16_t checksum() {
|
||||
|
|
76
bin/main.c
76
bin/main.c
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <tabby/link.h>
|
||||
|
@ -19,20 +20,34 @@ static void usage(int argc, char **argv, char *message, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s device\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s device sheet.tile\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int fd;
|
||||
int fd, tile_fd;
|
||||
|
||||
tabby_printer_packet header;
|
||||
tabby_printer_response response;
|
||||
void *tile;
|
||||
|
||||
uint16_t response;
|
||||
if (argc != 3) {
|
||||
usage(argc, argv, "Must specify device and tile");
|
||||
}
|
||||
|
||||
if (argc != 2) {
|
||||
usage(argc, argv, "No device specified");
|
||||
if ((tile = malloc(TABBY_PRINTER_SHEET_SIZE)) == NULL) {
|
||||
goto error_malloc_tile;
|
||||
}
|
||||
|
||||
if ((tile_fd = open(argv[2], O_RDONLY)) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "open()", argv[2], strerror(errno));
|
||||
|
||||
goto error_open_tile;
|
||||
}
|
||||
|
||||
if (read(tile_fd, tile, TABBY_PRINTER_SHEET_SIZE) < 0) {
|
||||
goto error_read_tile;
|
||||
}
|
||||
|
||||
if ((fd = tabby_link_open(argv[1])) < 0) {
|
||||
|
@ -42,27 +57,41 @@ int main(int argc, char **argv) {
|
|||
goto error_link_open;
|
||||
}
|
||||
|
||||
header.preamble[0] = 0x88;
|
||||
header.preamble[1] = 0x33;
|
||||
header.type = 0x0f;
|
||||
header.compression = 0;
|
||||
header.size = 0;
|
||||
|
||||
printf("Waiting for AVR to reboot after CTS\n");
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf("Initializing link\n");
|
||||
tabby_printer_link_init(fd);
|
||||
|
||||
//tabby_printer_link_init(fd);
|
||||
tabby_printer_init(fd, &response);
|
||||
|
||||
printf("Interrogating printer\n");
|
||||
printf("Initializing printer, got response %02x%02x\n",
|
||||
response.device, response.status);
|
||||
|
||||
if (tabby_printer_packet_send(fd, &header, NULL, &response) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "tabby_printer_packet_send()", argv[1], strerror(errno));
|
||||
} else {
|
||||
printf("Got response code %04x\n", response);
|
||||
while (response.device != 0x81) {
|
||||
tabby_printer_send_inquiry(fd, &response);
|
||||
|
||||
printf("Waiting for printer, status %02x%02x\n",
|
||||
response.device, response.status);
|
||||
}
|
||||
|
||||
tabby_printer_send_sheet(fd, tile, &response);
|
||||
|
||||
printf("Sent sheet, got response %02x%02x\n",
|
||||
response.device, response.status);
|
||||
|
||||
tabby_printer_job_start(fd, 1, 0x13, 0, 0x40, &response);
|
||||
|
||||
printf("Started job, got status %02x%02x\n",
|
||||
response.device, response.status);
|
||||
|
||||
while (response.status) {
|
||||
tabby_printer_send_inquiry(fd, &response);
|
||||
|
||||
printf("Printer status %02x%02x\n",
|
||||
response.device, response.status);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
tabby_link_close(fd);
|
||||
|
@ -70,5 +99,12 @@ int main(int argc, char **argv) {
|
|||
return 0;
|
||||
|
||||
error_link_open:
|
||||
error_read_tile:
|
||||
close(tile_fd);
|
||||
|
||||
error_open_tile:
|
||||
free(tile);
|
||||
|
||||
error_malloc_tile:
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -93,9 +93,6 @@ int tabby_printer_job_start(int fd, uint8_t sheets,
|
|||
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);
|
||||
|
||||
|
|
|
@ -175,20 +175,11 @@ int tabby_printer_job_start(int fd, uint8_t sheets,
|
|||
sheets, linefeeds, palette, density
|
||||
};
|
||||
|
||||
init_header(&header, TABBY_PRINTER_PACKET_INQUIRY, sizeof(body));
|
||||
init_header(&header, TABBY_PRINTER_PACKET_JOB, 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;
|
||||
|
@ -203,8 +194,9 @@ int tabby_printer_send_sheet(int fd, void *data,
|
|||
int i;
|
||||
size_t offset = 0;
|
||||
|
||||
tabby_printer_packet header;
|
||||
|
||||
for (i=0; i<TABBY_PRINTER_SHEET_BANDS; i++) {
|
||||
tabby_printer_packet header;
|
||||
tabby_printer_response current;
|
||||
|
||||
init_header(&header,
|
||||
|
@ -218,9 +210,14 @@ int tabby_printer_send_sheet(int fd, void *data,
|
|||
}
|
||||
|
||||
offset += TABBY_PRINTER_BAND_SIZE;
|
||||
|
||||
printf("Sent band, got status %02x%02x\n",
|
||||
current.device, current.status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
init_header(&header, TABBY_PRINTER_PACKET_DATA, 0);
|
||||
|
||||
return tabby_printer_packet_send(fd, &header, NULL, response);
|
||||
|
||||
error_packet_send:
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Reference in a new issue