From c23307d11666127bfd495dba8839d0e54e23f0aa Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 24 Jan 2016 18:33:50 +0100 Subject: . --- avr/main.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'avr') diff --git a/avr/main.c b/avr/main.c index 635c44d..9810e49 100644 --- a/avr/main.c +++ b/avr/main.c @@ -43,6 +43,9 @@ #define FUNC_START_BOOTLOADER 30 #define FUNC_GET_TYPE 0xFE +volatile int got_data = 0; // set to 1, if we get data to write from the PC + + void jump_to_bootloader(void) { cli(); @@ -67,6 +70,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) len = 0; break; case FUNC_READ: + got_data = 1; return USB_NO_MSG; case FUNC_WRITE: @@ -149,7 +153,7 @@ int main(void) wdt_reset(); // keep the watchdog happy usbPoll(); - if (++c % 3000 == 0) + if (++c % (got_data ? 1500 : 3000) == 0) { PORTC^=LED_BLUE; PORTC |= LED_RED | LED_GREEN; @@ -157,27 +161,17 @@ int main(void) if (c % 12000 == 0) { uint8_t result = w1_reset(); - if (result == 0) + if (result == 0) // device detected { PORTC &= ~LED_GREEN; ds1992_read(0, replyBuffer, 128); } - else if (result == 1) + else if (result == 1) // no presence pulse == no device detected PORTC &= ~LED_RED; - else + else // short circuit detected PORTC &= ~(LED_RED | LED_GREEN); } - /*if ( (c / 3000) % 40 == 0) - { - PORTC &= ~LED_RED; - usb_disconnect(); - } - else if ((c / 3000) % 40 == 20) - { - usb_reconnect(); - PORTC |= LED_RED; - }*/ } jump_to_bootloader(); -- cgit v1.2.1