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