Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
Diff: sdLogger/sdLogger.cpp
- Revision:
- 3:d7ec6dc025b0
- Parent:
- 2:bf699e054b34
--- a/sdLogger/sdLogger.cpp Sun Feb 25 16:40:28 2018 +0000 +++ b/sdLogger/sdLogger.cpp Fri Mar 30 10:32:10 2018 +0000 @@ -6,19 +6,20 @@ #include "SDBlockDevice.h" #include "LittleFileSystem.h" #include "FATFileSystem.h" +#include "logger.h" static void return_error(int ret_val){ if (ret_val) printf("SD: Failure. %d\r\n", ret_val); - else - printf("SD: done.\r\n"); + //else + //printf("SD: done.\r\n"); } static void errno_error(void* ret_val){ if (ret_val == NULL) printf("SD: Failure. %d \r\n", errno); - else - printf("SD: done.\r\n"); + //else + //printf("SD: done.\r\n"); } class SDLogger { @@ -26,9 +27,11 @@ static void run() { for (;;) { - char buffer[200]; - sprintf(buffer, "Pressure: %4.1f \t Temperature: %3.2f\t Altitude: %4.1f\r\nACC1:%2.1f;%2.1f;%2.1f\r\nACC2:%2.1f;%2.1f;%2.1f\r\n", pressure, temperature, altitude, (acc1[0]), (acc1[1]), (acc1[2]),(acc2[0]), (acc2[1]), (acc2[2])); - SD_appendData(buffer); + //char buffer[200]; + //sprintf(buffer, "Pressure: %4.1f \t Temperature: %3.2f\t Altitude: %4.1f\r\nACC1:%2.1f;%2.1f;%2.1f\r\nACC2:%2.1f;%2.1f;%2.1f\r\n", pressure, temperature, altitude, (acc1[0]), (acc1[1]), (acc1[2]),(acc2[0]), (acc2[1]), (acc2[2])); + char* msg = (char*) Logger::q.get(osWaitForever).value.p; + SD_appendData(msg); + delete[] msg; rtos::Thread::wait(6000);//10 datasets per minute. TODO: log current system time } } @@ -57,19 +60,19 @@ fclose(fd); printf("SD: done.\r\n"); } -static void SD_appendData(char* data) +static void SD_appendData(const char* data) { - printf("SD: Opening file data.txt.\r\n"); + //printf("SD: Opening file data.txt.\r\n"); FILE* fd = fopen("/fs/data.txt", "w+"); errno_error(fd); fprintf(fd, "%s", data); - printf("SD: Writing done.\r\n"); + //printf("SD: Writing done.\r\n"); - printf("SD: Closing file.\r\n"); + //printf("SD: Closing file.\r\n"); fclose(fd); - printf("SD: done.\r\n"); + //printf("SD: done.\r\n"); } static SDBlockDevice bd;//PinName mosi, PinName miso, PinName sclk, PinName cs static FATFileSystem fs;