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

View file

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