Check position. Use variable for button time.

This commit is contained in:
Lynn Ochs 2021-02-19 21:33:24 +01:00
parent bed7092e0a
commit e41375a43d

19
main.c
View File

@ -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)) {