Data sample and LCD plot

Dependencies:   BSP_DISCO_F746NG LCD_DISCO_F746NG SDRAM_DISCO_F746NG mbed

Files at this revision

API Documentation at this revision

Comitter:
tapiov
Date:
Fri Feb 23 20:28:44 2018 +0000
Parent:
1:c3c61d08f31b
Commit message:
New commit for forum review

Changed in this revision

functions.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
diff -r c3c61d08f31b -r 386f65563144 functions.cpp
--- a/functions.cpp	Fri Feb 23 16:56:03 2018 +0000
+++ b/functions.cpp	Fri Feb 23 20:28:44 2018 +0000
@@ -167,15 +167,12 @@
     for(i=0;i<NoOfPoints;i++) {
         Data->array[i]=(uint32_t)((0x0000 << 16) | ain.read_u16());
         wait_us(Period_us);
-        //if ((i%100)==0) {
-        //    pc2.printf("index i = %u",i);
-        //}
     }
 
     InitScreen(LCD_COLOR_BLACK,LCD_COLOR_WHITE);
     LCDWrite(5,"DONE!",CENTER_MODE);
 
-    pc2.printf("\r\nSampling done, index i = %u \r\n",i);
+    pc2.printf("Sampling done.\r\n",i);
 }
 
 void AvgAndPlotPoints(Array *Data,uint32_t NoOfPoints, uint32_t AvgSize) {
diff -r c3c61d08f31b -r 386f65563144 main.cpp
--- a/main.cpp	Fri Feb 23 16:56:03 2018 +0000
+++ b/main.cpp	Fri Feb 23 20:28:44 2018 +0000
@@ -2,8 +2,7 @@
 // (C) Tapio Valli 2018-02-17
 
 #include "mbed.h"
-#include <mbed_stats.h>
-#include "mbed_mem_trace.h"
+#include "mbed_stats.h"
 
 #include "LCD_DISCO_F746NG.h"
 
@@ -20,54 +19,36 @@
 Serial pc1(USBTX, USBRX);
 LCD_DISCO_F746NG lcd1;
 
-
-// Global heap stats
-mbed_stats_heap_t heap_stats;
-//mbed_stats_stack_t stack_stats;
-//mbed_mem_trace_cb_t mem_trace_result;
-
-// Mem trace callback
-// mbed_mem_trace_cb_t mem_trace(void) 
-// {
-//     pc1.printf("Heap = %lu, Max = %lu Percentage = %lu \r\n",
-//                heap_stats.current_size,heap_stats.max_size,
-//                (100*(heap_stats.current_size/heap_stats.max_size)));
-                   
-//    pc1.printf("Stack = %lu, Max = %lu Percentage = %lu \r\n",
-//                stack_stats.reserved_size,stack_stats.max_size,
-//                (100*(stack_stats.reserved_size/stack_stats.max_size)));    
-//}
-
 int main() {
 
     char CmdBuffer[30];
     char Arg[30]=" ";
     char Cmd[30]=" ";
+    size_t n=0;
 
     uint32_t    NoOfPoints=19200;  
     uint32_t    AvgSize=10;
     uint32_t    Period_us=100;
     uint32_t    Count_ms=1000;
-        
-//    mbed_mem_trace_set_callback(mem_trace);
+    
+    mbed_stats_heap_t heap_stats;
         
     // Clear screen, set it up 
     InitScreen(LCD_COLOR_BLACK,LCD_COLOR_WHITE);
-    
+        
     //Initialize data storage
     Array Data;
     initArray(&Data,NoOfPoints);  // initially 19200 elements
     
-    while (Cmd!="quit") {
+    while (!((strcmp(Cmd,"quit")==0)&&(n==1))) {
         
         // Print Ready and current settings 
         pc1.printf("Ready. Settings are Points = %u, Avg = %u, Period_us = %u, Count_ms = %u \r\n",
                    NoOfPoints,AvgSize,Period_us,Count_ms);
-
-        mbed_stats_heap_get(&heap_stats);                
-        pc1.printf("Heap = %lu, Max = %lu Percentage = %lu \r\n",
-                   heap_stats.current_size,heap_stats.max_size,
-                   (100*(heap_stats.current_size/heap_stats.max_size)));
+                   
+        mbed_stats_heap_get(&heap_stats);
+        printf("Current heap: %lu\r\n", heap_stats.current_size);
+        printf("Max heap size: %lu\r\n", heap_stats.max_size);
                                                                             
         pc1.gets(CmdBuffer,30);
         // pc1.printf("I got %s \r\n", CmdBuffer);
@@ -76,60 +57,67 @@
                 
         // Parse command and possible numeric arg
         char s[] = "Initial string";
-        char ** word_array = NULL;
+        char ** word_array=NULL;
         
         strcpy(s,CmdBuffer);
-        size_t n = string_parser(s, &word_array );
+        n=string_parser(s,&word_array);
 
-        for ( size_t i = 0; i < n; i++ ) {
+        for ( size_t i=0;i<n;i++) {
             if (i==0) {strcpy(Cmd,word_array[i]);}
             if (i==1) {strcpy(Arg,word_array[i]);}
             if (i>1) {pc1.printf("Wrong number of arguments \r\n");}
         }
         
         // pc1.printf("Cmd = %s Arg = %s \r\n",Cmd,Arg);
-        for ( size_t i = 0; i < n; i++ ) free( word_array[i] );
-        free( word_array );
+        for ( size_t i=0;i<n;i++) free( word_array[i] );
+        free(word_array);
     
         // Branch based on command        
         // meas: Sample and plot a data set
-        if(strcmp(Cmd,"meas") == 0) {
+        if((strcmp(Cmd,"meas")==0)&&(n==1)) {
             
             // Countdown
             CountDown(Count_ms);
                                  
             // Sample & plot data one time
             SamplePoints(&Data,NoOfPoints,Period_us);
-            
             AvgAndPlotPoints(&Data,NoOfPoints,AvgSize);
         }
         
         // setpoints: Adjust sampled points                          
-        else if(strcmp(Cmd,"setpoints") == 0) {
+        else if((strcmp(Cmd,"setpoints")==0)&&(n==2)) {
             // Allocate more or less data space
             NoOfPoints=(uint32_t) strtol(Arg,NULL,10);
             insertArray(&Data,NoOfPoints);
         }
             
         // setavg: Adjust average amount in samples            
-        else if(strcmp(Cmd,"setavg") == 0) {
+        else if((strcmp(Cmd,"setavg")==0)&&(n==2)) {
             AvgSize=(uint32_t) strtol(Arg,NULL,10);
         }
             
         // setperiod: Adjust sample period in us
-        else if(strcmp(Cmd,"setperiod") == 0) {
+        else if((strcmp(Cmd,"setperiod")==0)&&(n==2)) {
             Period_us=(uint32_t) strtol(Arg,NULL,10);
         }
         
         // setcount: Adjust countdown period in ms
-        else if(strcmp(Cmd,"setcount") == 0) {
+        else if((strcmp(Cmd,"setcount")==0)&&(n==2)) {
             Count_ms=(uint32_t) strtol(Arg,NULL,10);
-        }        
+        }
+        
+        // quit: Exit on next while
+        else if((strcmp(Cmd,"quit")==0)&&(n==1)) {
+            // Do nothing yet
+        }
+        else {
+            pc1.printf("Wrong command or argument \r\n");
+        }
     }
     
     // Free memory after quit
     freeArray(&Data);
-    pc1.printf("Exit. Data freed. \r\n", CmdBuffer);
+    pc1.printf("Exit. Data freed. \r\n");
     
     // Infinite loop
     while(1) 
diff -r c3c61d08f31b -r 386f65563144 mbed_app.json
--- a/mbed_app.json	Fri Feb 23 16:56:03 2018 +0000
+++ b/mbed_app.json	Fri Feb 23 20:28:44 2018 +0000
@@ -1,3 +1,4 @@
 {
-    "macros": ["MBED_MEM_TRACING_ENABLED"]
-}
\ No newline at end of file
+    "macros": ["MBED_HEAP_STATS_ENABLED=1"]
+}
+