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