Data sample and LCD plot
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG SDRAM_DISCO_F746NG mbed
main.cpp
- Committer:
- tapiov
- Date:
- 2018-02-23
- Revision:
- 1:c3c61d08f31b
- Parent:
- 0:b3e6088c873f
- Child:
- 2:386f65563144
File content as of revision 1:c3c61d08f31b:
// LoadCell_STM32_RAM v2 main
// (C) Tapio Valli 2018-02-17
#include "mbed.h"
#include <mbed_stats.h>
#include "mbed_mem_trace.h"
#include "LCD_DISCO_F746NG.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include "main.h"
// define the Serial object
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]=" ";
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);
// 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") {
// 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)));
pc1.gets(CmdBuffer,30);
// pc1.printf("I got %s \r\n", CmdBuffer);
strcpy(Cmd," ");
strcpy(Arg," ");
// Parse command and possible numeric arg
char s[] = "Initial string";
char ** word_array = NULL;
strcpy(s,CmdBuffer);
size_t n = string_parser(s, &word_array );
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 );
// Branch based on command
// meas: Sample and plot a data set
if(strcmp(Cmd,"meas") == 0) {
// 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) {
// 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) {
AvgSize=(uint32_t) strtol(Arg,NULL,10);
}
// setperiod: Adjust sample period in us
else if(strcmp(Cmd,"setperiod") == 0) {
Period_us=(uint32_t) strtol(Arg,NULL,10);
}
// setcount: Adjust countdown period in ms
else if(strcmp(Cmd,"setcount") == 0) {
Count_ms=(uint32_t) strtol(Arg,NULL,10);
}
}
// Free memory after quit
freeArray(&Data);
pc1.printf("Exit. Data freed. \r\n", CmdBuffer);
// Infinite loop
while(1)
{
// Do nothing
}
}