Fix warning about possible string truncation in the TempDataLogger project.
[pub/USBasp.git] / Projects / TempDataLogger / TempDataLogger.c
index 15c3e6a..816c326 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2013.
+     Copyright (C) Dean Camera, 2018.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -44,7 +44,7 @@ USB_ClassInfo_MS_Device_t Disk_MS_Interface =
        {
                .Config =
                        {
        {
                .Config =
                        {
-                               .InterfaceNumber           = 0,
+                               .InterfaceNumber           = INTERFACE_ID_MassStorage,
                                .DataINEndpoint            =
                                        {
                                                .Address           = MASS_STORAGE_IN_EPADDR,
                                .DataINEndpoint            =
                                        {
                                                .Address           = MASS_STORAGE_IN_EPADDR,
@@ -72,7 +72,7 @@ USB_ClassInfo_HID_Device_t Generic_HID_Interface =
        {
                .Config =
                        {
        {
                .Config =
                        {
-                               .InterfaceNumber              = 1,
+                               .InterfaceNumber              = INTERFACE_ID_HID,
                                .ReportINEndpoint             =
                                        {
                                                .Address              = GENERIC_IN_EPADDR,
                                .ReportINEndpoint             =
                                        {
                                                .Address              = GENERIC_IN_EPADDR,
@@ -125,7 +125,7 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
                char     LineBuffer[100];
                uint16_t BytesWritten;
 
                char     LineBuffer[100];
                uint16_t BytesWritten;
 
-               BytesWritten = sprintf(LineBuffer, "%02d/%02d/20%02d, %02d:%02d:%02d, %d Degrees\r\n",
+               BytesWritten = snprintf(LineBuffer, sizeof(LineBuffer), "%02d/%02d/20%02d, %02d:%02d:%02d, %d Degrees\r\n",
                                       CurrentTimeDate.Day, CurrentTimeDate.Month, CurrentTimeDate.Year,
                                       CurrentTimeDate.Hour, CurrentTimeDate.Minute, CurrentTimeDate.Second,
                                       Temperature_GetTemperature());
                                       CurrentTimeDate.Day, CurrentTimeDate.Month, CurrentTimeDate.Year,
                                       CurrentTimeDate.Hour, CurrentTimeDate.Minute, CurrentTimeDate.Second,
                                       Temperature_GetTemperature());
@@ -168,12 +168,12 @@ int main(void)
 /** Opens the log file on the Dataflash's FAT formatted partition according to the current date */
 void OpenLogFile(void)
 {
 /** Opens the log file on the Dataflash's FAT formatted partition according to the current date */
 void OpenLogFile(void)
 {
-       char LogFileName[12];
+       char LogFileName[16];
 
        /* Get the current date for the filename as "DDMMYY.csv" */
        TimeDate_t CurrentTimeDate;
        RTC_GetTimeDate(&CurrentTimeDate);
 
        /* Get the current date for the filename as "DDMMYY.csv" */
        TimeDate_t CurrentTimeDate;
        RTC_GetTimeDate(&CurrentTimeDate);
-       sprintf(LogFileName, "%02d%02d%02d.csv", CurrentTimeDate.Day, CurrentTimeDate.Month, CurrentTimeDate.Year);
+       snprintf(LogFileName, sizeof(LogFileName), "%02d%02d%02d.csv", CurrentTimeDate.Day, CurrentTimeDate.Month, CurrentTimeDate.Year);
 
        /* Mount the storage device, open the file */
        f_mount(0, &DiskFATState);
 
        /* Mount the storage device, open the file */
        f_mount(0, &DiskFATState);
@@ -211,8 +211,8 @@ void SetupHardware(void)
        RTC_Init();
 
        /* 500ms logging interval timer configuration */
        RTC_Init();
 
        /* 500ms logging interval timer configuration */
-       OCR1A   = (((F_CPU / 1024) / 2) - 1);
-       TCCR1B  = (1 << WGM12) | (1 << CS12) | (1 << CS10);
+       OCR1A   = (((F_CPU / 256) / 2) - 1);
+       TCCR1B  = (1 << WGM12) | (1 << CS12);
        TIMSK1  = (1 << OCIE1A);
 
        /* Check if the Dataflash is working, abort if not */
        TIMSK1  = (1 << OCIE1A);
 
        /* Check if the Dataflash is working, abort if not */