SO FREAKING ANNOYINGLY CLOSE

This commit is contained in:
XANTRONIX Development 2016-06-02 23:32:38 -05:00
parent a43cb02ec9
commit 84b5d6a2c9
2 changed files with 34 additions and 18 deletions

View file

@ -152,19 +152,24 @@ static uint16_t checksum() {
} }
int main() { int main() {
uint16_t sum = 0; uint16_t sum = 0,
c;
uart_init(); uart_init();
sei(); sei();
while (1) { while (1) {
uint8_t c; uart_putchar('O', NULL);
while (flags != TABBY_SEND_READING) { c = uart_getchar(NULL);
sleep_mode();
if (c == 'K') {
break;
}
} }
while (1) {
if (flags & TABBY_SEND_COMPLETE) { if (flags & TABBY_SEND_COMPLETE) {
uart_putchar(device, NULL); uart_putchar(device, NULL);
uart_putchar(status, NULL); uart_putchar(status, NULL);
@ -172,6 +177,8 @@ int main() {
flags = TABBY_SEND_READING; flags = TABBY_SEND_READING;
} }
while (flags != TABBY_SEND_READING);
c = uart_getchar(NULL); c = uart_getchar(NULL);
switch (i) { switch (i) {
@ -250,9 +257,10 @@ int main() {
} else if (b == header.size + 1) { } else if (b == header.size + 1) {
sum |= c << 8; sum |= c << 8;
if (sum == checksum()) {
i = 0; i = 0;
b = 0; b = 0;
if (sum == checksum()) {
flags |= TABBY_SEND_BUFFERED; flags |= TABBY_SEND_BUFFERED;
spi_start(); spi_start();

View file

@ -25,11 +25,11 @@ static void usage(int argc, char **argv, char *message, ...) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int fd, status; int fd;
tabby_printer_packet header; tabby_printer_packet header;
uint8_t body[TABBY_PRINTER_MAX_PACKET_SIZE]; uint16_t response;
if (argc != 2) { if (argc != 2) {
usage(argc, argv, "No device specified"); usage(argc, argv, "No device specified");
@ -42,19 +42,27 @@ int main(int argc, char **argv) {
goto error_link_open; goto error_link_open;
} }
while (1) { header.preamble[0] = 0x88;
status = tabby_printer_packet_recv(fd, &header, &body); header.preamble[1] = 0x33;
header.type = 0x0f;
header.compression = 0;
header.size = 0;
if (status < 0) { printf("Waiting for AVR to reboot after CTS\n");
fprintf(stderr, "%s: %s: %s\n",
argv[0], "tabby_printer_packet_recv()", strerror(errno));
continue; sleep(1);
}
if (header.type == 0x04) { printf("Initializing link\n");
write(1, body, header.size);
} tabby_printer_link_init(fd);
printf("Interrogating printer\n");
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);
} }
tabby_link_close(fd); tabby_link_close(fd);