diff --git a/main.c b/main.c index 4758476..3d61d8e 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,9 @@ #include "usb.h" #include "ringbuffer.h" #include "uart.h" +#include "encoder.h" + +static const uint32_t button_time = 100; volatile uint32_t tick = 0; RINGBUFFER_STORAGE(usb_to_uart_buf, 64) @@ -46,10 +49,12 @@ int main(void) { uart_setup(); sys_tick_setup(); buttons_setup(); + encoder_setup(); nvic_enable_irq(NVIC_USART3_IRQ); uint32_t last_tick = tick; + int last_pos = 0; while (1) { /* Handle control messages through the comms CDC */ char buf[64]; @@ -66,14 +71,24 @@ int main(void) { printf("%lu", (unsigned long)adc_bat_voltage()); break; case 'O': - buttons_open(15); + buttons_open(button_time); break; case 'C': - buttons_close(15); + buttons_close(button_time); + break; + case 'R': + printf("pos: %d", encoder_get()); break; } } + int pos = encoder_get(); + if (pos != last_pos && ringbuffer_empty(comm_out_buf)) { + printf("pos: %d", pos); + last_pos = pos; + } + + /* Send replies */ if ((buf_len = ringbuffer_peek(comm_out_buf, &buf[0], sizeof buf))) { if (usb_write_cdcacm(ACM_COMM, (void *)buf, buf_len, 1)) {