summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
Diffstat (limited to 'avr')
-rw-r--r--avr/main.c22
1 files changed, 8 insertions, 14 deletions
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();