From 2942ea4465feab44ff89d57680614f47eb3c314b Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 26 Aug 2013 20:04:02 +0200 Subject: Use button state for LED control if more than a second passed since last update. --- main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 0e5298d..8a093b0 100644 --- a/main.cpp +++ b/main.cpp @@ -159,6 +159,8 @@ Pin& usb_pu = PA15; USB_f1 usb(USB, dev_desc_p, conf_desc_p); +uint32_t last_led_time; + class USB_HID : public USB_class_driver { private: USB_generic& usb; @@ -216,6 +218,7 @@ class USB_HID : public USB_class_driver { if(len == 2) { uint32_t buf; usb.read(ep, &buf, len); + last_led_time = Time::time(); GPIOC.reg.ODR = buf & 0x7ff; } } @@ -304,7 +307,10 @@ int main() { usb.process(); uint16_t buttons = (~GPIOB.reg.IDR & 0x7ff); - //GPIOC.reg.ODR = buttons; + + if(Time::time() - last_led_time > 1000) { + GPIOC.reg.ODR = buttons; + } if(usb.ep_ready(1)) { report_t report = {buttons, uint8_t(TIM2.CNT), uint8_t(TIM3.CNT)}; -- cgit v1.2.3