aaa
Dependencies: IOTAtelier1819-FileSystem BSP_B-L475E-IOT01
Revision 27:e6be7f9b9e9f, committed 2018-12-06
- Comitter:
- frunzl
- Date:
- Thu Dec 06 12:14:07 2018 +0000
- Parent:
- 26:130bb1173866
- Commit message:
- temperature
Changed in this revision
diff -r 130bb1173866 -r e6be7f9b9e9f BSP_B-L475E-IOT01.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP_B-L475E-IOT01.lib Thu Dec 06 12:14:07 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST/code/BSP_B-L475E-IOT01/#9dfa42666f03
diff -r 130bb1173866 -r e6be7f9b9e9f IOTAtelier1819-FileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IOTAtelier1819-FileSystem.lib Thu Dec 06 12:14:07 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/lmottola/code/IOTAtelier1819-FileSystem/#130bb1173866
diff -r 130bb1173866 -r e6be7f9b9e9f main.cpp --- a/main.cpp Fri Nov 23 09:15:36 2018 +0000 +++ b/main.cpp Thu Dec 06 12:14:07 2018 +0000 @@ -21,6 +21,7 @@ // File systems #include "LittleFileSystem.h" #include "FATFileSystem.h" +#include "stm32l475e_iot01_tsensor.h" // Physical block device, can be any device that supports the BlockDevice API /*SPIFBlockDevice bd( @@ -28,50 +29,59 @@ MBED_CONF_SPIF_DRIVER_SPI_MISO, MBED_CONF_SPIF_DRIVER_SPI_CLK, MBED_CONF_SPIF_DRIVER_SPI_CS);*/ + +InterruptIn button(USER_BUTTON); +Ticker toggle_led_ticker; + +EventQueue queue(32 * EVENTS_EVENT_SIZE); +Thread t; #define BLOCK_SIZE 512 -HeapBlockDevice bd(2048, BLOCK_SIZE); +HeapBlockDevice bd(16384, BLOCK_SIZE); // File system declaration LittleFileSystem fs("fs"); -// Set up the button to trigger an erase -InterruptIn irq(BUTTON1); -void erase() { - printf("Initializing the block device... "); - fflush(stdout); - int err = bd.init(); - printf("%s\n", (err ? "Fail :(" : "OK")); - if (err) { - error("error: %s (%d)\n", strerror(-err), err); - } +static FILE *f; +volatile int counter = 0; - printf("Erasing the block device... "); +void get_data_from_sensors() { + float sensor_value=0; + sensor_value = BSP_TSENSOR_ReadTemp(); + fprintf(f, "%f\n", sensor_value); + fflush(f); fflush(stdout); - err = bd.erase(0, bd.size()); - printf("%s\n", (err ? "Fail :(" : "OK")); - if (err) { - error("error: %s (%d)\n", strerror(-err), err); - } - - printf("Deinitializing the block device... "); - fflush(stdout); - err = bd.deinit(); - printf("%s\n", (err ? "Fail :(" : "OK")); - if (err) { - error("error: %s (%d)\n", strerror(-err), err); - } + printf("Saving temperature...\n"); } +void print_data_from_file() { + fflush(stdout); + fflush(f); + fseek(f, 0, SEEK_SET); + float value; + while (!feof(f)) { + fscanf(f, "%f", &value); + printf("%f\n", value); + } + fflush(stdout); +} + +void toggle() { + queue.call(print_data_from_file); +} + +void toggle_led() { + queue.call(get_data_from_sensors); +} // Entry point for the example int main() { + t.start(callback(&queue, &EventQueue::dispatch_forever)); + BSP_TSENSOR_Init(); + button.rise(&toggle); + printf("--- Mbed OS filesystem example ---\n"); - // Setup the erase event on button press, use the event queue - // to avoid running in interrupt context - irq.fall(mbed_event_queue()->event(erase)); - // Try to mount the filesystem printf("Mounting the filesystem... "); fflush(stdout); @@ -92,7 +102,7 @@ // Open the numbers file printf("Opening \"/fs/numbers.txt\"... "); fflush(stdout); - FILE *f = fopen("/fs/numbers.txt", "r+"); + f = fopen("/fs/numbers.txt", "r +"); printf("%s\n", (!f ? "Fail :(" : "OK")); if (!f) { // Create the numbers file if it doesn't exist @@ -104,17 +114,6 @@ error("error: %s (%d)\n", strerror(errno), -errno); } - for (int i = 0; i < 10; i++) { - printf("\rWriting numbers (%d/%d)... ", i, 10); - fflush(stdout); - err = fprintf(f, " %d\n", i); - if (err < 0) { - printf("Fail :(\n"); - error("error: %s (%d)\n", strerror(errno), -errno); - } - } - printf("\rWriting numbers (%d/%d)... OK\n", 10, 10); - printf("Seeking file... "); fflush(stdout); err = fseek(f, 0, SEEK_SET); @@ -123,99 +122,9 @@ error("error: %s (%d)\n", strerror(errno), -errno); } } - - // Go through and increment the numbers - for (int i = 0; i < 10; i++) { - printf("\rIncrementing numbers (%d/%d)... ", i, 10); - fflush(stdout); - - // Get current stream position - long pos = ftell(f); - - // Parse out the number and increment - int32_t number; - fscanf(f, "%d", &number); - number += 1; - - // Seek to beginning of number - fseek(f, pos, SEEK_SET); - // Store number - fprintf(f, " %d\n", number); - - // Flush between write and read on same file - fflush(f); - } - printf("\rIncrementing numbers (%d/%d)... OK\n", 10, 10); - - // Close the file which also flushes any cached writes - printf("Closing \"/fs/numbers.txt\"... "); - fflush(stdout); - err = fclose(f); - printf("%s\n", (err < 0 ? "Fail :(" : "OK")); - if (err < 0) { - error("error: %s (%d)\n", strerror(errno), -errno); - } - - // Display the root directory - printf("Opening the root directory... "); - fflush(stdout); - DIR *d = opendir("/fs/"); - printf("%s\n", (!d ? "Fail :(" : "OK")); - if (!d) { - error("error: %s (%d)\n", strerror(errno), -errno); - } + // Go through and record the acc + toggle_led_ticker.attach(&toggle_led, 60); - printf("root directory:\n"); - while (true) { - struct dirent *e = readdir(d); - if (!e) { - break; - } - - printf(" %s\n", e->d_name); - } - - printf("Closing the root directory... "); - fflush(stdout); - err = closedir(d); - printf("%s\n", (err < 0 ? "Fail :(" : "OK")); - if (err < 0) { - error("error: %s (%d)\n", strerror(errno), -errno); - } - - // Display the numbers file - printf("Opening \"/fs/numbers.txt\"... "); - fflush(stdout); - f = fopen("/fs/numbers.txt", "r"); - printf("%s\n", (!f ? "Fail :(" : "OK")); - if (!f) { - error("error: %s (%d)\n", strerror(errno), -errno); - } - - printf("numbers:\n"); - while (!feof(f)) { - int c = fgetc(f); - printf("%c", c); - } - - printf("\rClosing \"/fs/numbers.txt\"... "); - fflush(stdout); - err = fclose(f); - printf("%s\n", (err < 0 ? "Fail :(" : "OK")); - if (err < 0) { - error("error: %s (%d)\n", strerror(errno), -errno); - } - - // Tidy up - printf("Unmounting... "); - fflush(stdout); - err = fs.unmount(); - printf("%s\n", (err < 0 ? "Fail :(" : "OK")); - if (err < 0) { - error("error: %s (%d)\n", strerror(-err), err); - } - - printf("Mbed OS filesystem example done!\n"); }