Added incomplete MIDIToneGenerator project.
[pub/USBasp.git] / Projects / TemperatureDataLogger / TempDataLogger.c
index 538a6a5..955359d 100644 (file)
@@ -96,6 +96,7 @@ FATFS DiskFATState;
 FIL TempLogFile;\r
 \r
 \r
+/** ISR to handle the 500ms ticks for sampling and data logging */\r
 ISR(TIMER1_COMPA_vect, ISR_BLOCK)\r
 {\r
        uint8_t LEDMask = LEDs_GetLEDs();\r
@@ -109,6 +110,7 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
        /* Reset log tick counter to prepare for next logging interval */\r
        CurrentLoggingTicks = 0;\r
        \r
+       /* Only log when not connected to a USB host */\r
        if (USB_DeviceState == DEVICE_STATE_Unattached)\r
        {\r
                uint8_t Day,  Month,  Year;\r
@@ -138,15 +140,15 @@ int main(void)
        /* Fetch logging interval from EEPROM */\r
        LoggingInterval500MS_SRAM = eeprom_read_byte(&LoggingInterval500MS_EEPROM);\r
 \r
-       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
-\r
        SetupHardware();\r
 \r
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+\r
        /* Mount and open the log file on the dataflash FAT partition */\r
        OpenLogFile();\r
 \r
        /* Discard the first sample from the temperature sensor, as it is generally incorrect */\r
-       uint8_t Dummy = Temperature_GetTemperature();\r
+       volatile uint8_t Dummy = Temperature_GetTemperature();\r
        (void)Dummy;\r
        \r
        for (;;)\r
@@ -157,6 +159,7 @@ int main(void)
        }\r
 }\r
 \r
+/** Opens the log file on the Dataflash's FAT formatted partition according to the current date */\r
 void OpenLogFile(void)\r
 {\r
        char LogFileName[12];\r
@@ -172,6 +175,7 @@ void OpenLogFile(void)
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
 }\r
 \r
+/** Closes the open data log file on the Dataflash's FAT formatted partition */\r
 void CloseLogFile(void)\r
 {\r
        /* Sync any data waiting to be written, unmount the storage device */\r
@@ -196,6 +200,7 @@ void SetupHardware(void)
        Temperature_Init();\r
        Dataflash_Init();\r
        USB_Init();\r
+       TWI_Init();\r
        \r
        /* 500ms logging interval timer configuration */\r
        OCR1A   = ((F_CPU / 1024) / 2);\r
@@ -301,6 +306,7 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
        DS1307_SetDate(ReportParams->Day,  ReportParams->Month,  ReportParams->Year);\r
        DS1307_SetTime(ReportParams->Hour, ReportParams->Minute, ReportParams->Second);\r
        \r
+       /* If the logging interval has changed from its current value, write it to EEPROM */\r
        if (LoggingInterval500MS_SRAM != ReportParams->LogInterval500MS)\r
        {\r
                LoggingInterval500MS_SRAM = ReportParams->LogInterval500MS;\r