Update copyright year to 2010.
[pub/USBasp.git] / Projects / TemperatureDataLogger / TempDataLogger.c
index 6cb1792..b181ec2 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
@@ -64,7 +64,7 @@ FATFS DiskFATState;
 /** FAT Fs structure to hold a FAT file handle for the log data write destination. */\r
 FIL TempLogFile;\r
 \r
-/** Counter to count the number of 10 millisecond tick that has elapsed since the last sample */\r
+/** Counter to count the number of 10 millisecond ticks that has elapsed since the last sample */\r
 uint16_t CurrentLogTick;\r
 \r
 \r
@@ -73,6 +73,10 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
        if (CurrentLogTick++ != LOG_INTERVAL_10MS)\r
          return;\r
          \r
+       uint8_t LEDMask = LEDs_GetLEDs();\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
+\r
        CurrentLogTick = 0;\r
 \r
        if (USB_DeviceState == DEVICE_STATE_Unattached)\r
@@ -80,6 +84,8 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
                f_printf(&TempLogFile, "%d Degrees\r\n", Temperature_GetTemperature());\r
                f_sync(&TempLogFile);\r
        }\r
+       \r
+       LEDs_SetAllLEDs(LEDMask);\r
 }\r
 \r
 \r
@@ -96,11 +102,12 @@ int main(void)
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
-\r
-       /* Write out the log seperator line */\r
        f_printf(&TempLogFile, "===========================\r\n");\r
-       Temperature_GetTemperature(); // Discard first temperature reading to ensure accuracy\r
-\r
+       \r
+       /* Discard the first sample from the temperature sensor, as it is generally incorrect */\r
+       uint8_t Dummy = Temperature_GetTemperature();\r
+       (void)Dummy;\r
+       \r
        for (;;)\r
        {\r
                MS_Device_USBTask(&Disk_MS_Interface);\r
@@ -121,15 +128,14 @@ void SetupHardware(void)
        /* Hardware Initialization */\r
        LEDs_Init();\r
        SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);\r
-       Dataflash_Init();\r
-       USB_Init();\r
        ADC_Init(ADC_REFERENCE_AVCC | ADC_FREE_RUNNING | ADC_PRESCALE_128);\r
        Temperature_Init();\r
+       Dataflash_Init();\r
+       USB_Init();\r
        \r
        /* 10ms interval timer configuration */\r
        OCR1A   = (((F_CPU / 1024) / 100) - 1);\r
-       TCCR1A  = (1 << WGM01);  // CTC mode\r
-       TCCR1B  = (1 << CS12) | (1 << CS10);   // Fcpu/1024 speed\r
+       TCCR1B  = (1 << WGM12) | (1 << CS12) | (1 << CS10);   // CTC mode, Fcpu/1024 speed\r
        TIMSK1  = (1 << OCIE1A);\r
 \r
        /* Clear Dataflash sector protections, if enabled */\r
@@ -154,6 +160,7 @@ void EVENT_USB_Device_Disconnect(void)
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
+       f_printf(&TempLogFile, "===========================\r\n");\r
 }\r
 \r
 /** Event handler for the library USB Configuration Changed event. */\r