Use tabby_printer_response struct for good times!
This commit is contained in:
parent
6fa31cccd8
commit
75dd5b3c9b
3 changed files with 13 additions and 9 deletions
13
avr/send.c
13
avr/send.c
|
@ -12,13 +12,12 @@ static tabby_printer_packet header = {
|
||||||
.size = 0
|
.size = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static tabby_printer_response response;
|
||||||
|
|
||||||
static uint8_t body[TABBY_PRINTER_MAX_PACKET_SIZE];
|
static uint8_t body[TABBY_PRINTER_MAX_PACKET_SIZE];
|
||||||
|
|
||||||
static uint16_t sum = 0x0000;
|
static uint16_t sum = 0x0000;
|
||||||
|
|
||||||
static uint8_t device = 0x00,
|
|
||||||
status = 0x00;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* So like, we're abusing pins here. So badly, it's beyond. So here's what's
|
* So like, we're abusing pins here. So badly, it's beyond. So here's what's
|
||||||
* going down: We want to retain the same physical I/O connections between
|
* going down: We want to retain the same physical I/O connections between
|
||||||
|
@ -102,8 +101,8 @@ static void spi_send_packet() {
|
||||||
(void)spi_send_byte( sum & 0x00ff);
|
(void)spi_send_byte( sum & 0x00ff);
|
||||||
(void)spi_send_byte((sum & 0xff00) >> 8);
|
(void)spi_send_byte((sum & 0xff00) >> 8);
|
||||||
|
|
||||||
device = spi_send_byte(0);
|
response.device = spi_send_byte(0);
|
||||||
status = spi_send_byte(0);
|
response.status = spi_send_byte(0);
|
||||||
|
|
||||||
_delay_us(270);
|
_delay_us(270);
|
||||||
}
|
}
|
||||||
|
@ -228,8 +227,8 @@ int main() {
|
||||||
if (sum == checksum()) {
|
if (sum == checksum()) {
|
||||||
spi_send_packet();
|
spi_send_packet();
|
||||||
|
|
||||||
uart_putchar(device, NULL);
|
uart_putchar(response.device, NULL);
|
||||||
uart_putchar(status, NULL);
|
uart_putchar(response.status, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ typedef struct _tabby_printer_packet {
|
||||||
};
|
};
|
||||||
} tabby_printer_packet;
|
} tabby_printer_packet;
|
||||||
|
|
||||||
|
typedef struct _tabby_printer_response {
|
||||||
|
uint8_t device;
|
||||||
|
uint8_t status;
|
||||||
|
} tabby_printer_response;
|
||||||
|
|
||||||
int tabby_printer_link_init(int fd);
|
int tabby_printer_link_init(int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,6 +51,6 @@ int tabby_printer_packet_recv(int fd,
|
||||||
int tabby_printer_packet_send(int fd,
|
int tabby_printer_packet_send(int fd,
|
||||||
tabby_printer_packet *header,
|
tabby_printer_packet *header,
|
||||||
void *body,
|
void *body,
|
||||||
uint16_t *response);
|
tabby_printer_response *response);
|
||||||
|
|
||||||
#endif /* _TABBY_PRINTER_H */
|
#endif /* _TABBY_PRINTER_H */
|
||||||
|
|
|
@ -110,7 +110,7 @@ error_io:
|
||||||
int tabby_printer_packet_send(int fd,
|
int tabby_printer_packet_send(int fd,
|
||||||
tabby_printer_packet *header,
|
tabby_printer_packet *header,
|
||||||
void *body,
|
void *body,
|
||||||
uint16_t *response) {
|
tabby_printer_response *response) {
|
||||||
uint16_t sum = checksum(header, body);
|
uint16_t sum = checksum(header, body);
|
||||||
|
|
||||||
if (write(fd, header, sizeof(*header)) < 0) {
|
if (write(fd, header, sizeof(*header)) < 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue