From 4407c8d39ff31912e080fd98aca03ddde236239d Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 13 Dec 2016 21:20:29 +0100 Subject: Process inputs even when USB is inactive. --- main.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 931485e..5c66b67 100644 --- a/main.cpp +++ b/main.cpp @@ -498,6 +498,8 @@ int main() { qe2a.set_mode(Pin::AF); qe2b.set_mode(Pin::AF); + uint32_t last_time = 0; + uint8_t last_x = 0; uint8_t last_y = 0; @@ -507,20 +509,22 @@ int main() { while(1) { usb.process(); - uint16_t buttons = button_inputs.get() ^ 0x7ff; - if(do_reset_bootloader) { Time::sleep(10); reset_bootloader(); } - if(Time::time() - last_led_time > 1000) { + uint16_t buttons = button_inputs.get() ^ 0x7ff; + uint8_t x = TIM2.CNT; + uint8_t y = TIM3.CNT; + uint32_t time = Time::time(); + + if(time - last_led_time > 1000) { button_leds.set(buttons); } - if(usb.ep_ready(1)) { - uint8_t x = TIM2.CNT; - uint8_t y = TIM3.CNT; + if(last_time != time) { + last_time = time; int8_t rx = x - last_x; int8_t ry = y - last_y; last_x = x; @@ -558,9 +562,6 @@ int main() { buttons |= 1 << 14; } - report_t report = {buttons, x, y}; - - usb.write(1, (uint32_t*)&report, sizeof(report)); /* uint32_t ps_state = (1 << 5) | (1 << 6) | (1 << 7); @@ -592,5 +593,10 @@ int main() { spi_ps.set_state(ps_state); } + + if(usb.ep_ready(1)) { + report_t report = {buttons, x, y}; + usb.write(1, (uint32_t*)&report, sizeof(report)); + } } } -- cgit v1.2.3